In computer science, a data structure is a way to store and organize your data so you can access or operate on this information effectively. Hash Table is a type of data structure. In other languages, they can be referred to as dictionary, hash map or map. Hash tables are useful to do quick looks ups on a set of data. They are a quick way to implement mappings of key value pairs.

Sound familiar? JavaScript Objects! Under the hood, objects are constructed by hash tables essentially.

From a high overview, hash table consists of:

  • Data (key values) to be stored and then accessed when given the key
  • Hash Function which is a function that maps your data of arbitrary size to a calculated index
  • Storage buckets is the location that stores values to be accessed

This simple example below stores people’s phone numbers for quick lookup.

Apparently, constructing a hash function is not something we need to do. They are created by really smart folks with PhD’s who wrote a hash function that magically breaks down our key input into an index, based on provided storage size. The internet is a place we can search for a good hash function to leverage. In general, a good hash function:

  • Efficiently computable and the hash value is fully determined by data being hashed
  • The data being hashed is consistent each time it is hashed
  • Uniformly (ideally) distributes the data across the storage buckets
  • Avoids collision (explained below)

#bootcamp #data-structures #hash-table #javascript #coding

JavaScript Newbies on Hash Table
1.50 GEEK