1.0.0 • Published 3 years ago

@utilityjs/disjoint-set v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

An implementation of DisjointSet data structure.

license npm latest package npm downloads types

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;
}