function* djikstra([ex, ey], m = 1) {
const seen = new d3.InternSet([], JSON.stringify);
const next = new d3.InternSet([], JSON.stringify);
const distances = new d3.InternMap([[[0, 0], 0]], JSON.stringify);
const paths = new d3.InternMap([], JSON.stringify);
let p = [0, 0];
while (p[0] !== ex || p[1] !== ey) {
for (const n of neighbors(p, m)) {
if (seen.has(n)) continue;
const d = distances.get(p) + extended(n);
if (!distances.has(n) || d < distances.get(n)) {
distances.set(n, d);
paths.set(n, p);
}
next.add(n);
}
seen.add(p);
p = d3.least(
d3.filter(next, ([p]) => !seen.has(p)),
(a, b) => distances.get(a) - distances.get(b)
);
next.delete(p);
yield { seen, distances, paths };
}
yield { seen, distances, paths, done: true };
}