topological-sort-group
Version:
Topological sorting and cycle detection. Optional grouping for parallel processing
21 lines (20 loc) • 681 B
TypeScript
import type { Cycle, GraphOptions, Key, SortModeEnum, SortResult } from './types.ts';
export default class Graph<T> {
protected size: number;
static SortMode: {
readonly Group: 1;
readonly Flat: 2;
};
private nodeMap;
private path;
constructor(options?: GraphOptions);
static from<T>(values: Array<Key | T | [Key | T, Key | T]>, options?: GraphOptions): Graph<T>;
key(keyOrValue: Key | T): Key;
keys(): Key[];
value(key: Key): T;
edges(key: Key): Key[];
add(keyOrValue: Key | T, toKeyOrValue?: Key | T): void;
degrees(): Record<Key, number>;
cycles(): Cycle[];
sort(mode?: SortModeEnum): SortResult<T>;
}