Class HashTable<K, V>

Type Parameters

  • K

  • V

Hierarchy

  • HashTable

Constructors

Properties

Accessors

Methods

Constructors

  • The constructor initializes the capacity, size, and buckets of an object.

    Type Parameters

    • K

    • V

    Parameters

    • Optional capacity: number = 1000

      The capacity parameter represents the maximum number of elements that the data structure can hold. It is an optional parameter with a default value of 1000.

    Returns HashTable<K, V>

Properties

_buckets: (null | HashNode<K, V>)[]
_capacity: number
_size: number

Accessors

Methods

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

    Parameters

    • key: K

      The parameter "key" 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 hash function takes a key, converts it to a string, calculates the sum of the ASCII values of its characters, and returns the remainder when divided by the capacity of the data structure.

    Parameters

    • key: K

      The key parameter represents the key that needs to be hashed. It is of type K, which means it can be any data type that can be converted to a string.

    Returns number

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

  • The put function adds a key-value pair to a hash table, handling collisions by chaining.

    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 can be any data type that can be used as a key, such as a string, number, or object.

    • val: V

      The val parameter represents the value associated with the key in the hash table.

    Returns void

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

  • 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.

Generated using TypeDoc