How it works...
The comparison of strings is slow because we are required to compare all the characters of the string one-by-one, if strings have equal length. Instead of doing that, we replace the comparison of strings with the comparison of integers. This is done via the hash function - the function that makes some short-fixed length representation of the string.
Let's talk about the hash values on apples. Imagine that you have two apples with labels, as shown in the following diagram, and you wish to check that the apples are of the same cultivar. The simplest way to compare those apples is by comparing them by labels. Otherwise, you'll lose a lot of time comparing the apples based on the color, size, form, and other parameters. Hash is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access