Class LinkedHashMap<K, V, R>

  1. Maintaining the Order of Element Insertion: Unlike HashMap, LinkedHashMap maintains the order in which entries are inserted. Therefore, when you traverse it, entries will be returned in the order they were inserted into the map.
  2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of entries through the linked list.
  3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.

Type Parameters

  • K = any

  • V = any

  • R = [K, V]

Hierarchy

Constructors

  • The constructor initializes a LinkedHashMap object with an optional raw collection and options.

    Type Parameters

    • K = any

    • V = any

    • R = [K, V]

    Parameters

    • entryOrRawElements: Iterable<R> = []

      The entryOrRawElements parameter is an iterable collection of elements. It is used to initialize the HashMapLinked instance with key-value pairs. Each element in the entryOrRawElements is converted to a key-value pair using the toEntryFn function (if provided) and then added to the HashMap

    • Optional options: LinkedHashMapOptions<K, V, R>

      The options parameter is an optional object that can contain the following properties:

    Returns LinkedHashMap<K, V, R>

Accessors

  • get first(): undefined | [K, V]
  • Time Complexity: O(1) Space Complexity: O(1)

    The function returns the key-value pair at the front of a data structure.

    Returns undefined | [K, V]

    The front element of the data structure, represented as a tuple with a key (K) and a value (V).

  • get hashFn(): ((key) => string)
  • The function returns the hash function used for generating a hash value for a given key.

    Returns ((key) => string)

    The hash function that takes a key of type K and returns a string.

      • (key): string
      • The function returns the hash function used for generating a hash value for a given key.

        Parameters

        • key: K

        Returns string

        The hash function that takes a key of type K and returns a string.

  • get head(): HashMapLinkedNode<K, undefined | V>
  • The function returns the head node of a HashMapLinkedNode.

    Returns HashMapLinkedNode<K, undefined | V>

    The method getHead() is returning a HashMapLinkedNode object with key type K and a value type V | undefined.

  • get last(): undefined | [K, V]
  • Time Complexity: O(1) Space Complexity: O(1)

    The function returns the key-value pair at the end of a data structure.

    Returns undefined | [K, V]

    The method is returning an array containing the key-value pair of the tail element in the data structure.

  • get noObjMap(): Record<string, HashMapLinkedNode<K, undefined | V>>
  • The function returns a record of HashMapLinkedNode objects with string keys.

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

    The method is returning a Record object, which is a TypeScript type that represents an object with string keys and values that are HashMapLinkedNode objects with keys of type K and values of type V or undefined.

  • get objHashFn(): ((key) => object)
  • The function returns the object hash function.

    Returns ((key) => object)

    The function objHashFn is being returned.

      • (key): object
      • The function returns the object hash function.

        Parameters

        • key: K

        Returns object

        The function objHashFn is being returned.

  • get objMap(): WeakMap<object, HashMapLinkedNode<K, undefined | V>>
  • The function returns the WeakMap object used to map objects to HashMapLinkedNode instances.

    Returns WeakMap<object, HashMapLinkedNode<K, undefined | V>>

    The objMap property is being returned.

  • get size(): number
  • The function returns the size of an object.

    Returns number

    The size of the object.

  • get tail(): HashMapLinkedNode<K, undefined | V>
  • The function returns the tail node of a HashMapLinkedNode.

    Returns HashMapLinkedNode<K, undefined | V>

    The _tail property of type HashMapLinkedNode<K, V | undefined> is being returned.

  • get toEntryFn(): ((rawElement) => [K, V])
  • The function returns the value of the _toEntryFn property.

    Returns ((rawElement) => [K, V])

    The function being returned is this._toEntryFn.

      • (rawElement): [K, V]
      • Parameters

        • rawElement: R

        Returns [K, V]

Methods

  • Time Complexity: O(n) Space Complexity: O(1)

    The function is an implementation of the Symbol.iterator method that returns an iterable iterator.

    Parameters

    • Rest ...args: any[]

      The args parameter in the code snippet represents a rest parameter. It allows the function to accept any number of arguments as an array. In this case, the args parameter is used to pass any additional arguments to the _getIterator method.

    Returns IterableIterator<[K, V]>

  • Time Complexity: O(1) Space Complexity: O(1)

    The _deleteNode function removes a node from a doubly linked list and updates the head and tail pointers if necessary.

    Parameters

    • node: HashMapLinkedNode<K, undefined | V>

      The node parameter is an instance of the HashMapLinkedNode class, which represents a node in a linked list. It contains a key-value pair and references to the previous and next nodes in the list.

    Returns boolean

  • Time Complexity: O(n) Space Complexity: O(1) where n is the number of entries in the LinkedHashMap.

    The above function is an iterator that yields key-value pairs from a linked list.

    Returns Generator<[K, V], void, unknown>

  • Time Complexity: O(n) Space Complexity: O(1)

    The function at retrieves the key-value pair at a specified index in a linked list.

    Parameters

    • index: number

      The index parameter is a number that represents the position of the element we want to retrieve from the data structure.

    Returns undefined | V

    The method at(index: number) is returning an array containing the key-value pair at the specified index in the data structure. The key-value pair is represented as a tuple [K, V], where K is the key and V is the value.

  • The begin() function in TypeScript iterates over a linked list and yields key-value pairs.

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

  • Time Complexity: O(1) Space Complexity: O(1)

    The clear function clears all the entries in a data structure and resets its properties.

    Returns void

  • Time Complexity: O(n) Space Complexity: O(n)

    The clone function creates a new instance of a LinkedHashMap with the same key-value pairs as the original.

    Returns LinkedHashMap<K, V, [K, V]>

    The clone() method is returning a new instance of LinkedHashMap<K, V> that is a clone of the original LinkedHashMap object.

  • Time Complexity: O(1) Space Complexity: O(1)

    The delete function removes a key-value pair from a map-like data structure.

    Parameters

    • key: K

      The key parameter is the key that you want to delete from the data structure. It can be of any type, but typically it is a string or an object.

    Returns boolean

    a boolean value. It returns true if the deletion was successful, and false if the key was not found.

  • Time Complexity: O(n) Space Complexity: O(1)

    The deleteAt function deletes a node at a specified index in a linked list.

    Parameters

    • index: number

      The index parameter represents the position at which the node should be deleted in the linked list.

    Returns boolean

    The size of the list after deleting the element at the specified index.

  • Time Complexity: O(n) Space Complexity: O(n)

    The function returns an iterator that yields key-value pairs from the object, where the value can be undefined.

    Returns IterableIterator<[K, undefined | V]>

  • Time Complexity: O(n) Space Complexity: O(1)

    The every function checks if every element in a collection satisfies a given condition.

    Parameters

    • predicate: EntryCallback<K, V, boolean>

      The predicate parameter is a callback function that takes three arguments: value, key, and index. It should return a boolean value indicating whether the condition is met for the current element in the iteration.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the predicate function. If thisArg is provided, it will be passed as the first argument to the predicate function. If thisArg is not provided

    Returns boolean

    The every method is returning a boolean value. It returns true if every element in the collection satisfies the provided predicate function, and false otherwise.

  • Time Complexity: O(n) Space Complexity: O(n)

    The filter function creates a new LinkedHashMap containing key-value pairs from the original map that satisfy a given predicate function.

    Parameters

    • predicate: EntryCallback<K, V, boolean>

      The predicate parameter is a callback function that takes four arguments: value, key, index, and this. It should return a boolean value indicating whether the current element should be included in the filtered map or not.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that allows you to specify the value of this within the predicate function. It is used when you want to bind a specific object as the context for the predicate function. If thisArg is not provided, this @returns a new LinkedHashMapobject that contains the key-value pairs from the originalLinkedHashMap` object that satisfy the given predicate function.

    Returns LinkedHashMap<K, V, [K, V]>

  • Time Complexity: O(n) Space Complexity: O(1)

    The find function iterates over the entries of a collection and returns the first value for which the callback function returns true.

    Parameters

    • callbackfn: EntryCallback<K, V, [K, V]>

      The callback function that will be called for each entry in the collection. It takes three arguments: the value of the entry, the key of the entry, and the index of the entry in the collection. It should return a boolean value indicating whether the current entry matches the desired condition.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the callbackfn function. If thisArg is provided, it will be passed as the this value to the callbackfn function. If thisArg @returns The method findreturns the value of the first element in the iterable that satisfies the provided callback function. If no element satisfies the callback function,undefined` is returned.

    Returns undefined | [K, V]

  • Time Complexity: O(n) Space Complexity: O(1)

    The forEach function iterates over each key-value pair in a collection and executes a callback function for each pair.

    Parameters

    • callbackfn: EntryCallback<K, V, void>

      The callback function that will be called for each element in the collection. It takes four parameters: the value of the current element, the key of the current element, the index of the current element, and the collection itself.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that allows you to specify the value of this within the callback function. If thisArg is provided, it will be used as the this value when calling the callback function. If thisArg is not provided, `

    Returns void

  • Time Complexity: O(1) Space Complexity: O(1)

    The function get retrieves the value associated with a given key from a map, either by using the key directly or by using an index stored in the key object.

    Parameters

    • key: K

      The key parameter is the key used to retrieve a value from the map. It can be of any type, but typically it is a string or symbol.

    Returns undefined | V

    The value associated with the given key is being returned. If the key is an object key, the value is retrieved from the _nodes array using the index stored in the OBJ_KEY_INDEX property of the key. If the key is a string key, the value is retrieved from the _noObjMap object using the key itself. If the key is not found, undefined is

  • The function checks if a given key exists in a map, using different logic depending on whether the key is a weak key or not.

    Parameters

    • key: K

      The key parameter is the key that is being checked for existence in the map.

    Returns boolean

    The method has is returning a boolean value.

  • Time Complexity: O(n) Space Complexity: O(1)

    The function checks if a given value exists in a collection.

    Parameters

    • value: V

      The parameter "value" is the value that we want to check if it exists in the collection.

    Returns boolean

    a boolean value, either true or false.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function checks if a data structure is empty by comparing its size to zero.

    Returns boolean

    The method is returning a boolean value indicating whether the size of the object is 0 or not.

  • The function checks if a given element is an array with exactly two elements.

    Parameters

    • rawElement: any

      The rawElement parameter is of type any, which means it can be any data type.

    Returns rawElement is [K, V]

    a boolean value.

  • Time Complexity: O(n) Space Complexity: O(n)

    The map function in TypeScript creates a new LinkedHashMap by applying a callback function to each key-value pair in the original map.

    Type Parameters

    • VM

    Parameters

    • callback: EntryCallback<K, V, VM>

      The callback parameter is a function that will be called for each key-value pair in the map. It takes four arguments: the value of the current key-value pair, the key of the current key-value pair, the index of the current key-value pair, and the map itself. The callback function should

    • Optional thisArg: any

      The thisArg parameter is an optional argument that allows you to specify the value of this within the callback function. If provided, the callback function will be called with thisArg as its this value. If not provided, this will refer to the current map

    Returns LinkedHashMap<K, VM, [K, VM]>

    a new LinkedHashMap object with the values mapped according to the provided callback function.

  • Time Complexity: O(1) Space Complexity: O(1)

    The put function sets a value in a data structure using a specified key.

    Parameters

    • key: K

      The key parameter is of type K, which represents the type of the key being passed to the function.

    • value: V

      The value parameter represents the value that you want to associate with the specified key in the data structure.

    Returns boolean

    The method is returning a boolean value.

  • Time Complexity: O(n) Space Complexity: O(1)

    The reduce function iterates over key-value pairs and applies a callback function to each pair, accumulating a single value.

    Type Parameters

    • U

    Parameters

    • callbackfn: ReduceEntryCallback<K, V, U>

      The callback function that will be called for each element in the collection. It takes four arguments: the current accumulator value, the current value of the element, the key of the element, and the index of the element in the collection. It should return the updated accumulator value.

    • initialValue: U

      The initialValue parameter is the initial value of the accumulator. It is the value that will be used as the first argument to the callbackfn function when reducing the elements of the collection.

    Returns U

    The reduce method is returning the final value of the accumulator after iterating over all the elements in the collection.

  • The function reverseBegin() iterates over a linked list in reverse order, yielding each node's key and value.

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

  • Time Complexity: O(1) Space Complexity: O(1)

    The set function adds a new key-value pair to a data structure, either using an object key or a string key.

    Parameters

    • key: K

      The key parameter is the key to be set in the data structure. It can be of any type, but typically it is a string or symbol.

    • Optional value: V

      The value parameter is an optional parameter of type V. It represents the value associated with the key being set in the data structure.

    Returns boolean

    the size of the data structure after the key-value pair has been set.

  • The function setMany takes an iterable collection, converts each element into a key-value pair using a provided function, and sets each key-value pair in the current object, returning an array of booleans indicating the success of each set operation.

    Parameters

    • entryOrRawElements: Iterable<R>

      The entryOrRawElements parameter is an iterable collection of elements of type R.

    Returns boolean[]

    The setMany function returns an array of booleans.

  • Time Complexity: O(n) Space Complexity: O(1)

    The "some" function iterates over a collection and returns true if at least one element satisfies a given predicate.

    Parameters

    • predicate: EntryCallback<K, V, boolean>

      The predicate parameter is a callback function that takes three arguments: value, key, and index. It should return a boolean value indicating whether the condition is met for the current element in the iteration.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as the this value when executing the predicate function. If thisArg is provided, it will be passed as the first argument to the predicate function. If thisArg is

    Returns boolean

    a boolean value. It returns true if the predicate function returns true for any pair in the collection, and false otherwise.

Generated using TypeDoc