@utilityjs/disjoint-set
v1.0.0
Published
An implementation of DisjointSet data structure.
Downloads
3
Maintainers
Readme
An implementation of DisjointSet data structure.
npm i @utilityjs/disjoint-set | yarn add @utilityjs/disjoint-set
declare type KeyGenerator<T> = (value: T) => string;
export declare class Item<T> {
constructor(value: T, keyGenerator?: KeyGenerator<T>);
getKey(): string;
getRoot(): Item<T>;
isRoot(): boolean;
getRank(): number;
getChildren(): Item<T>[];
setParent(parent: Item<T>, alsoAsParentChild?: boolean): void;
getParent(): Item<T> | null;
addChild(child: Item<T>): void;
}
export default class DisjointSet<T> {
constructor(keyGenerator?: KeyGenerator<T>);
makeSet(value: T): void;
find(value: T): string | null;
union(valueA: T, valueB: T): DisjointSet<T>;
inSameSet(valueA: T, valueB: T): boolean;
}