SealedCreates a set holding each distinct element of elements once, in first-seen order; empty
when elements is omitted, undefined or null. Options are never taken from a source set.
Time: O(m) average for m elements, plus the key or equivalence calls.
Optionalelements: Iterable<E, any, any> | null
The initial elements.
Optionaloptions: LinkedHashSetOptions<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 sequenced collections so isSequencedCollection 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).
'LinkedHashSet', for Object.prototype.toString. Time: O(1).
A number that changes on every insertion, removal or move 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 as an equal HashSet's with the same key function, the same equivalence, or
neither. Values are unspecified. Time: O(n) plus the hash calls.
Node's inspect hook: LinkedHashSet(2) { 1, 2 } in console.log. Time: as toString.
Returns an iterator over the members in order. It is live, as a native Set iterator is:
members deleted before they are reached are skipped, members inserted at the end are visited,
members inserted at the front are not, and a moved member counts as deleted and inserted at its
new end. After clear() it continues with members added later; once done it stays done.
Time: O(1) to create; O(1) per step, amortised over the steps and the changes made while it is open.
A new live iterator.
Adds element at the end 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 at the end, in order, after reading them all; members already
present stay where they are. 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.
Inserts element at the front, or moves the member equal to it to the front (the stored
member is kept, not replaced by element), and returns the set. Nothing changes when that
member is already first.
Time: O(1) amortised average, plus one key or hash call and the equals calls (the first
call that needs linked order costs O(n), once).
The element to insert or move (-0 is stored as 0).
The set.
Inserts element at the end, or moves the member equal to it to the end (the stored member is
kept, not replaced by element), and returns the set. Nothing changes when that member is
already last.
Time: O(1) amortised average, plus one key or hash call and the equals calls (the first
call that needs linked order costs O(n), once).
The element to insert or move (-0 is stored as 0).
The set.
Removes every member. An open iteration starts over before the first member, so members added
at the end afterwards are visited, as with native Set.
Time: O(1) with an equivalence; one native clear otherwise (at most O(n)).
Returns a new LinkedHashSet with the same members, order and key or equivalence,
independent of this one. Stored keys and hashes are copied; no user function is called.
Time: O(n).
The copy.
Returns a live cursor in order; remove() removes the member next() returned, from wherever
it now stands, without calling key, equals or hash while that member is still stored. A
member hasNext() has reached is returned even if it was deleted or moved meanwhile.
Time: O(1) to create; next O(1) amortised over the steps and the changes made while it is
open; 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 which has every member of this set and whose
every member this set has — whatever the 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 order, with this set to thisArg, as
native Set does. The loop is live, as [Symbol.iterator] describes.
Time: O(n) plus the calls.
Called with each member twice and the set.
OptionalthisArg: unknown
The this value for action.
Returns the first member.
Time: O(1) amortised. Calls no key, equals or hash function.
The first member.
Returns the last member.
Time: O(1) amortised (the first call that needs linked order costs O(n), once). Calls no
key, equals or hash function.
The last member.
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 order, as values() does.
Time: O(1) to create; O(1) per step, amortised over the steps and the changes made while it is open.
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 and returns the first member.
Time: O(1) amortised average. Calls no key, equals or hash function.
The removed member.
Removes every member for which predicate returns a truthy value. Every member is decided
first, in order; if predicate throws, or inserts, removes or moves members, nothing is
removed.
Time: O(n) plus the calls.
Called with each member.
true when any member was removed.
Removes and returns the last member.
Time: O(1) amortised average (the first call that needs linked order costs O(n), once). Calls
no key, equals or hash function.
The removed member.
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 live view of this set in the opposite order. Changes through either show in both;
the view's getFirst, removeFirst and addFirst act on this set's last member or end, and
its add inserts an absent member at the view's end, which is this set's front. Reversing the
view returns this set.
Time: O(1). Every call through the view needs linked order: the first such call on the set costs O(n), once, and the view's operations cost what the set's cost, amortised.
The reversed view, printed as ReversedLinkedHashSet.
Returns a new array of the members in order, so JSON.stringify writes the set as an array.
Time: O(n).
A new array.
Returns an iterator over the members in order.
Time: O(1) to create; O(1) per step, amortised over the steps and the changes made while it is open.
A new live iterator.
Static[hasReturns whether value is a LinkedHashSet, including one created by another copy of the
library with the same major version. A reversed view is not one.
Time: O(1).
The value on the left of instanceof.
true when value is a LinkedHashSet.
StaticfromReturns 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: LinkedHashSetOptions<T> | null
key or equivalence; null means none.
A new set.
A set in insertion order that behaves like native
Set— SameValueZero membership (NaNis one member,-0is stored as0),addreturning the set and keeping a present member where it is, live iteration — and can also be read and changed at both ends:getFirst,getLast,removeFirstandremoveLast,addFirstandaddLast, which insert an absent member at that end or move the present one there, and a livereversed()view. Each takes O(1) amortised (average for those that look up or remove).A set without the
keyorequivalenceoption keeps its members in a nativeSetuntil the first call that needs linked order:addFirst,addLastof a member,getLast,removeLast, or any call throughreversed(). That call costs O(n), once; this is why the ends,addFirstandaddLastare amortised.The
keyandequivalenceoptions work as they do forHashSet; 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 inserted at the end the loop is heading to are visited, members inserted at the end it started from are not, and nothing throwsConcurrentModificationError. A move acts as a delete followed by an insertion at the new end, sofor (const x of set) set.addLast(x)never ends, exactly asfor (const x of set) { set.delete(x); set.add(x) }never ends on a nativeSet. An open iterator or cursor keeps the members removed since its last step reachable until it advances or is dropped; release iterators that are no longer needed.Members are found by their
keyresult orhashwhen they are stored. If that changes while a member is in the set, lookups,addFirst,addLastanddeletegive unspecified results for it;removeFirst,removeLast, a cursor'sremove,removeIfandclearstill remove it.Two sets are equal when they have the same size and each has every member of the other, in any order. A
LinkedHashSetis not aHashSet(instanceof HashSetisfalse); both are sets. The class is not designed to be subclassed.Example