h is the hash function and g is the pre-designed offset
calculator, each cell in the bucket has one of the following
three states: Occupied, Free, Removed.
void insert(Key k, Data & object)
{
int index = h(k);
int i = index;
for(int j = 1; bucket[i] is Occupied; j++)
i = (i + g(j, k)) mod N;
insert object to bucket[i];
change bucket[i].status to Occupied;
}
Data & lookup(Key k)
{
int index = h(k);
int i = index;
for(int j = 1; bucket[i] is not Free; j++) {
if (bucket[i] is Occupied && bucket[i].key == k)
return bucket[i].object;
i = (i + g(j, k)) mod N;
}
throw exception of not found;
}
Data & remove(Key k)
{
int index = h(k);
int i = index;
for(int j = 1; bucket[i] is not Free; j++) {
if (bucket[i] is Occupied && bucket[i].key == k) {
change bucket[i].state to Removed;
return bucket[i].object;
}
i = (i + g(j, k)) mod N;
}
throw exception of not found;
}