LinkedHashSet
Defined in: src/set/LinkedHashSet.ts:23
A hash Set that iterates in insertion order (re-adding an element keeps its place) and supports the
SequencedSet operations. Elements are equal by equals()/hashCode(); null and undefined are allowed.
add, remove and contains run in O(1) expected time, as do first/last access and removal; iterators are
fail-fast. Backed by a LinkedHashMap.
Extends HashSet so instanceof HashSet holds, but HashSet keeps no map to reuse: every method is
overridden to use a LinkedHashMap instead, and the inherited storage fields (shared empty ones) and modCount stay unused.
Extends
Section titled “Extends”HashSet<E>
Type Parameters
Section titled “Type Parameters”E
Implements
Section titled “Implements”SequencedSet<E>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LinkedHashSet<
E>():LinkedHashSet<E>
Defined in: src/set/LinkedHashSet.ts:29
Creates an empty set.
Returns
Section titled “Returns”LinkedHashSet<E>
Overrides
Section titled “Overrides”Constructor
Section titled “Constructor”new LinkedHashSet<
E>(initialCapacity,loadFactor?):LinkedHashSet<E>
Defined in: src/set/LinkedHashSet.ts:34
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”LinkedHashSet<E>
Throws
Section titled “Throws”IllegalArgumentException if initialCapacity is negative or NaN, or loadFactor is not positive
Overrides
Section titled “Overrides”Constructor
Section titled “Constructor”new LinkedHashSet<
E>(c):LinkedHashSet<E>
Defined in: src/set/LinkedHashSet.ts:39
Creates a set with the elements of c, in c’s iteration order; duplicates are dropped.
Parameters
Section titled “Parameters”Collection<E>
Returns
Section titled “Returns”LinkedHashSet<E>
Throws
Section titled “Throws”IllegalArgumentException if c is neither a number nor a collection
Overrides
Section titled “Overrides”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.
Inherited from
Section titled “Inherited from”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/LinkedHashSet.ts:130
Returns a fail-fast iterator over the elements, in insertion order.
Returns
Section titled “Returns”IterableIterator<E>
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”add(
e):boolean
Defined in: src/set/LinkedHashSet.ts:99
Adds e if no equal element is present. O(1) expected. null and undefined are allowed. A new element goes to
the end; re-adding an element keeps its place.
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”boolean
true if the set changed
Implementation of
Section titled “Implementation of”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
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”addFirst()
Section titled “addFirst()”addFirst(
e):void
Defined in: src/set/LinkedHashSet.ts:200
Adds e as the first element, or moves it to the front if already present. O(1) expected.
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”addLast()
Section titled “addLast()”addLast(
e):void
Defined in: src/set/LinkedHashSet.ts:205
Adds e as the last element, or moves it to the end if already present. O(1) expected.
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”clear()
Section titled “clear()”clear():
void
Defined in: src/set/LinkedHashSet.ts:112
Removes all elements.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”clone()
Section titled “clone()”clone():
LinkedHashSet<E>
Defined in: src/set/LinkedHashSet.ts:67
Shallow copy of the same runtime class (subclass fields included), in the same order.
Returns
Section titled “Returns”LinkedHashSet<E>
Overrides
Section titled “Overrides”contains()
Section titled “contains()”contains(
o):boolean
Defined in: src/set/LinkedHashSet.ts:90
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
Implementation of
Section titled “Implementation of”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
Implementation of
Section titled “Implementation of”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
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”forEach()
Section titled “forEach()”forEach(
action):void
Defined in: src/set/LinkedHashSet.ts:139
Calls action for each element, in insertion 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
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”getFirst()
Section titled “getFirst()”getFirst():
E
Defined in: src/set/LinkedHashSet.ts:171
Returns the first (eldest) element. O(1).
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException if this set is empty
Implementation of
Section titled “Implementation of”getLast()
Section titled “getLast()”getLast():
E
Defined in: src/set/LinkedHashSet.ts:179
Returns the last (youngest) element. O(1).
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException if this set is empty
Implementation of
Section titled “Implementation of”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
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”isEmpty()
Section titled “isEmpty()”isEmpty():
boolean
Defined in: src/set/LinkedHashSet.ts:82
Returns true if this set has no elements. O(1).
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”iterator()
Section titled “iterator()”iterator():
Iterator<E>
Defined in: src/set/LinkedHashSet.ts:117
Returns a fail-fast iterator over the elements, in insertion order; its remove is supported.
Returns
Section titled “Returns”Iterator<E>
Implementation of
Section titled “Implementation of”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>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”remove()
Section titled “remove()”remove(
o):boolean
Defined in: src/set/LinkedHashSet.ts:107
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
Implementation of
Section titled “Implementation of”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
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”removeFirst()
Section titled “removeFirst()”removeFirst():
E
Defined in: src/set/LinkedHashSet.ts:187
Removes and returns the first element. O(1).
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException if this set is empty
Implementation of
Section titled “Implementation of”removeIf()
Section titled “removeIf()”removeIf(
filter):boolean
Defined in: src/set/LinkedHashSet.ts:161
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
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”removeLast()
Section titled “removeLast()”removeLast():
E
Defined in: src/set/LinkedHashSet.ts:195
Removes and returns the last element. O(1).
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException if this set is empty
Implementation of
Section titled “Implementation of”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
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”reversed()
Section titled “reversed()”reversed():
SequencedSet<E>
Defined in: src/set/LinkedHashSet.ts:213
Returns a live reverse-ordered view: changes through either side are visible in the other. Writes go to this set:
add of a new element appends it here, so it shows up first in the view.
Returns
Section titled “Returns”SequencedSet<E>
Implementation of
Section titled “Implementation of”size()
Section titled “size()”size():
number
Defined in: src/set/LinkedHashSet.ts:77
Returns the number of elements. O(1).
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”spliterator()
Section titled “spliterator()”spliterator():
Spliterator<E>
Defined in: src/set/LinkedHashSet.ts:125
Returns a spliterator over the elements, used to build streams; fail-fast like the iterator. SIZED, SUBSIZED, DISTINCT and ORDERED; late-binding.
Returns
Section titled “Returns”Spliterator<E>
Implementation of
Section titled “Implementation of”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>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”toArray()
Section titled “toArray()”Call Signature
Section titled “Call Signature”toArray():
E[]
Defined in: src/set/LinkedHashSet.ts:144
Returns a new array with all elements, in insertion order. Changing the array does not affect this set.
Returns
Section titled “Returns”E[]
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”Call Signature
Section titled “Call Signature”toArray<
A>(generator):A
Defined in: src/set/LinkedHashSet.ts:149
Fills an array created by generator(size()) with the elements, in insertion 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
Implementation of
Section titled “Implementation of”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
Implementation of
Section titled “Implementation of”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
Inherited from
Section titled “Inherited from”newLinkedHashSet()
Section titled “newLinkedHashSet()”
staticnewLinkedHashSet<E>(numElements):LinkedHashSet<E>
Defined in: src/set/LinkedHashSet.ts:54
Returns an empty set intended for numElements elements (capacity is only a hint, 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”LinkedHashSet<E>
Throws
Section titled “Throws”IllegalArgumentException if numElements is negative or NaN
staticof<E>(…xs):LinkedHashSet<E>
Defined in: src/set/LinkedHashSet.ts:60
Returns a new set of the given elements in argument order; a repeated element keeps its first position.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”…E[]
Returns
Section titled “Returns”LinkedHashSet<E>