Hash

A hash is used to provide direct access to data based on a calculated key.

Hash Tables

A hash table stores the hash function inputs and outputs in a data structure such as a dictionary as key value pairs:

  • key - generated using the hash function

  • value - is the input to the hash function

Python Example

# Create hash fixed size integers using input objects.
key1 = hash("string to hash")
key2 = hash(235.367)

# Instantiate a dictionary.
dictionary = dict()

# Use the hash values, such as securing data in a dictionary.
dictionary[key1] = "Value for key1."
dictionary[key2] = "Value for key2."

# Use the hash values to retrieve dictionary values.
value1 = dictionary[key1]
value2 = dictionary[key2]
print(str(value1), str(value2))