LinkedHashMap
data-structure-typed / LinkedHashMap
Class: LinkedHashMap<K, V, R>
Defined in: data-structures/hash/hash-map.ts:861
Hash-based map that preserves insertion order via a doubly-linked list.
Remarks
Time O(1), Space O(1)
Example
examples will be generated by unit test
Extends
IterableEntryBase<K,V>
Type Parameters
K
K = any
V
V = any
R
R = [K, V]
Constructors
Constructor
new LinkedHashMap<K, V, R>(entryOrRawElements?, options?): LinkedHashMap<K, V, R>;
Defined in: data-structures/hash/hash-map.ts:871
Create a LinkedHashMap and optionally bulk-insert entries.
Parameters
entryOrRawElements?
Iterable<[K, V] | R> = []
Iterable of entries or raw elements to insert.
options?
LinkedHashMapOptions<K, V, R>
Options: hash functions and optional record-to-entry converter.
Returns
LinkedHashMap<K, V, R>
New LinkedHashMap instance.
Remarks
Time O(N), Space O(N)
Overrides
IterableEntryBase<K, V>.constructor
Accessors
first
Get Signature
get first(): [K, V] | undefined;
Defined in: data-structures/hash/hash-map.ts:963
Get the first [key, value] pair.
Remarks
Time O(1), Space O(1)
Returns
[K, V] | undefined
First entry or undefined when empty.
head
Get Signature
get head(): HashMapLinkedNode<K, V | undefined>;
Defined in: data-structures/hash/hash-map.ts:925
Get the head node (first entry) sentinel link.
Remarks
Time O(1), Space O(1)
Returns
HashMapLinkedNode<K, V | undefined>
Head node or sentinel.
last
Get Signature
get last(): [K, V] | undefined;
Defined in: data-structures/hash/hash-map.ts:973
Get the last [key, value] pair.
Remarks
Time O(1), Space O(1)
Returns
[K, V] | undefined
Last entry or undefined when empty.
noObjMap
Get Signature
get noObjMap(): Record<string, HashMapLinkedNode<K, V | undefined>>;
Defined in: data-structures/hash/hash-map.ts:909
Get the internal record for non-object keys.
Remarks
Time O(1), Space O(1)
Returns
Record<string, HashMapLinkedNode<K, V | undefined>>
Record of hash→node.
objHashFn
Get Signature
get objHashFn(): (key) => object;
Defined in: data-structures/hash/hash-map.ts:898
Get the hash function for object/weak keys.
Remarks
Time O(1), Space O(1)
Returns
Object-hash function.
(key) => object
size
Get Signature
get size(): number;
Defined in: data-structures/hash/hash-map.ts:954
Total number of entries.
Remarks
Time O(1), Space O(1)
Returns
number
Entry count.
Overrides
tail
Get Signature
get tail(): HashMapLinkedNode<K, V | undefined>;
Defined in: data-structures/hash/hash-map.ts:936
Get the tail node (last entry) sentinel link.
Remarks
Time O(1), Space O(1)
Returns
HashMapLinkedNode<K, V | undefined>
Tail node or sentinel.
Methods
[iterator]()
iterator: IterableIterator<[K, V]>;
Defined in: data-structures/base/iterable-entry-base.ts:22
Default iterator yielding [key, value] entries.
Parameters
args
...unknown[]
Returns
IterableIterator<[K, V]>
Iterator of [K, V].
Remarks
Time O(n) to iterate, Space O(1)
Inherited from
at()
at(index): V | undefined;
Defined in: data-structures/hash/hash-map.ts:1087
Get the value at a given index in insertion order.
Parameters
index
number
Zero-based index.
Returns
V | undefined
Value at the index.
Remarks
Time O(N), Space O(1)
begin()
begin(): Generator<(K | V | undefined)[], void, unknown>;
Defined in: data-structures/hash/hash-map.ts:983
Iterate from head → tail.
Returns
Generator<(K | V | undefined)[], void, unknown>
Iterator of [key, value].
Remarks
Time O(N), Space O(1)
clear()
clear(): void;
Defined in: data-structures/hash/hash-map.ts:1157
Remove all entries.
Returns
void
Remarks
Time O(n) typical, Space O(1)
Overrides
clone()
clone(): this;
Defined in: data-structures/hash/hash-map.ts:1163
Deep clone preserving the concrete subtype.
Returns
this
A new instance of the same concrete class (this type).
Remarks
Time O(n) typical, Space O(n)
Overrides
deleteAt()
deleteAt(index): boolean;
Defined in: data-structures/hash/hash-map.ts:1142
Delete the entry at a given index.
Parameters
index
number
Zero-based index.
Returns
boolean
True if removed.
Remarks
Time O(N), Space O(1)
deleteWhere()
deleteWhere(predicate): boolean;
Defined in: data-structures/hash/hash-map.ts:1116
Delete the first entry that matches a predicate.
Parameters
predicate
(key, value, index, map) => boolean
Function (key, value, index, map) → boolean to decide deletion.
Returns
boolean
True if an entry was removed.
Remarks
Time O(N), Space O(1)
entries()
entries(): IterableIterator<[K, V | undefined]>;
Defined in: data-structures/base/iterable-entry-base.ts:31
Iterate over [key, value] pairs (may yield undefined values).
Returns
IterableIterator<[K, V | undefined]>
Iterator of [K, V | undefined].
Remarks
Time O(n), Space O(1)
Inherited from
every()
every(predicate, thisArg?): boolean;
Defined in: data-structures/base/iterable-entry-base.ts:66
Test whether all entries satisfy the predicate.
Parameters
predicate
EntryCallback<K, V, boolean>
(key, value, index, self) => boolean.
thisArg?
unknown
Optional this for callback.
Returns
boolean
true if all pass; otherwise false.
Remarks
Time O(n), Space O(1)
Inherited from
filter()
filter(predicate, thisArg?): this;
Defined in: data-structures/hash/hash-map.ts:1168
Filter entries and return the same-species structure.
Parameters
predicate
EntryCallback<K, V, boolean>
thisArg?
unknown
Returns
this
A new instance of the same concrete class (this type).
Remarks
Time O(n), Space O(n)
Overrides
find()
find(callbackfn, thisArg?): [K, V] | undefined;
Defined in: data-structures/base/iterable-entry-base.ts:114
Find the first entry that matches a predicate.
Parameters
callbackfn
EntryCallback<K, V, boolean>
(key, value, index, self) => boolean.
thisArg?
unknown
Optional this for callback.
Returns
[K, V] | undefined
Matching [key, value] or undefined.
Remarks
Time O(n), Space O(1)
Inherited from
forEach()
forEach(callbackfn, thisArg?): void;
Defined in: data-structures/base/iterable-entry-base.ts:99
Visit each entry, left-to-right.
Parameters
callbackfn
EntryCallback<K, V, void>
(key, value, index, self) => void.
thisArg?
unknown
Optional this for callback.
Returns
void
Remarks
Time O(n), Space O(1)
Inherited from
get()
get(key): V | undefined;
Defined in: data-structures/hash/hash-map.ts:1070
Get the value under a key.
Parameters
key
K
Key to look up.
Returns
V | undefined
Value or undefined.
Remarks
Time O(n) generic, Space O(1)
Overrides
has()
has(key): boolean;
Defined in: data-structures/hash/hash-map.ts:1061
Whether the given key exists.
Parameters
key
K
Key to test.
Returns
boolean
true if found; otherwise false.
Remarks
Time O(n) generic, Space O(1)
Overrides
hasValue()
hasValue(value): boolean;
Defined in: data-structures/base/iterable-entry-base.ts:143
Whether there exists an entry with the given value.
Parameters
value
V
Value to test.
Returns
boolean
true if found; otherwise false.
Remarks
Time O(n), Space O(1)
Inherited from
isEmpty()
isEmpty(): boolean;
Defined in: data-structures/hash/hash-map.ts:1149
Whether there are no entries.
Returns
boolean
true if empty; false otherwise.
Remarks
Time O(1) typical, Space O(1)
Overrides
keys()
keys(): IterableIterator<K>;
Defined in: data-structures/base/iterable-entry-base.ts:42
Iterate over keys only.
Returns
IterableIterator<K>
Iterator of keys.
Remarks
Time O(n), Space O(1)
Inherited from
map()
map<MK, MV>(callback, thisArg?): LinkedHashMap<MK, MV>;
Defined in: data-structures/hash/hash-map.ts:1187
Map each entry to a new [key, value] pair and preserve order.
Type Parameters
MK
MK
MV
MV
Parameters
callback
EntryCallback<K, V, [MK, MV]>
Mapping function (key, value, index, map) → [newKey, newValue].
thisArg?
unknown
Value for this inside the callback.
Returns
LinkedHashMap<MK, MV>
A new map of the same class with transformed entries.
Remarks
Time O(N), Space O(N)
Overrides
print()
print(): void;
Defined in: data-structures/base/iterable-entry-base.ts:203
Print a human-friendly representation to the console.
Returns
void
Remarks
Time O(n), Space O(n)
Inherited from
reduce()
reduce<U>(callbackfn, initialValue): U;
Defined in: data-structures/base/iterable-entry-base.ts:171
Reduce entries into a single accumulator.
Type Parameters
U
U
Parameters
callbackfn
ReduceEntryCallback<K, V, U>
(acc, value, key, index, self) => acc.
initialValue
U
Initial accumulator.
Returns
U
Final accumulator.
Remarks
Time O(n), Space O(1)
Inherited from
reverseBegin()
reverseBegin(): Generator<(K | V | undefined)[], void, unknown>;
Defined in: data-structures/hash/hash-map.ts:996
Iterate from tail → head.
Returns
Generator<(K | V | undefined)[], void, unknown>
Iterator of [key, value].
Remarks
Time O(N), Space O(1)
set()
set(key, value?): boolean;
Defined in: data-structures/hash/hash-map.ts:1011
Insert or replace a single entry; preserves insertion order.
Parameters
key
K
Key.
value?
V
Value.
Returns
boolean
True when the operation succeeds.
Remarks
Time O(1), Space O(1)
some()
some(predicate, thisArg?): boolean;
Defined in: data-structures/base/iterable-entry-base.ts:83
Test whether any entry satisfies the predicate.
Parameters
predicate
EntryCallback<K, V, boolean>
(key, value, index, self) => boolean.
thisArg?
unknown
Optional this for callback.
Returns
boolean
true if any passes; otherwise false.
Remarks
Time O(n), Space O(1)
Inherited from
toArray()
toArray(): [K, V][];
Defined in: data-structures/base/iterable-entry-base.ts:186
Converts data structure to [key, value] pairs.
Returns
[K, V][]
Array of entries.
Remarks
Time O(n), Space O(n)
Inherited from
toVisual()
toVisual(): string | [K, V][];
Defined in: data-structures/base/iterable-entry-base.ts:195
Visualize the iterable as an array of [key, value] pairs (or a custom string).
Returns
string | [K, V][]
Array of entries (default) or a string.
Remarks
Time O(n), Space O(n)
Inherited from
values()
values(): IterableIterator<V>;
Defined in: data-structures/base/iterable-entry-base.ts:53
Iterate over values only.
Returns
IterableIterator<V>
Iterator of values.
Remarks
Time O(n), Space O(1)
Inherited from
Protected Members
_getIterator()
protected _getIterator(): IterableIterator<[K, V]>;
Defined in: data-structures/hash/hash-map.ts:1198
Underlying iterator for the default iteration protocol.
Returns
IterableIterator<[K, V]>
Iterator of [K, V].
Remarks
Time O(n), Space O(1)
Overrides
IterableEntryBase._getIterator