Abstract
- Certainty - always gives the same output given the same input
- Efficient - takes as little computation as possible
- Hash Value of different data structures
Uses modular arithmetic to calculate bucket index
- We can use either Prime Number (质数) or Composite number if we are sure the key is evenly distributed.
- Else if there is some kind of pattern like, the key is a multiple of 3, prime number can reduce Hash Collision
- Thus, we usually use Prime Number (质数) to take the modules, since we can’t predict the distribute of the keys
Immutable Key
- Because if the key changes, then its hash value will change, and we will lose the mapping between the key & the bucket index
- Objects created on Heap Segment can be key, because we use its Memory Address to generate the hash