I have seen Wikipedia pages on it, but I still can not understand it. Can anyone help my brains to understand the concepts of hashing, hashtable / hampp, and hash functions? Some examples will really help.
There will be a lot of technical information in the Wikipedia article, but something like this below has a simple view.
Imagine that there is a magical function that can give a number to an object. Given the same object, it always returns the same number.
Immediately if you have two objects the same, there is a quick way to check: Ask this function for their numbers and compare them. If they are different, then they are not the same.
But what if they have the same number? Is there only one number of two separate items?
Yes, it is possible in most scenarios. Suppose that the function can give between 1. 1.10 only, for example, and 100 different objects. Then, of course, some different objects should have the same number. This is called a "collision". A "collision" does not make our quick equality test as useful, as much as possible, we want to reduce its occurrence. A good magical function is that it will try to reduce the number of "collision".
So what else can you do with this number? Okay, you can use it in an array index. Looking at an object, you can keep it from this magical function based on number. This array is essentially a hashtable; This magical function is a hash function.
Comments
Post a Comment