1 2 3 4 5 6 7 8 9

How do you compute H? What are the properties of a good
Transform? Ideally you would like one that computes H so
that its values are uniformly distributed across the full
range of positive integers that can be stored in a 4-byte
unsigned integer.


[Actually, we would really like the right-most k bits to be
random, where k=4 if M is 16, etc., but this is even more
difficult].
One scheme is given in K&R page 144. This looks kind
of expensive (an addition and multiplication for each
character in the name), but is it really?
Another scheme is to try and use the bit-wise XOR
operator (^) that we featured in earlier discussions about
Gray Codes and BitStrings. Too elaborate?
Or we could try some el-cheapo scheme like adding
together the 8-bit integers that correspond to each ASCII
character in the animal-type name. Poor, but let us start
with this.


Thus Transform ("dog") is 100+111+103 = 314
while Transform ("cat") is 99+97+116 = 312 and
Transform ("hen") is 315.
If M = 10 (ten boxes), then the dog would go in box 4, the cat
in box 2 and the hen in box 5, and everyone would be happy.


Retrieving is the reverse process. If we want the "hen",
look in box
Transform ("hen") % M;
That is, box 5 and take the hen.

February 15 1998

Page 6

TAM C201 notes