hash function

A function that turns data of any size into a fixed-size value, called its hash, used to find items quickly in a table or to detect any change in the data.

In more detail

A hash function must be deterministic (same input, same output), produce output of a fixed width however large the input, and scatter similar inputs across different values. Hash tables reduce the hash to a slot number to jump straight to a key. Cryptographic hashes such as SHA-256 add a further promise: it is infeasible to find two inputs with the same hash, so they serve as tamper-evident fingerprints.

Examples

hash(42) == 42  # small integers hash to themselves in CPython
hash('apple')  # differs on every interpreter launch

Related terms

Taught in

References