Hash Table

Hash Set

A hash table (or hash map) is an implementation of a map ADT.

A hash set is an implementation of a set ADT.

You can add mappings from keys to values, and later retrieve values associated with keys.

You can add values, and later check for containment.
phoneBook.put("Alice", "+123456789")
if (people.contains("Alice"))
A hash table stores key-value pairs. The hashing is based on the key.
A hash set stores values. The value is also the key, i.e. the hashing is based on the value.

Note: The literature on these types of data structures (including many of the articles here on Programming.Guide) mostly focus on hash sets rather than hash tables. This is because the actual values are never really relevant to the discussion, and it's easy to generalize an implementation that works only with keys, into one that works with key-value pairs.


Be the first to comment!