Define what is a Hash Function?

Technology CommunityCategory: Hash TablesDefine what is a Hash Function?
VietMX Staff asked 3 years ago

hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes. The values are used to index a fixed-size table called a hash table. Use of a hash function to index a hash table is called hashing or scatter storage addressing.

Mathematically speaking, a hash function is usually defined as a mapping from the universe of elements you want to store in the hash table to the range {0, 1, 2, .., numBuckets - 1}.

Some properties of Hash Functions are:

  • Very fast to compute (nearly constant)
  • One way; can not be reversed
  • Output does not reveal information on input
  • Hard to find collisions (different data with same hash)
  • Implementation is based on parity-preserving bit operations (XOR and ADD), multiply, or divide.