Skip to content

objectDisjointSet<T>(elements?): GrowableDisjointSet<T>

Defined in: packages/disjoint-set/src/disjoint-set.ts:167

Create a DisjointSet backed by one { parent, rank } object per element, optionally pre-populated with elements that each start in their own singleton set.

Merges follow union by rank. The shorter tree is attached under the taller one, so tree height grows only when two trees of equal rank meet. Lookups follow path halving, a single-pass compression that repoints every node it visits to its grandparent and then continues from that grandparent. Together they bound each operation at O(alpha(n)) amortized time.

Prefer indexedDisjointSet when elements are the dense integer range 0..size - 1, or structOfArraysDisjointSet for large generic element counts.

T

Iterable<T, any, any>

Elements to insert, each in its own singleton set.

GrowableDisjointSet<T>

When elements yields the same element twice.