Class LinkedHashMap<K, V, R>

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

Time O(1), Space O(1)

examples will be generated by unit test

Type Parameters

  • K = any
  • V = any
  • R = [K, V]

Hierarchy (view full)

Constructors

  • Create a LinkedHashMap and optionally bulk-insert entries.

    Type Parameters

    • K = any
    • V = any
    • R = [K, V]

    Parameters

    • OptionalentryOrRawElements: Iterable<[K, V] | R, any, any> = []

      Iterable of entries or raw elements to insert.

    • Optionaloptions: LinkedHashMapOptions<K, V, R>

      Options: hash functions and optional record-to-entry converter.

    Returns LinkedHashMap<K, V, R>

    New LinkedHashMap instance.

    Time O(N), Space O(N)

Accessors

  • get first(): undefined | [K, V]
  • Get the first [key, value] pair.

    Returns undefined | [K, V]

    First entry or undefined when empty.

    Time O(1), Space O(1)

  • get head(): HashMapLinkedNode<K, undefined | V>
  • Get the head node (first entry) sentinel link.

    Returns HashMapLinkedNode<K, undefined | V>

    Head node or sentinel.

    Time O(1), Space O(1)

  • get last(): undefined | [K, V]
  • Get the last [key, value] pair.

    Returns undefined | [K, V]

    Last entry or undefined when empty.

    Time O(1), Space O(1)

  • get noObjMap(): Record<string, HashMapLinkedNode<K, undefined | V>>
  • Get the internal record for non-object keys.

    Returns Record<string, HashMapLinkedNode<K, undefined | V>>

    Record of hash→node.

    Time O(1), Space O(1)

  • get objHashFn(): ((key: K) => object)
  • Get the hash function for object/weak keys.

    Returns ((key: K) => object)

    Object-hash function.

      • (key): object
      • Parameters

        • key: K

        Returns object

    Time O(1), Space O(1)

  • get tail(): HashMapLinkedNode<K, undefined | V>
  • Get the tail node (last entry) sentinel link.

    Returns HashMapLinkedNode<K, undefined | V>

    Tail node or sentinel.

    Time O(1), Space O(1)

Methods

  • Get the value at a given index in insertion order.

    Parameters

    • index: number

      Zero-based index.

    Returns undefined | V

    Value at the index.

    Time O(N), Space O(1)

  • Iterate from head → tail.

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

    Iterator of [key, value].

    Time O(N), Space O(1)

  • Delete the entry at a given index.

    Parameters

    • index: number

      Zero-based index.

    Returns boolean

    True if removed.

    Time O(N), Space O(1)

  • Delete the first entry that matches a predicate.

    Parameters

    • predicate: ((key: K, value: undefined | V, index: number, map: this) => boolean)

      Function (key, value, index, map) → boolean to decide deletion.

        • (key, value, index, map): boolean
        • Parameters

          • key: K
          • value: undefined | V
          • index: number
          • map: this

          Returns boolean

    Returns boolean

    True if an entry was removed.

    Time O(N), Space O(1)

  • Test whether all entries satisfy the predicate.

    Parameters

    • predicate: EntryCallback<K, V, boolean>

      (key, value, index, self) => boolean.

    • OptionalthisArg: any

      Optional this for callback.

    Returns boolean

    true if all pass; otherwise false.

    Time O(n), Space O(1)

  • Filter entries and return the same-species structure.

    Parameters

    • predicate: EntryCallback<K, V, boolean>
    • OptionalthisArg: any

    Returns any

    A new instance of the same concrete class (this type).

    Time O(n), Space O(n)

  • Find the first entry that matches a predicate.

    Parameters

    • callbackfn: EntryCallback<K, V, boolean>

      (key, value, index, self) => boolean.

    • OptionalthisArg: any

      Optional this for callback.

    Returns undefined | [K, V]

    Matching [key, value] or undefined.

    Time O(n), Space O(1)

  • Map each entry to a new [key, value] pair and preserve order.

    Type Parameters

    • MK
    • MV

    Parameters

    • callback: EntryCallback<K, V, [MK, MV]>

      Mapping function (key, value, index, map) → [newKey, newValue].

    • OptionalthisArg: any

      Value for this inside the callback.

    Returns any

    A new map of the same class with transformed entries.

    Time O(N), Space O(N)

  • Iterate from tail → head.

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

    Iterator of [key, value].

    Time O(N), Space O(1)

  • Insert or replace a single entry; preserves insertion order.

    Parameters

    • key: K

      Key.

    • Optionalvalue: V

      Value.

    Returns boolean

    True when the operation succeeds.

    Time O(1), Space O(1)

  • Test whether any entry satisfies the predicate.

    Parameters

    • predicate: EntryCallback<K, V, boolean>

      (key, value, index, self) => boolean.

    • OptionalthisArg: any

      Optional this for callback.

    Returns boolean

    true if any passes; otherwise false.

    Time O(n), Space O(1)