Search code examples
chashhashtablekey-value

Difference between hashed value, and key-value?


I'm trying to understand something that feels pretty basic but I cannot wrap my head around

we have a key value, character, string, whatever , and we want to send it to our hashing function , which gives some index.

My question is, is the result of the hashing function the value in a key-value pair ?

Or is the value separate from the result of the hashing function?


Solution

  • A 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 usually used to index a fixed-size table called a hash table.

    https://en.wikipedia.org/wiki/Hash_function

    So, you provide an input, which is presumably the key and get the result of the hashing function, which is the hash.

    • I used the word presumably above, because it is up to you what your algorithm considers to be a key and what it considers to be a value, but, in general, the result of a hashing function is a value that can be used to index a hash table.

    Here's a picture taken from wikipedia

    enter image description here