previous | start | next

Example

        Keys will be 'Product codes'
        Values will be 'quantity on hand'

        Pairs to be inserted into a hash:
        (14913, 20)
        (15930, 10)
        (16918, 50)
        (17020, 19)
     

We will put these into a hash table using open addressing and storing the values in an array.

The success of hashing depends on how full the array is. As a rule of thumb, one should try to keep the array no more than 75% full.

We will use size 7 for this example.

        The hash function should map each key to the array index range: 
        0 - 6.

        An easy way to do this is to use the remainder on division by 7:

        hash(key) = key % 7;
     


previous | start | next