# structOfArraysDisjointSet

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

Defined in: [packages/disjoint-set/src/struct-of-arrays-disjoint-set.ts:57](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/disjoint-set/src/struct-of-arrays-disjoint-set.ts#L57)

Create a [DisjointSet](/reference/knotkit/disjoint-set/interfaces/disjointset/) backed by a struct of arrays. Parent pointers live in an `Int32Array` and ranks in a `Uint8Array`, instead of one `{ parent, rank }` object per element.

The algorithm is the one [objectDisjointSet](/reference/knotkit/disjoint-set/functions/objectdisjointset/) uses, union by rank with path halving, and the observable behavior is identical. Only the memory layout differs, with two consequences at scale:

* **Node memory.** A `{ parent, rank }` object plus its slot in the backing array measured 48 bytes per element in a prior V8 run (arm64), once the object header, the hidden-class pointer, and alignment are counted. The typed arrays cost exactly 5 bytes per element, so node storage shrinks by about 9x. Both generic layouts additionally keep the same element registry. Use [indexedDisjointSet](/reference/knotkit/disjoint-set/functions/indexeddisjointset/) to remove that registry for dense integer IDs.
* **Locality.** Parent pointers sit in one contiguous buffer, so the pointer chase inside `find` walks cache lines instead of scattered heap objects, and each read compiles to an indexed load rather than a property lookup.

A `Uint8Array` is wide enough for ranks. Union by rank keeps rank bounded by the height of the tree, which is at most log2(n), so 255 covers every element count an `Int32Array` can index.

The typed arrays double in capacity when they fill up, which makes `add` amortized O(1) and leaves at most 2x the needed capacity allocated.

## 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.
