kind = (np+i)->TAG;
and one of the union fields would be:
value = (np+i)->data.number;
provided i < M and TAG == FLOAT
An example:
Let use now review a typical C115 hashing problem.
Given an array of M boxes. Into each we are going to store
one animal from an input queue:
"dog", "cat", "hen", etc.
Assume we want to store them in these boxes according to
some hashing scheme.
First we must compute a hashnumber based on some
transformation of the animal type.
H = Transform ("dog");
Then we must compute the hash index modulo M to
determine into which box to store the animal.
i = H % M;
If box iis empty, pop the animal in.
If the box is occupied, compute the address of the next
available box with:
i = (i +1) % M;
until you find an empty box. Note our method guarantees
that you will eventually look in all M boxes before
determining that there is no room at the Inn.
|