Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@utilityjs/disjoint-set

mimshins4MIT1.0.0TypeScript support: included

An implementation of DisjointSet data structure.

javascript, typescript, data structure, algorithm, disjoint set, union-find, merge-find

readme

DisjointSet

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