Class HashMap<K, V, R>

  1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key map to a value.
  2. Fast Lookup: It's used when you need to quickly find, insert, or delete entries based on a key.
  3. Unique Keys: Keys are unique. If you try to insert another entry with the same key, the new one will replace the old entry.
  4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.

Type Parameters

  • K = any

  • V = any

  • R = [K, V]

Hierarchy

Constructors

  • The constructor function initializes a HashMap object with an optional initial collection and options.

    Type Parameters

    • K = any

    • V = any

    • R = [K, V]

    Parameters

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

      The entryOrRawElements parameter is an iterable collection of elements of a type T. It is an optional parameter and its default value is an empty array [].

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

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

    Returns HashMap<K, V, R>

Accessors

  • get hashFn(): ((key) => string)
  • The hasFn function is a function that takes in an item and returns a boolean indicating whether the item is contained within the hash table.

    Returns ((key) => string)

    The hash function

      • (key): string
      • Parameters

        • key: K

        Returns string

  • get objMap(): Map<object, V>
  • The function returns the object map.

    Returns Map<object, V>

    The objMap property is being returned, which is a Map object with keys of type object and values of type V.

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

    Returns number

    The size of the object, which is a number.

  • get store(): {
        [p: string]: HashMapStoreItem<K, V>;
    }
  • The function returns the store object, which is a dictionary of HashMapStoreItem objects.

    Returns {
        [p: string]: HashMapStoreItem<K, V>;
    }

    The store property is being returned. It is a dictionary-like object with string keys and values of type HashMapStoreItem<K, V>.

    • [p: string]: HashMapStoreItem<K, V>
  • get toEntryFn(): undefined | ((rawElement) => [K, V])
  • The function returns the value of the _toEntryFn property.

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

    The function being returned is this._toEntryFn.

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]>

  • The function returns an iterator that yields key-value pairs from both an object store and an object map.

    Returns IterableIterator<[K, V]>

  • The function _getNoObjKey takes a key and returns a string representation of the key, handling different types of keys.

    Parameters

    • key: K

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

    Returns string

    a string value.

  • The function checks if a given key is an object or a function.

    Parameters

    • key: any

      The parameter "key" can be of any type.

    Returns key is object | ((...args) => any)

    a boolean value.

  • The clear() function resets the state of an object by clearing its internal store, object map, and size.

    Returns void

  • The clone function creates a new HashMap with the same key-value pairs as this one. The clone function is useful for creating a copy of an existing HashMap, and then modifying that copy without affecting the original.

    Returns HashMap<K, V, R>

    A new hashmap with the same values as this one

  • The delete function removes an element from a map-like data structure based on the provided key.

    Parameters

    • key: K

      The key parameter is the key of the element that you want to delete from the data structure.

    Returns boolean

    The delete method returns a boolean value. It returns true if the key was successfully deleted from the map, and false if the key was not found in the map.

  • 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 HashMap containing key-value pairs from the original HashMap that satisfy a given predicate function.

    Parameters

    • predicate: EntryCallback<K, V, boolean>

      The predicate parameter is a function that takes four arguments: value, key, index, and map. It is used to determine whether an element should be included in the filtered map or not. The function should return a boolean value - true if the element should be included, and false otherwise.

    • 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 this value to the predicate function. If thisArg is

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

    The filter method is returning a new HashMap object that contains the key-value pairs from the original HashMap that pass the provided predicate function.

  • 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

  • The get function retrieves a value from a map based on a given key, either from an object map or a string map.

    Parameters

    • key: K

      The key parameter is the key used to retrieve a value from the map. It can be of any type, but it should be compatible with the key type used when the map was created.

    Returns undefined | V

    The method get(key: K) returns a value of type V if the key exists in the _objMap or _store, otherwise it returns undefined.

  • The has function checks if a given key exists in the _objMap or _store based on whether it is an object key or not.

    Parameters

    • key: K

      The parameter "key" is of type K, which means it can be any type.

    Returns boolean

    The has method 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.

  • The function checks if the size of an object is equal to zero and returns a boolean value.

    Returns boolean

    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 HashMap by applying a callback function to each key-value pair in the original HashMap.

    Type Parameters

    • VM

    Parameters

    • callbackfn: EntryCallback<K, V, VM>

      The callback function that will be called for each key-value pair in the HashMap. It takes four parameters:

    • 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 mapmethod is returning a newHashMap` object with the transformed values based on the provided callback function.

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

  • 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 set function adds a key-value pair to a map-like data structure, incrementing the size if the key is not already present.

    Parameters

    • key: K

      The key parameter is the key used to identify the value in the data structure. It can be of any type, but if it is an object, it will be stored in a Map, otherwise it will be stored in a regular JavaScript object.

    • value: V

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

    Returns boolean

  • The function setMany takes an iterable collection of objects, maps each object to a key-value pair using a mapping function, and sets each key-value pair in the current object.

    Parameters

    • entryOrRawElements: Iterable<[K, V] | R>

      The entryOrRawElements parameter is an iterable collection of elements of a type T.

    Returns boolean[]

    The setMany function is returning 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