[**data-structure-typed**](../README.md)

***

[data-structure-typed](../README.md) / LinkedHashMap

# Class: LinkedHashMap\<K, V, R\>

Defined in: [data-structures/hash/hash-map.ts:953](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L953)

Hash-based map that preserves insertion order via a doubly-linked list.

## Remarks

Time O(1), Space O(1)

## Example

```ts
examples will be generated by unit test
```

## Extends

- [`IterableEntryBase`](IterableEntryBase.md)\<`K`, `V`\>

## Type Parameters

### K

`K` = `any`

### V

`V` = `any`

### R

`R` = \[`K`, `V`\]

## Constructors

### Constructor

```ts
new LinkedHashMap<K, V, R>(entryOrRawElements?, options?): LinkedHashMap<K, V, R>;
```

Defined in: [data-structures/hash/hash-map.ts:963](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L963)

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

```ts
IterableEntryBase<K, V>.constructor
```

## Accessors

### first

#### Get Signature

```ts
get first(): [K, V] | undefined;
```

Defined in: [data-structures/hash/hash-map.ts:1053](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1053)

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

```ts
get head(): HashMapLinkedNode<K, V | undefined>;
```

Defined in: [data-structures/hash/hash-map.ts:1017](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1017)

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

```ts
get last(): [K, V] | undefined;
```

Defined in: [data-structures/hash/hash-map.ts:1063](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1063)

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

```ts
get noObjMap(): Record<string, HashMapLinkedNode<K, V | undefined>>;
```

Defined in: [data-structures/hash/hash-map.ts:1001](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1001)

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

```ts
get objHashFn(): (key) => object;
```

Defined in: [data-structures/hash/hash-map.ts:990](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L990)

Get the hash function for object/weak keys.

##### Remarks

Time O(1), Space O(1)

##### Returns

Object-hash function.

(`key`) => `object`

***

### size

#### Get Signature

```ts
get size(): number;
```

Defined in: [data-structures/hash/hash-map.ts:1044](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1044)

Total number of entries.

##### Remarks

Time O(1), Space O(1)

##### Returns

`number`

Entry count.

#### Overrides

[`IterableEntryBase`](IterableEntryBase.md).[`size`](IterableEntryBase.md#size)

***

### tail

#### Get Signature

```ts
get tail(): HashMapLinkedNode<K, V | undefined>;
```

Defined in: [data-structures/hash/hash-map.ts:1028](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1028)

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\]()

```ts
iterator: IterableIterator<[K, V]>;
```

Defined in: [data-structures/base/iterable-entry-base.ts:22](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L22)

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

[`IterableEntryBase`](IterableEntryBase.md).[`[iterator]`](IterableEntryBase.md#iterator)

***

### at()

```ts
at(index): V | undefined;
```

Defined in: [data-structures/hash/hash-map.ts:1181](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1181)

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()

```ts
begin(): Generator<(K | V | undefined)[], void, unknown>;
```

Defined in: [data-structures/hash/hash-map.ts:1073](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1073)

Iterate from head → tail.

#### Returns

`Generator`\<(`K` \| `V` \| `undefined`)[], `void`, `unknown`\>

Iterator of [key, value].

#### Remarks

Time O(N), Space O(1)

***

### clear()

```ts
clear(): void;
```

Defined in: [data-structures/hash/hash-map.ts:1254](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1254)

Remove all entries.

#### Returns

`void`

#### Remarks

Time O(n) typical, Space O(1)

#### Overrides

[`IterableEntryBase`](IterableEntryBase.md).[`clear`](IterableEntryBase.md#clear)

***

### clone()

```ts
clone(): this;
```

Defined in: [data-structures/hash/hash-map.ts:1260](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1260)

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

[`IterableEntryBase`](IterableEntryBase.md).[`clone`](IterableEntryBase.md#clone)

***

### deleteAt()

```ts
deleteAt(index): [K, V | undefined];
```

Defined in: [data-structures/hash/hash-map.ts:1237](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1237)

Delete the entry at a given index.

#### Parameters

##### index

`number`

Zero-based index.

#### Returns

\[`K`, `V` \| `undefined`\]

The removed entry [key, value].

#### Remarks

Time O(N), Space O(1)

#### Throws

If index is out of bounds.

***

### deleteWhere()

```ts
deleteWhere(predicate): boolean;
```

Defined in: [data-structures/hash/hash-map.ts:1210](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1210)

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()

```ts
entries(): IterableIterator<[K, V | undefined]>;
```

Defined in: [data-structures/base/iterable-entry-base.ts:31](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L31)

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

[`IterableEntryBase`](IterableEntryBase.md).[`entries`](IterableEntryBase.md#entries)

***

### every()

```ts
every(predicate, thisArg?): boolean;
```

Defined in: [data-structures/base/iterable-entry-base.ts:66](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L66)

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

[`IterableEntryBase`](IterableEntryBase.md).[`every`](IterableEntryBase.md#every)

***

### filter()

```ts
filter(predicate, thisArg?): this;
```

Defined in: [data-structures/hash/hash-map.ts:1265](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1265)

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

[`IterableEntryBase`](IterableEntryBase.md).[`filter`](IterableEntryBase.md#filter)

***

### find()

```ts
find(callbackfn, thisArg?): [K, V] | undefined;
```

Defined in: [data-structures/base/iterable-entry-base.ts:114](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L114)

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

[`IterableEntryBase`](IterableEntryBase.md).[`find`](IterableEntryBase.md#find)

***

### forEach()

```ts
forEach(callbackfn, thisArg?): void;
```

Defined in: [data-structures/base/iterable-entry-base.ts:99](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L99)

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

[`IterableEntryBase`](IterableEntryBase.md).[`forEach`](IterableEntryBase.md#foreach)

***

### get()

```ts
get(key): V | undefined;
```

Defined in: [data-structures/hash/hash-map.ts:1164](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1164)

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

[`IterableEntryBase`](IterableEntryBase.md).[`get`](IterableEntryBase.md#get)

***

### has()

```ts
has(key): boolean;
```

Defined in: [data-structures/hash/hash-map.ts:1155](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1155)

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

[`IterableEntryBase`](IterableEntryBase.md).[`has`](IterableEntryBase.md#has)

***

### hasValue()

```ts
hasValue(value): boolean;
```

Defined in: [data-structures/base/iterable-entry-base.ts:143](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L143)

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

[`IterableEntryBase`](IterableEntryBase.md).[`hasValue`](IterableEntryBase.md#hasvalue)

***

### isEmpty()

```ts
isEmpty(): boolean;
```

Defined in: [data-structures/hash/hash-map.ts:1246](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1246)

Whether there are no entries.

#### Returns

`boolean`

`true` if empty; `false` otherwise.

#### Remarks

Time O(1) typical, Space O(1)

#### Overrides

[`IterableEntryBase`](IterableEntryBase.md).[`isEmpty`](IterableEntryBase.md#isempty)

***

### keys()

```ts
keys(): IterableIterator<K>;
```

Defined in: [data-structures/base/iterable-entry-base.ts:42](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L42)

Iterate over keys only.

#### Returns

`IterableIterator`\<`K`\>

Iterator of keys.

#### Remarks

Time O(n), Space O(1)

#### Inherited from

[`IterableEntryBase`](IterableEntryBase.md).[`keys`](IterableEntryBase.md#keys)

***

### map()

```ts
map<MK, MV>(callback, thisArg?): LinkedHashMap<MK, MV>;
```

Defined in: [data-structures/hash/hash-map.ts:1284](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1284)

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

[`IterableEntryBase`](IterableEntryBase.md).[`map`](IterableEntryBase.md#map)

***

### print()

```ts
print(): void;
```

Defined in: [data-structures/base/iterable-entry-base.ts:203](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L203)

Print a human-friendly representation to the console.

#### Returns

`void`

#### Remarks

Time O(n), Space O(n)

#### Inherited from

[`IterableEntryBase`](IterableEntryBase.md).[`print`](IterableEntryBase.md#print)

***

### reduce()

```ts
reduce<U>(callbackfn, initialValue): U;
```

Defined in: [data-structures/base/iterable-entry-base.ts:171](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L171)

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

[`IterableEntryBase`](IterableEntryBase.md).[`reduce`](IterableEntryBase.md#reduce)

***

### reverseBegin()

```ts
reverseBegin(): Generator<(K | V | undefined)[], void, unknown>;
```

Defined in: [data-structures/hash/hash-map.ts:1086](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1086)

Iterate from tail → head.

#### Returns

`Generator`\<(`K` \| `V` \| `undefined`)[], `void`, `unknown`\>

Iterator of [key, value].

#### Remarks

Time O(N), Space O(1)

***

### set()

```ts
set(key, value?): this;
```

Defined in: [data-structures/hash/hash-map.ts:1101](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1101)

Insert or replace a single entry; preserves insertion order.

#### Parameters

##### key

`K`

Key.

##### value?

`V`

Value.

#### Returns

`this`

This map (for chaining).

#### Remarks

Time O(1), Space O(1)

***

### some()

```ts
some(predicate, thisArg?): boolean;
```

Defined in: [data-structures/base/iterable-entry-base.ts:83](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L83)

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

[`IterableEntryBase`](IterableEntryBase.md).[`some`](IterableEntryBase.md#some)

***

### toArray()

```ts
toArray(): [K, V][];
```

Defined in: [data-structures/base/iterable-entry-base.ts:186](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L186)

Converts data structure to `[key, value]` pairs.

#### Returns

\[`K`, `V`\][]

Array of entries.

#### Remarks

Time O(n), Space O(n)

#### Inherited from

[`IterableEntryBase`](IterableEntryBase.md).[`toArray`](IterableEntryBase.md#toarray)

***

### toVisual()

```ts
toVisual(): string | [K, V][];
```

Defined in: [data-structures/base/iterable-entry-base.ts:195](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L195)

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

[`IterableEntryBase`](IterableEntryBase.md).[`toVisual`](IterableEntryBase.md#tovisual)

***

### values()

```ts
values(): IterableIterator<V>;
```

Defined in: [data-structures/base/iterable-entry-base.ts:53](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L53)

Iterate over values only.

#### Returns

`IterableIterator`\<`V`\>

Iterator of values.

#### Remarks

Time O(n), Space O(1)

#### Inherited from

[`IterableEntryBase`](IterableEntryBase.md).[`values`](IterableEntryBase.md#values)


---

## Protected Members

### \_getIterator()

```ts
protected _getIterator(): IterableIterator<[K, V]>;
```

Defined in: [data-structures/hash/hash-map.ts:1295](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L1295)

Underlying iterator for the default iteration protocol.

#### Returns

`IterableIterator`\<\[`K`, `V`\]\>

Iterator of `[K, V]`.

#### Remarks

Time O(n), Space O(1)

#### Overrides

[`IterableEntryBase`](IterableEntryBase.md).[`_getIterator`](IterableEntryBase.md#_getiterator)

***
