Skip to content

Defined in: packages/snapshot-set/src/snapshot-set.ts:57

A mutable set backed by per-value toggle-version history.

Values are compared with SameValueZero, the same equality that Map and Set use. NaN equals itself, and 0 equals -0.

values() walks values in first-registration order — the order a value was first added, not Set’s reinsertion order. A value that is removed and later re-added keeps its original position, because its registry index never changes.

createSnapshot() mints an id denoting the set’s state at the moment of the call. Later mutations never change any answer derived from an id minted at or before that call — that is the one invariant the whole design exists to hold. Only ids createSnapshot() returned are valid; hasAt and valuesAt throw for anything else, including a version number the structure passed through but never handed out as a snapshot id.

All implementations mutate in place.

T

readonly kind: "version-chain"

Defined in: packages/snapshot-set/src/snapshot-set.ts:59

Stable identifier for the implementation’s storage layout.


readonly size: number

Defined in: packages/snapshot-set/src/snapshot-set.ts:61

Number of values currently present. O(1).


readonly has: (value) => boolean

Defined in: packages/snapshot-set/src/snapshot-set.ts:63

Return true when the value is currently present. O(1) average.

T

boolean


readonly add: (value) => boolean

Defined in: packages/snapshot-set/src/snapshot-set.ts:71

Insert a value. O(1) amortized.

A no-op when the value is already present.

T

boolean

true when the value was not already present.


readonly delete: (value) => boolean

Defined in: packages/snapshot-set/src/snapshot-set.ts:79

Delete a value. O(1) average.

A no-op when the value is not present.

T

boolean

true when the value was present and is now removed.


readonly values: () => IterableIterator<T>

Defined in: packages/snapshot-set/src/snapshot-set.ts:87

Iterate over the values present when the call was made, in first-registration order. O(1) per step, O(n) total.

The iterator covers the values present at call time; mutating the set while iterating does not extend the walk.

IterableIterator<T>


readonly createSnapshot: () => number

Defined in: packages/snapshot-set/src/snapshot-set.ts:97

Mint an id denoting the set’s state at this moment. O(1); nothing is copied.

Shares its counter with add/delete, so two createSnapshot() calls with no intervening mutation return different ids that answer identically for every value. Ids are strictly increasing across the structure’s lifetime.

number


readonly hasAt: (id, value) => boolean

Defined in: packages/snapshot-set/src/snapshot-set.ts:104

Return true when the value was present at the given snapshot. O(log h), where h is the number of times that value has toggled.

number

T

boolean

When id was never returned by createSnapshot().


readonly valuesAt: (id) => IterableIterator<T>

Defined in: packages/snapshot-set/src/snapshot-set.ts:122

Iterate over the values present at the given snapshot, in first-registration order. O(r * log h) total, where r is the number of values registered at or before the snapshot and h is a given value’s toggle count.

This cost is proportional to how many values had been registered by that snapshot, not to how many the snapshot’s result actually contains — an old snapshot on a set that has since churned through many distinct values still pays for every value registered before it, including ones long removed by then.

The iterator covers the registry prefix that existed when the call was made; mutating the set while iterating does not change the walk.

number

IterableIterator<T>

When id was never returned by createSnapshot().