Math176
Non-lazy deletion in a linear probing hash table

Below is the algorithm which I described in class for non-lazyt deletion in a hash table which uses linear probing.  This algorithm is not in our text book, and seems to not be well-known, since most textbooks do not include it.  However, on the day after we discussed the algorithm in lecture, I received a free copy of a book which does describe this method of non-lazy deletion, so it is not completely unknown.  (The book is: Data Structures and Algorithms with Object-Oriented Design Patterns in Java, by Bruno Preiss, pp 237-239.)

Here is the algorithm for non-lazy deletion.  (It is slightly shortened from what I presented in class.)

Variables:  A - hash table.  
A[i] - i-th entry of the hash table. (0-based)
S - table size
--
Algorithm:      To remove the object (key) in A[i]:

to :=  i
from  := i
loop
    from  :=   (from+1) mod S
    if  A[from] is empty, break from loop..
    h  :=   hash code of A[from] mod S
    if   to is "circularly between"   h  and  from       
        // slide down:
        A[to] := A[from]
        to  :=  from
    fi
endloop
Make A[to] empty.

--
Algorithm: To check if b is "circularly between" a and c (mod S) ,
   or equivalently, b is in the "circular" half-open interval [a,c):

if    a <= c,
    return true iff  a <= b  and   b < c.
else
    return true iff  a <= b  or   b < c