HashSet
Defined in: src/set/HashSet.ts:21
A hash table Set: the default set. Elements are equal by equals()/hashCode() (SameValueZero for
primitives and objects without equals()); null and undefined are allowed; iteration order is unspecified.
add, remove and contains run in O(1) expected time (O(k) when k elements share one hashCode()); iterators
are fail-fast.
Same hybrid storage as HashMap: small non-negative integers as flags in a dense array, other SameValueZero elements in a native Set, elements with equals()/hashCode() and Dates in hashCode buckets (always arrays, so iterators can track them).
Extends
Section titled “Extends”AbstractSet<E>
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”E
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new HashSet<
E>():HashSet<E>
Defined in: src/set/HashSet.ts:36
Creates an empty set.
Returns
Section titled “Returns”HashSet<E>
Overrides
Section titled “Overrides”Constructor
Section titled “Constructor”new HashSet<
E>(initialCapacity,loadFactor?):HashSet<E>
Defined in: src/set/HashSet.ts:41
Creates an empty set. The arguments are sizing hints only: they are validated but storage grows on demand.
Parameters
Section titled “Parameters”initialCapacity
Section titled “initialCapacity”number
loadFactor?
Section titled “loadFactor?”number
Returns
Section titled “Returns”HashSet<E>
Throws
Section titled “Throws”IllegalArgumentException if initialCapacity is negative or NaN, or loadFactor is not positive
Overrides
Section titled “Overrides”AbstractSet<E>.constructor
Constructor
Section titled “Constructor”new HashSet<
E>(c):HashSet<E>
Defined in: src/set/HashSet.ts:46
Creates a set with the elements of c; duplicates are dropped.
Parameters
Section titled “Parameters”Collection<E>
Returns
Section titled “Returns”HashSet<E>
Throws
Section titled “Throws”IllegalArgumentException if c is neither a number nor a collection
Overrides
Section titled “Overrides”AbstractSet<E>.constructor
Properties
Section titled “Properties”modCount
Section titled “modCount”modCount:
number=0
Defined in: src/set/HashSet.ts:33
Structural modification count; iterators compare against it.
Accessors
Section titled “Accessors”[SET_BRAND]
Section titled “[SET_BRAND]”Get Signature
Section titled “Get Signature”get [SET_BRAND]():
true
Defined in: src/abstract/AbstractSet.ts:24
Runtime brand that marks this object as a Set (TypeScript interfaces do not exist at runtime); always true.
Returns
Section titled “Returns”true
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”[INSPECT]()
Section titled “[INSPECT]()”[INSPECT]():
string
Defined in: src/abstract/AbstractCollection.ts:195
Node’s util.inspect hook: console.log prints the toString() form.
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”[iterator]()
Section titled “[iterator]()”[iterator]():
IterableIterator<E>
Defined in: src/set/HashSet.ts:223
Returns a fail-fast iterator over the elements, in unspecified order.
Returns
Section titled “Returns”IterableIterator<E>
Overrides
Section titled “Overrides”add(
e):boolean
Defined in: src/set/HashSet.ts:110
Adds e if no equal element is present. O(1) expected. null and undefined are allowed.
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”boolean
true if the set changed
Overrides
Section titled “Overrides”addAll()
Section titled “addAll()”addAll(
c):boolean
Defined in: src/abstract/AbstractCollection.ts:96
Calls add for each element of a snapshot of c (so addAll(this) terminates); returns true if any call
changed the collection.
Parameters
Section titled “Parameters”Collection<E>
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”NullPointerException if c is null
Throws
Section titled “Throws”UnsupportedOperationException if add is not supported and c is not empty
Inherited from
Section titled “Inherited from”clear()
Section titled “clear()”clear():
void
Defined in: src/set/HashSet.ts:199
Removes all elements. Open iterators then fail with ConcurrentModificationException.
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”clone()
Section titled “clone()”clone():
HashSet<E>
Defined in: src/set/HashSet.ts:71
Shallow copy of the same runtime class (subclass fields included).
Returns
Section titled “Returns”HashSet<E>
contains()
Section titled “contains()”contains(
o):boolean
Defined in: src/set/HashSet.ts:96
Returns true if this set contains an element equal to o (by equals(), SameValueZero for primitives). O(1)
expected.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”boolean
Overrides
Section titled “Overrides”containsAll()
Section titled “containsAll()”containsAll(
c):boolean
Defined in: src/abstract/AbstractCollection.ts:83
Returns true if this collection contains every element of c (calls contains for each).
Parameters
Section titled “Parameters”Collection<unknown>
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”NullPointerException if c is null
Inherited from
Section titled “Inherited from”equals()
Section titled “equals()”equals(
o):boolean
Defined in: src/abstract/AbstractSet.ts:37
Returns true if o is a Set of the same size that this set containsAll of; any Set implementation
compares. A ClassCastException or NullPointerException from containsAll counts as “not equal”.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”forEach()
Section titled “forEach()”forEach(
action):void
Defined in: src/set/HashSet.ts:232
Calls action for each element, in unspecified order.
Parameters
Section titled “Parameters”action
Section titled “action”(e) => void
Returns
Section titled “Returns”void
Throws
Section titled “Throws”NullPointerException if action is null
Throws
Section titled “Throws”ConcurrentModificationException if action structurally modifies this set
Overrides
Section titled “Overrides”hashCode()
Section titled “hashCode()”hashCode():
number
Defined in: src/abstract/AbstractSet.ts:81
Returns the sum of the element hashes (32-bit), so equal sets hash the same whatever their order.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”isEmpty()
Section titled “isEmpty()”isEmpty():
boolean
Defined in: src/set/HashSet.ts:88
Returns true if this set has no elements. O(1).
Returns
Section titled “Returns”boolean
Overrides
Section titled “Overrides”iterator()
Section titled “iterator()”iterator():
Iterator<E>
Defined in: src/set/HashSet.ts:209
Returns a fail-fast iterator over the elements, in unspecified order; its remove is supported.
Returns
Section titled “Returns”Iterator<E>
Overrides
Section titled “Overrides”parallelStream()
Section titled “parallelStream()”parallelStream():
Stream<E>
Defined in: src/abstract/AbstractCollection.ts:180
Returns a stream over spliterator() flagged as parallel.
Returns
Section titled “Returns”Stream<E>
Inherited from
Section titled “Inherited from”remove()
Section titled “remove()”remove(
o):boolean
Defined in: src/set/HashSet.ts:144
Removes the element equal to o, if present. O(1) expected.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”boolean
true if an element was removed
Overrides
Section titled “Overrides”removeAll()
Section titled “removeAll()”removeAll(
c):boolean
Defined in: src/abstract/AbstractSet.ts:56
Removes every element also in c. Walks the smaller side, sized by size(): when this set is larger, iterates c and calls this.remove(e) for each element (so this set’s equality decides, and remove(null) may throw NullPointerException); otherwise iterates this set, removing (iterator.remove, via removeIf) each element c.contains().
Parameters
Section titled “Parameters”Collection<unknown>
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”NullPointerException if c is null, or this set contains null and c does not permit null
Inherited from
Section titled “Inherited from”removeIf()
Section titled “removeIf()”removeIf(
filter):boolean
Defined in: src/set/HashSet.ts:280
Removes every element for which filter returns true, in one O(n) pass.
Parameters
Section titled “Parameters”filter
Section titled “filter”(e) => boolean
Returns
Section titled “Returns”boolean
true if any element was removed
Throws
Section titled “Throws”NullPointerException if filter is null
Throws
Section titled “Throws”ConcurrentModificationException if filter structurally modifies this set
Overrides
Section titled “Overrides”retainAll()
Section titled “retainAll()”retainAll(
c):boolean
Defined in: src/abstract/AbstractCollection.ts:118
Removes every element that c does not contain, through the iterator’s remove(); returns true if any was
removed.
Parameters
Section titled “Parameters”Collection<unknown>
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”NullPointerException if c is null
Inherited from
Section titled “Inherited from”size()
Section titled “size()”size():
number
Defined in: src/set/HashSet.ts:83
Returns the number of elements. O(1).
Returns
Section titled “Returns”number
Overrides
Section titled “Overrides”spliterator()
Section titled “spliterator()”spliterator():
Spliterator<E>
Defined in: src/set/HashSet.ts:217
Returns a spliterator over the elements, used to build streams; fail-fast like the iterator. SIZED and DISTINCT (SIZED until split); late-binding.
Returns
Section titled “Returns”Spliterator<E>
Overrides
Section titled “Overrides”stream()
Section titled “stream()”stream():
Stream<E>
Defined in: src/abstract/AbstractCollection.ts:175
Returns a sequential stream over spliterator().
Returns
Section titled “Returns”Stream<E>
Inherited from
Section titled “Inherited from”toArray()
Section titled “toArray()”Call Signature
Section titled “Call Signature”toArray():
E[]
Defined in: src/set/HashSet.ts:257
Returns a new array with all elements, in unspecified order. Changing the array does not affect this set.
Returns
Section titled “Returns”E[]
Overrides
Section titled “Overrides”Call Signature
Section titled “Call Signature”toArray<
A>(generator):A
Defined in: src/set/HashSet.ts:262
Fills an array created by generator(size()) with the elements, in unspecified order, and returns it.
Type Parameters
Section titled “Type Parameters”A extends WritableArrayLike<E>
Parameters
Section titled “Parameters”generator
Section titled “generator”(length) => A
creates the target array for a given length
Returns
Section titled “Returns”A
Overrides
Section titled “Overrides”toString()
Section titled “toString()”toString():
string
Defined in: src/abstract/AbstractCollection.ts:199
Returns [e1, e2, ...] in iteration order; an element that is this collection prints as (this Collection).
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”newHashSet()
Section titled “newHashSet()”
staticnewHashSet<E>(numElements):HashSet<E>
Defined in: src/set/HashSet.ts:58
Returns an empty set intended for numElements elements. Capacity is only a hint here, so this just validates it.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”numElements
Section titled “numElements”number
Returns
Section titled “Returns”HashSet<E>
Throws
Section titled “Throws”IllegalArgumentException if numElements is negative or NaN
staticof<E>(…xs):HashSet<E>
Defined in: src/set/HashSet.ts:64
Returns a new set of the given elements; duplicates are dropped.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”…E[]
Returns
Section titled “Returns”HashSet<E>