# objectDisjointSet

> **objectDisjointSet**<`T`>(`elements?`): [`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`T`>

Defined in: [packages/disjoint-set/src/disjoint-set.ts:167](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/disjoint-set/src/disjoint-set.ts#L167)

Create a [DisjointSet](/reference/knotkit/disjoint-set/interfaces/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](/reference/knotkit/disjoint-set/functions/indexeddisjointset/) when elements are the dense integer range `0..size - 1`, or [structOfArraysDisjointSet](/reference/knotkit/disjoint-set/functions/structofarraysdisjointset/) for large generic element counts.

## Type Parameters

### T

`T`

## Parameters

### elements?

`Iterable`<`T`, `any`, `any`>

Elements to insert, each in its own singleton set.

## Returns

[`GrowableDisjointSet`](/reference/knotkit/disjoint-set/interfaces/growabledisjointset/)<`T`>

## Throws

When `elements` yields the same element twice.
