HashTable

DataStructure. HashTable

In order to store key-value pairs in memory from the hash table a way to take the key and turn it into an address is needed, this operation is known as hashing. Basically it takes a key and serializes it into a unique number for that key.

 hashKey("abc") => 96354
 hashKey("xyz") => 119193

The hashing algorithm will limit the size of key, to prevent that the key is not to big. Which means that there are a limit number of addresses for an unlimited number of values.

Constructor

new HashTable()

Start with an empty array and store the length of the "hashtable".
Source:

Methods

(static) hashKey(key) → {number}

Accepts a string and outputs a (mostly) unique address that will be used in other functions of this class.
Parameters:
Name Type Description
key String Key to get hashed
Source:
Throws:
  • Key can not be undefined!
    Type
    ReferenceError
  • The key needs to be type of string!
    Type
    TypeError
Returns:
Type
number

get(key) → {*}

Retrieve the value of a given key. Hash the key and get value from "memory".
Parameters:
Name Type Description
key String Key to retrieve value
Source:
Throws:
  • Key can not be undefined!
    Type
    ReferenceError
  • The key needs to be type of string!
    Type
    TypeError
Returns:
Type
*

remove(key)

Remove a pair of data.
Parameters:
Name Type Description
key String Key of pair that should be removed
Source:
Throws:
  • Key can not be undefined!
    Type
    ReferenceError
  • The key needs to be type of string!
    Type
    TypeError

set(key, value)

Set value for key. Hash the key and set value in "memory".
Parameters:
Name Type Description
key String Key
value * Value for given key
Source:
Throws:
  • Key can not be undefined!
    Type
    ReferenceError
  • The key needs to be type of string!
    Type
    TypeError