You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
831 B
33 lines
831 B
export function doBFS(queue, visited, fn, navigator) {
|
|
while (queue.length) {
|
|
const node = queue.shift();
|
|
const abort = fn(node);
|
|
if (abort) {
|
|
return true;
|
|
}
|
|
visited.add(node.id);
|
|
navigator(node.id).forEach((n) => {
|
|
if (!visited.has(n.id)) {
|
|
visited.add(n.id);
|
|
queue.push(n);
|
|
}
|
|
});
|
|
}
|
|
return false;
|
|
}
|
|
export function doDFS(node, visited, fn, navigator) {
|
|
const abort = fn(node);
|
|
if (abort) {
|
|
return true;
|
|
}
|
|
visited.add(node.id);
|
|
for (const n of navigator(node.id)) {
|
|
if (!visited.has(n.id)) {
|
|
if (doDFS(n, visited, fn, navigator)) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
//# sourceMappingURL=traverse.js.map
|