Search⌘ K

Associative Containers: The Hash Function

Explore the requirements and functionality of hash functions in unordered associative containers. Understand how keys and values must behave, the impact of collisions, bucket capacity, and the process of rehashing. This lesson helps you optimize access times by managing load factors and choosing appropriate bucket sizes for efficient data handling in Modern C++.

We'll cover the following...

Which requirements must the key and the value of an unordered associative container fulfill?

The key must be

  • comparable with the equality function,
  • available as a hash value,
  • copyable and moveable.

The value must be

  • by default constructible,
  • copyable and moveable.

A hash function is good if two factors are present: one, if the mapping from the keys to the values produces few collisions; two, if the hash values are uniformly distributed among the buckets. Since the execution time of the hash function is constant, the access time of the elements is also constant. ...