What's the purpose in hashing information?

前端 未结 5 428
时光说笑
时光说笑 2021-01-31 10:44

After being taught how to create a hash table in class, I don\'t understand when hashing data would be useful. It seems to me that all hashing does is storing information in se

5条回答
  •  再見小時候
    2021-01-31 11:42

    alt text

    One of the major uses of the hash tables you created in class is when you need fast O(1) lookup times. You'll have have two components, keys and the values.

    The hash function transforms the key into a hash. That hash is a number, and specifically, it is the index of the data in the array.

    So, when you need to look up Agscala's reputation up in a hash table and you have used your username as the key, it takes almost no time to locate and find the relevant value. It simply re-hashes your username and viola, there is the index of the data you were looking for. You didn't have to iterate over the entire array looking for that specific value.

    For some reference the Wikipedia page on Hash tables is pretty good.

提交回复
热议问题