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.
Type Parameters
Section titled “Type Parameters”T
Properties
Section titled “Properties”
readonlykind:"version-chain"
Defined in: packages/snapshot-set/src/snapshot-set.ts:59
Stable identifier for the implementation’s storage layout.
readonlysize:number
Defined in: packages/snapshot-set/src/snapshot-set.ts:61
Number of values currently present. O(1).
readonlyhas: (value) =>boolean
Defined in: packages/snapshot-set/src/snapshot-set.ts:63
Return true when the value is currently present. O(1) average.
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”boolean
readonlyadd: (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.
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”boolean
true when the value was not already present.
delete
Section titled “delete”
readonlydelete: (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.
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”boolean
true when the value was present and is now removed.
values
Section titled “values”
readonlyvalues: () =>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.
Returns
Section titled “Returns”IterableIterator<T>
createSnapshot
Section titled “createSnapshot”
readonlycreateSnapshot: () =>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.
Returns
Section titled “Returns”number
readonlyhasAt: (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.
Parameters
Section titled “Parameters”number
T
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”When id was never returned by createSnapshot().
valuesAt
Section titled “valuesAt”
readonlyvaluesAt: (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.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”IterableIterator<T>
Throws
Section titled “Throws”When id was never returned by createSnapshot().