Class HashTable<K, V>

Type Parameters

  • K

  • V

Hierarchy

  • HashTable

Constructors

Properties

_buckets: (null | HashTableNode<K, V>)[]
_capacity: number
_hashFn: HashFunction<K>
_size: number
DEFAULT_CAPACITY: 16 = 16
LOAD_FACTOR: 0.75 = 0.75

Accessors

Methods

  • The function _defaultHashFn calculates the hash value of a given key and returns the remainder when divided by the capacity of the data structure.

    Parameters

    • key: K

      The key parameter is the input value that needs to be hashed. It can be of any type, but in this code snippet, it is checked whether the key is a string or an object. If it is a string, the _murmurStringHashFn function is used to

    Returns number

    the hash value of the key modulo the capacity of the data structure.

  • The expand function increases the capacity of a hash table by creating a new array of buckets with double the capacity and rehashing all the existing key-value pairs into the new buckets.

    Returns void

  • The _hash function takes a key and returns a number.

    Parameters

    • key: K

      The parameter "key" is of type K, which represents the type of the key that will be hashed.

    Returns number

    The hash function is returning a number.

  • The _multiplicativeStringHashFn function calculates a hash value for a given string key using the multiplicative string hash function.

    Type Parameters

    • K

    Parameters

    • key: K

      The key parameter is the input value for which we want to calculate the hash. It can be of any type, as it is generic (K). The function converts the key to a string using the String() function.

    Returns number

    a number, which is the result of the multiplicative string hash function applied to the input key.

  • The function _murmurStringHashFn calculates a hash value for a given string key using the MurmurHash algorithm.

    Type Parameters

    • K

    Parameters

    • key: K

      The key parameter is the input value for which you want to calculate the hash. It can be of any type, but it will be converted to a string using the String() function before calculating the hash.

    Returns number

    a number, which is the hash value calculated for the given key.

  • The function _objectHash takes a key and returns a hash value, using a custom hash function for objects.

    Parameters

    • key: K

      The parameter "key" is of type "K", which means it can be any type. It could be a string, number, boolean, object, or any other type of value. The purpose of the objectHash function is to generate a hash value for the key, which can be used for

    Returns number

    a number, which is the hash value of the key.

  • The function calculates a hash value for a given string using the djb2 algorithm.

    Parameters

    • key: string

      The key parameter in the stringHash function is a string value that represents the input for which we want to calculate the hash value.

    Returns number

    a number, which is the hash value of the input string.

  • The get function retrieves the value associated with a given key from a hash table.

    Parameters

    • key: K

      The key parameter represents the key of the element that we want to retrieve from the data structure.

    Returns undefined | V

    The method is returning the value associated with the given key if it exists in the hash table. If the key is not found, it returns undefined.

  • The remove function removes a key-value pair from a hash table.

    Parameters

    • key: K

      The key parameter represents the key of the key-value pair that needs to be removed from the hash table.

    Returns void

    Nothing is being returned. The remove method has a return type of void, which means it does not return any value.

  • The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.

    Parameters

    • key: K

      The key parameter represents the key of the key-value pair that you want to insert into the hash table. It is of type K, which is a generic type representing the key's data type.

    • val: V

      The parameter val represents the value that you want to associate with the given key in the hash table.

    Returns void

    Nothing is being returned. The return type of the put method is void, which means it does not return any value.

Generated using TypeDoc