[Home]
[Chapter]
[Contents]
[Previous Algorithm]
[Next Algorithm]


Double hashing: insertion


procedure insert( key : typekey; var r : dataarray ); var i, inc, last : integer; begin i := hashfunction( key ) ; inc := increment( key ); last := (i+(m-1)*inc) mod m; while (i<>last) and (not empty(r[i])) and (not deleted(r[i])) and (r[i].k<>key) do i := (i+inc) mod m; if empty(r[i]) or deleted(r[i]) then begin {*** insert here ***} r[i].k := key; n := n+1 end else Error {*** table full, or key already in table ***}; end;

C source (335.ins.c) Pascal source (335.ins.p)



© Addison-Wesley Publishing Co. Inc.