Hash Table - 401-advanced-javascript-v/seattle-javascript-401d29 GitHub Wiki

Hashtables are a data structure that utilize key value pairs. This means every Node or Bucket has both a key, and a value.

A hash is the ability to encode the key that will eventually map to a specific location in the data structure that we can look at directly to retrieve the value.

Hash maps do this to store values:

  • accept a key
  1. calculate the hash of the key
  2. use modulus to convert the hash into an array index
  3. store the key with the value by appending both to the end of a linked list
  4. Hash maps do this to read value:
  • accept a key
  1. calculate the hash of the key
  2. use modulus to convert the hash into an array index
  3. use the array index to access the short LinkedList representing a bucket
  4. search through the bucket looking for a node with a key/value pair that matches the key you were given