Entry[] bucket = new Entry[ N ]; int NItems = 0;
bucket[ NItems ] = new Entry ( ... , ... ); NItems ++;
get( Key k ) { for ( int i = 0; i < NItems; i++ ) { if ( bucket[i] contains the key ) return the value in bucket[i]; } return null; // not found }
Hash function: h(k) = k%10
Storage of the Map content in the hash table:
Hash function: h(k) = (k%10 + k/10)%10
Map content:
Lookup procedure:
h(56) = (5 + 6)%10 = 1
Example: (using a hypothethical hash function)
(When 2 or entries are hashed into the same bucket, then an additional search operation within the bucket must be performed)
The reason why these conditions are necessary for efficiency in hashing is explained next...
These are called collisions
Example:
Hash function: h(k) = k/100
(All entries are stored in the bucket 0)