Skip to content

@graphty/algorithms / index / IntUnionFind

Class: IntUnionFind ​

Defined in: indexed/structures/union-find.ts:8

Index-keyed union-find over [0, size) with union by rank and path halving. The legacy UnionFind (src/data-structures/union-find.ts) is NodeId-keyed and stays where it is.

Constructors ​

Constructor ​

new IntUnionFind(size): IntUnionFind

Defined in: indexed/structures/union-find.ts:16

Create a union-find whose every element is a singleton set.

Parameters ​

size ​

number

The number of elements, each initially its own singleton set

Returns ​

IntUnionFind

Methods ​

find() ​

find(x): number

Defined in: indexed/structures/union-find.ts:29

Find the representative of an element's set, halving the path on the way up.

Parameters ​

x ​

number

An element index

Returns ​

number

The representative of x's set


toLabels() ​

toLabels(): object

Defined in: indexed/structures/union-find.ts:67

Dense labels in FIRST-SEEN order, which is what makes groups() identical to the legacy iteration order and identical to the GPU's after its own renumberPartition readback (design 9.7's connectedComponents row).

Returns ​

object

The labels and the number of distinct sets

count ​

readonly count: number

labels ​

readonly labels: U32


union() ​

union(a, b): boolean

Defined in: indexed/structures/union-find.ts:44

Merge the sets of two elements, attaching the shallower tree under the deeper one.

Parameters ​

a ​

number

An element index

b ​

number

An element index

Returns ​

boolean

True when the two sets were distinct and have now been merged