EnhancedSet
Defined in: packages/data/src/set/enhanced-set.ts:41
A set with caller-supplied equality.
Native Set is locked to SameValueZero, and so are @ac-kit/algo’s
union/intersection/… free functions, which are built on it. This type
exists to escape that: two elements are equal when this set’s comparator
says so, and the algebra below is implemented here rather than delegated,
because delegating would silently discard the caller’s equality.
Time complexity: an arbitrary equality cannot be hashed, so membership is a linear scan and the algebra is pairwise.
has/add/delete: O(n)union/intersection/difference/symmetricDifference: O(n·m)isSubsetOf/isSupersetOf/isDisjointFrom: O(n·m)
Space complexity: O(n). Reach for a native Set when SameValueZero is what
you actually want — it is O(1) per operation and this is not.
Type Parameters
Section titled “Type Parameters”T
The type of elements. Anything except undefined.
Implements
Section titled “Implements”ISet<T>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new EnhancedSet<
T>(iterable?,options?):EnhancedSet<T>
Defined in: packages/data/src/set/enhanced-set.ts:45
Parameters
Section titled “Parameters”iterable?
Section titled “iterable?”Iterable<T, any, any>
options?
Section titled “options?”Returns
Section titled “Returns”EnhancedSet<T>
Methods
Section titled “Methods”[iterator]()
Section titled “[iterator]()”[iterator]():
Iterator<T>
Defined in: packages/data/src/set/enhanced-set.ts:57
Returns
Section titled “Returns”Iterator<T>
Implementation of
Section titled “Implementation of”add(
item):void
Defined in: packages/data/src/set/enhanced-set.ts:70
O(n): the incoming element is compared against every element held.
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”addAll()
Section titled “addAll()”addAll(
items):void
Defined in: packages/data/src/set/enhanced-set.ts:77
O(n·m) in the size of this set and of items.
Parameters
Section titled “Parameters”Iterable<T>
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”clear()
Section titled “clear()”clear():
void
Defined in: packages/data/src/set/enhanced-set.ts:65
Removes all elements from the collection.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”count()
Section titled “count()”count():
number
Defined in: packages/data/src/set/enhanced-set.ts:61
The number of elements in the collection.
A method, not a getter: its async counterpart needs a round trip to the backing store, and a member must have the same shape in both.
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”delete()
Section titled “delete()”delete(
item):boolean
Defined in: packages/data/src/set/enhanced-set.ts:84
O(n).
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”difference()
Section titled “difference()”difference(
other):EnhancedSet<T>
Defined in: packages/data/src/set/enhanced-set.ts:139
O(n·m).
Parameters
Section titled “Parameters”Iterable<T>
Returns
Section titled “Returns”EnhancedSet<T>
Implementation of
Section titled “Implementation of”has(
item):boolean
Defined in: packages/data/src/set/enhanced-set.ts:103
O(n).
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”intersection()
Section titled “intersection()”intersection(
other):EnhancedSet<T>
Defined in: packages/data/src/set/enhanced-set.ts:123
O(n·m).
Parameters
Section titled “Parameters”Iterable<T>
Returns
Section titled “Returns”EnhancedSet<T>
Implementation of
Section titled “Implementation of”isDisjointFrom()
Section titled “isDisjointFrom()”isDisjointFrom(
other):boolean
Defined in: packages/data/src/set/enhanced-set.ts:195
O(n·m).
Parameters
Section titled “Parameters”Iterable<T>
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”isSubsetOf()
Section titled “isSubsetOf()”isSubsetOf(
other):boolean
Defined in: packages/data/src/set/enhanced-set.ts:171
O(n·m).
Parameters
Section titled “Parameters”Iterable<T>
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”isSupersetOf()
Section titled “isSupersetOf()”isSupersetOf(
other):boolean
Defined in: packages/data/src/set/enhanced-set.ts:184
O(n·m).
Parameters
Section titled “Parameters”Iterable<T>
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”symmetricDifference()
Section titled “symmetricDifference()”symmetricDifference(
other):EnhancedSet<T>
Defined in: packages/data/src/set/enhanced-set.ts:155
O(n·m).
Parameters
Section titled “Parameters”Iterable<T>
Returns
Section titled “Returns”EnhancedSet<T>
Implementation of
Section titled “Implementation of”union()
Section titled “union()”union(
other):EnhancedSet<T>
Defined in: packages/data/src/set/enhanced-set.ts:108
O(n·m).
Parameters
Section titled “Parameters”Iterable<T>
Returns
Section titled “Returns”EnhancedSet<T>