Record Keys: 27, 18, 29, 28, 39, 13, 16, 38, 53
Table Size = 11; Hash Function = hash(key) = key mod 11
Incrementing Function = i(key) = Quotient (Key / 11) mod 11 (computed on resident key)
(nof = number of offsets)
|
|
|
||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|
1. 27 mod 11 = 5 | |
|
|
|
|
4. 28 mod 11 = 6; 5. h(39) = 6; i(28) = 2; goto 8 then 10 |
|
|
|
|
2. 18 mod 11 = 7; 3. 29 mod 11 = 7; i(18) = 1 so goto 8 |
|
|
|
||
|
|
|||
|
|
|
Note that the number of offsets indicates what to multiply i(key) by to find the next record in the chain. To find 28, (18/11) mod 11 = 1 mod 11; offset is 1; number of offsets is one so the record is at address 8. To find 39, (28/11) mod 11 = 2 mod 11; offset = 2, loc8 is occupied so try 10. It works so the number of offsets stored in the predecessors pseudolink is 2.
|
|
|
||
|
|
|||
|
|
|||
|
|
|
6. 13 mod 11 = 2 | |
|
|
|||
|
|
|||
|
|
|
|
7. 16 mod 11 = 5; i(27) = 2; goto 7 then 9; 8. 38 mod 11 = 5; but 27 |
|
|
|
|
already has a successor so go there (1 seek); it has no successor; |
|
|
|
|
use i(16) = 1 to go to loc10; it's occupied so wrap around to loc0; |
|
|
|
insert 38 at loc0; update 16's pseudolink to 2 | |
|
|
|
||
|
|
|
|
|
|
||
|
|
|
||
|
|
|||
|
|
|
||
|
|
|||
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
9. h(53) = 9; since h(16) = 5; 16 is not at its home address, we need to |
|
|
|
do some moving. Move 16 and ALL its successors. |
16 has a successor so we must find it. Remove and save 16 and 38; update pseudolink for 27. Now put 53 where it belongs so there will only be 1 probe for it. Then re-insert 16 and 38.
|
|
|
SAVE 16 and 38 | |
|
|
|
|
|
|
|
|
||
|
|
|
||
|
|
|||
|
|
|||
|
|
|
|
9A. h(16) = 5; i(27) = 2; goto 7,9,0 and insert; 3 offsets |
|
|
|
|
9B. h(38) = 5; follow links to loc0; i(16) = 1; goto 1 and insert |
|
|
|
|
|
|
|
|
||
|
|
|
||
|
|
|
Variation: we can cut down the number of searches considerably by creating multiple chains.
We need a way to decide which chain to follow based on the key we are looking for. One simple method is to use one chain for even keys and another for odd keys. We need to add another pseudolink field but the extra space may not be as important as the reduced search time. Now what we do when we get to the start of a chain is to follow pseudolink0 if the probe key is even ((probekey mod 2)=0) and psudolink1 if the probe key is odd ((probekey mod 2) = 1). When keys need to be moved only one pseudolink chain is affected.