void delete(HashTable ht, Key k)
{
int N = ht->nslots;
Item *a = ht->items;
int i, j, h = hash(k,N);
for (j = 0; j < N; j++) {
i = (h+j)%N;
if (a[i] == NoItem) return;
if (eq(k,key(a[i]))) break;
}
a[i] = NoItem;
ht->nitems--;
j = i+1;
while (a[j] != NoItem) {
Item it = a[j];
a[j] = NoItem;
ht->nitems--;
insert(ht, it);
j = (j+1)%N;
}
}
|