Skip to content

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.

T

The type of elements. Anything except undefined.

new EnhancedSet<T>(iterable?, options?): EnhancedSet<T>

Defined in: packages/data/src/set/enhanced-set.ts:45

Iterable<T, any, any>

EnhancedSetOptions<T>

EnhancedSet<T>

[iterator](): Iterator<T>

Defined in: packages/data/src/set/enhanced-set.ts:57

Iterator<T>

ISet.[iterator]


add(item): void

Defined in: packages/data/src/set/enhanced-set.ts:70

O(n): the incoming element is compared against every element held.

T

void

ISet.add


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.

Iterable<T>

void

ISet.addAll


clear(): void

Defined in: packages/data/src/set/enhanced-set.ts:65

Removes all elements from the collection.

void

ISet.clear


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.

number

ISet.count


delete(item): boolean

Defined in: packages/data/src/set/enhanced-set.ts:84

O(n).

T

boolean

ISet.delete


difference(other): EnhancedSet<T>

Defined in: packages/data/src/set/enhanced-set.ts:139

O(n·m).

Iterable<T>

EnhancedSet<T>

ISet.difference


has(item): boolean

Defined in: packages/data/src/set/enhanced-set.ts:103

O(n).

T

boolean

ISet.has


intersection(other): EnhancedSet<T>

Defined in: packages/data/src/set/enhanced-set.ts:123

O(n·m).

Iterable<T>

EnhancedSet<T>

ISet.intersection


isDisjointFrom(other): boolean

Defined in: packages/data/src/set/enhanced-set.ts:195

O(n·m).

Iterable<T>

boolean

ISet.isDisjointFrom


isSubsetOf(other): boolean

Defined in: packages/data/src/set/enhanced-set.ts:171

O(n·m).

Iterable<T>

boolean

ISet.isSubsetOf


isSupersetOf(other): boolean

Defined in: packages/data/src/set/enhanced-set.ts:184

O(n·m).

Iterable<T>

boolean

ISet.isSupersetOf


symmetricDifference(other): EnhancedSet<T>

Defined in: packages/data/src/set/enhanced-set.ts:155

O(n·m).

Iterable<T>

EnhancedSet<T>

ISet.symmetricDifference


union(other): EnhancedSet<T>

Defined in: packages/data/src/set/enhanced-set.ts:108

O(n·m).

Iterable<T>

EnhancedSet<T>

ISet.union