I want to hash the following key "LOWELL" using a simple hash function that used 3 steps :
Step 1: transform the key into a number.
LOWELL = | L | O | W | E | L | L | | | | | | |
ASCII code: 76 79 87 69 76 76 32 32 32 32 32 32
my question here why it added more 6 empty positions with fixed ASCII code 32
Step 2: fold and add (chop off pieces of the number and add them together)
7679|8769|7676|3232|3232|3232|
7679+8769+7676+3232+3232+3232 = 33,820
Step 3: take the mod by a prime number
33,820 mod 19937 = 13,883
Another question here for why dividing by prime numbers i found this answer : Dividing by a number is good when there are sequences of consecutive numbers. If there are many dierent sequences of consecutive numbers, dividing by a number that has many small factors may result in lots of collisions. A prime number is a better choice. but i didn't get it
Step 4: divide by the size of the address space (preferably a prime number). 13,883 mod 101 = 46
finally why it divided the address space ?!
You can find detailed steps here (Slide 350) Many Thanks in advance for helping