@thi.ng/adjacency
Version:
Sparse & bitwise adjacency matrices, lists and selected traversal algorithms for directed & undirected graphs
51 lines • 1.74 kB
TypeScript
import type { Maybe } from "@thi.ng/api";
import { BitField } from "@thi.ng/bitfield/bitfield";
import type { CostFn, IGraph } from "./api.js";
/**
* Breadth-First / shortest path search between `src` and `dest` in `graph`,
* with optional `cost` function. By default all edges have an uniform cost,
* i.e. the overall path cost is topological distance.
*
* @remarks
* Also see {@link bfs} for ad hoc queries.
*
* Reference:
*
* - https://en.wikipedia.org/wiki/Breadth-first_search
* - https://algs4.cs.princeton.edu/40graphs/
*/
export declare class BFS {
graph: IGraph;
marked: BitField;
edges: Uint32Array;
dist: Float32Array;
constructor(graph: IGraph, src: number, cost?: CostFn);
protected search(id: number, cost: CostFn): void;
hasPathTo(id: number): boolean;
pathTo(id: number): Maybe<Iterable<number>>;
}
/**
* One-off Breadth-First / shortest path search between `src` and `dest` in
* `graph`, with optional `cost` function. If successful, returns path as
* iterable or undefined if no path connects the given vertices.
*
* @remarks
* For repeated queries starting from the same `src` vertex, it's much better &
* faster to create an {@link BFS} instance to re-use internal state and use
* {@link BFS.pathTo} to check/obtain paths.
*
* By default all edges have an uniform cost, i.e. the overall path cost is
* topological distance.
*
* Reference:
*
* - https://en.wikipedia.org/wiki/Breadth-first_search
* - https://algs4.cs.princeton.edu/40graphs/
*
* @param graph -
* @param src -
* @param dest -
* @param cost -
*/
export declare const bfs: (graph: IGraph, src: number, dest: number, cost?: CostFn) => Maybe<Iterable<number>>;
//# sourceMappingURL=bfs.d.ts.map