sclass BreadthFirstPathFinder implements Steppable {
// must set
IF1> getChildren;
// graph representation - filled during exploration
new MultiMap links;
// node queue (temporary)
new LinkedList queue;
*() {}
*(IF1> *getChildren) {}
*(IF1> *getChildren, A startNode) { add(startNode); }
void add(A a, A prev default null) {
if (!links.containsKey(a)) {
links.put(a, prev);
queue.add(a);
}
}
public bool step() {
ping();
if (empty(queue)) false;
A a = popFirst(queue);
fOr (A b : getChildren.get(a))
add(b, a);
true;
}
bool nodeReached(A a) {
ret links.containsKey(a);
}
Cl getBackLinks(A a) {
ret links.get(a);
}
L examplePath(A start, A dest) {
new L path;
A node = dest;
path.add(node);
do {
if (node == null) null; // no path found
node = first(getBackLinks(node));
path.add(node);
} while (node != start);
ret reversed(path);
}
}