Defined in: packages/disjoint-set/src/disjoint-set.ts:98
A disjoint set whose element domain can grow after construction.
Extends
Section titled “Extends”DisjointSet<T>
Type Parameters
Section titled “Type Parameters”T
Properties
Section titled “Properties”
readonlysize:number
Defined in: packages/disjoint-set/src/disjoint-set.ts:55
Number of elements across all sets. O(1).
Inherited from
Section titled “Inherited from”setCount
Section titled “setCount”
readonlysetCount:number
Defined in: packages/disjoint-set/src/disjoint-set.ts:57
Number of disjoint sets. O(1).
Inherited from
Section titled “Inherited from”
readonlyhas: (element) =>boolean
Defined in: packages/disjoint-set/src/disjoint-set.ts:59
Return true when the element belongs to the disjoint set. O(1) average.
Parameters
Section titled “Parameters”element
Section titled “element”T
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”
readonlyunite: (x,y) =>boolean
Defined in: packages/disjoint-set/src/disjoint-set.ts:67
Merge the sets containing x and y. O(alpha(n)) amortized.
Parameters
Section titled “Parameters”T
T
Returns
Section titled “Returns”boolean
true when two distinct sets were merged, false when both
elements already belonged to the same set.
Throws
Section titled “Throws”When either element is absent.
Inherited from
Section titled “Inherited from”areConnected
Section titled “areConnected”
readonlyareConnected: (x,y) =>boolean
Defined in: packages/disjoint-set/src/disjoint-set.ts:74
Return true when x and y belong to the same set. O(alpha(n))
amortized.
Parameters
Section titled “Parameters”T
T
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”When either element is absent.
Inherited from
Section titled “Inherited from”
readonlyfind: (element) =>T
Defined in: packages/disjoint-set/src/disjoint-set.ts:81
Return the representative of the set containing the element. O(alpha(n)) amortized.
Parameters
Section titled “Parameters”element
Section titled “element”T
Returns
Section titled “Returns”T
Throws
Section titled “Throws”When the element is absent.
Inherited from
Section titled “Inherited from”elements
Section titled “elements”
readonlyelements: () =>IterableIterator<T>
Defined in: packages/disjoint-set/src/disjoint-set.ts:88
Iterate over every element in insertion order. O(1) per step, O(n) total.
The iterator covers the elements present when the call was made, so adding elements while iterating does not extend the walk.
Returns
Section titled “Returns”IterableIterator<T>
Inherited from
Section titled “Inherited from”
readonlysets: () =>Map<T,T[]>
Defined in: packages/disjoint-set/src/disjoint-set.ts:94
Collect every set into a Map keyed by representative. Members appear in
insertion order. O(n * alpha(n)) time and O(n) space. The result is a copy
and does not track later mutations.
Returns
Section titled “Returns”Map<T, T[]>
Inherited from
Section titled “Inherited from”
readonlykind:"object"|"struct-of-arrays"
Defined in: packages/disjoint-set/src/disjoint-set.ts:100
Generic growable layouts use object or struct-of-arrays storage.
Overrides
Section titled “Overrides”
readonlyadd: (element) =>void
Defined in: packages/disjoint-set/src/disjoint-set.ts:107
Add an element as its own singleton set. O(1) amortized.
Parameters
Section titled “Parameters”element
Section titled “element”T
Returns
Section titled “Returns”void
Throws
Section titled “Throws”With code
ELEMENT_ALREADY_REGISTERED when the element is already present.