SealedCreates a set holding each distinct element of elements once, in first-seen order; empty
when elements is omitted, undefined or null (as new Set(null) is). A string is
iterable, so new HashSet('ab') holds 'a' and 'b'.
Time: O(m) average for m elements, plus the key or equivalence calls.
Optionalelements: Iterable<E, any, any> | null
The initial elements.
Optionaloptions: HashSetOptions<E> | null
key or equivalence; null means none.
Creates an empty set with the given options.
Time: O(1).
key or equivalence.
Marks collections so isCollection recognises them across copies of the package. Its key is
not exported, so the getter is not called directly. Time: O(1).
Marks instances of this class so instanceof recognises them across copies of the package.
Its key is not exported, so the getter is not called directly. Time: O(1).
Marks sets so isSetCollection recognises them across copies of the package. Its key is not
exported, so the getter is not called directly. Time: O(1).
'HashSet', for Object.prototype.toString. Time: O(1).
A number that changes on every change to the members and never on a read or on a call that changes nothing. Its exact values are unspecified. Time: O(1).
The number of members. Time: O(1).
The value-equality protocol; delegates to equals. Time: as equals.
The value-equality protocol: an order-independent combination of the members' hashes, the
same for equal sets that use the same key function, the same equivalence, or neither.
Values are unspecified. Time: O(n) plus the hash calls.
Node's inspect hook: HashSet(2) { 1, 2 } in console.log. Time: as toString.
Returns an iterator over the members in insertion order. It is live, as a native Set
iterator is: deleted members not yet reached are skipped, added members are visited, and
clear() ends it.
Time: O(1) to create; O(1) per step.
A new live iterator.
Adds element unless a member equals it, and returns the set, so calls chain. A member already
present keeps its value and its place in the order.
Time: O(1) average, plus one key or hash call and the equals calls.
The element to add (-0 is stored as 0).
The set.
Adds every element of elements, in order, after reading them all. Elements added before an
error stay.
Time: O(m) average for m elements, plus the calls.
The elements to add.
true when any element was added.
Returns a live cursor in insertion order; remove() removes the member next() returned,
without calling key, equals or hash while that member is still stored. A member
hasNext() has reached is returned even if it was deleted meanwhile.
Time: O(1) to create; next O(1); remove O(1) average.
A new cursor.
Removes the member equal to element.
Time: O(1) average, plus one key or hash call and the equals calls.
The value to remove.
true when a member was removed.
Returns whether other is a set of the same size in which every member of this set is
present, and which has every member of this set — whatever the insertion order, and the same
both ways round. Lists, queues, maps, arrays and native Set are never equal to it.
Time: O(n) average, plus the has calls on both sets.
Any value.
true when other is an equal set.
Calls action(member, member, set) for each member in insertion order, with this set to
thisArg, as native Set does. Members deleted before they are reached are skipped; members
added during the loop are visited.
Time: O(n) plus the calls.
Called with each member twice and the set.
OptionalthisArg: unknown
The this value for action.
Returns whether a member equals element.
Time: O(1) average, plus one key or hash call and the equals calls.
The value to look for.
true when a member equals it.
Returns an iterator over the members in insertion order, as values() does.
Time: O(1) to create; O(1) per step.
A new live iterator.
Removes every member equal, under this set's equality, to an element of elements. The
elements are read first and looked up through a temporary index built with this set's key
or equivalence; an error while deciding removes nothing.
Time: O(n + m) average, plus one key or hash call per element and the equals calls.
The elements to remove.
true when any member was removed.
Removes every member for which predicate returns a truthy value. Every member is decided
first; if predicate throws, or adds or removes members, nothing is removed.
Time: O(n) plus the calls.
Called with each member.
true when any member was removed.
Removes every member not equal, under this set's equality, to an element of elements, as
removeAll decides.
Time: O(n + m) average, plus one key or hash call per element and the equals calls.
The elements to keep.
true when any member was removed.
Returns a new array of the members in insertion order, so JSON.stringify writes the set as an
array (a native Set is written as {}).
Time: O(n).
A new array.
Returns an iterator over the members in insertion order.
Time: O(1) to create; O(1) per step.
A new live iterator.
Static[hasStaticfromReturns a new set of the distinct elements of elements, in first-seen order, with the given
options.
Time: O(m) average for m elements, plus the key or equivalence calls.
The elements.
Optionaloptions: HashSetOptions<T> | null
key or equivalence; null means none.
A new set.
A set that behaves like native
Set— insertion order, SameValueZero membership (NaNis one member,-0is stored as0),addreturning the set, live iteration — and adds value equality on request, structuralequals, and the shared collection API (removeIf,removeAll,retainAll, cursors,toJSON).Give a
keyfunction to treat values with the same derived key as one member, or anequivalence(such asvalueEquivalence) to decide membership by itsequalsandhash. The original values are stored and returned, never the keys.nullandundefinedare allowed.Iteration is live, as with native
Set: members deleted before they are reached are skipped, members added during iteration are visited, and nothing throwsConcurrentModificationError. Changing a member's key or hash while it is in the set leaves lookups for it unspecified; it can still be removed by a cursor,removeIforclear.Two sets are equal when they have the same size and each has every member of the other, in any order. The class is not designed to be subclassed.
Example