topological-sort-group
Version:
Topological sorting and cycle detection. Optional grouping for parallel processing
14 lines (13 loc) • 547 B
TypeScript
import type { Counter, GraphOptions, Key, Node, Value } from './types.js';
export default class Graph<T extends Key> {
private nodeMap;
private path;
constructor(options?: GraphOptions);
static from<T extends Key>(nodes: Node<T>[] | Node<T>[][], options?: GraphOptions): Graph<Key>;
key(keyOrValue: Key | Value<T>): Key;
keys(): Key[];
value(key: Key): Value<T> | T;
edges(key: Key): T[];
add(keyOrValue: Key | Value<T>, toKeyOrValue?: Key | Value<T>): void;
degrees<T extends Key>(): Counter<T, number>;
}