Quadratic hashing: insertion


procedure insert( key : typekey; var r : dataarray ); var i, inc : integer; begin i := hashfunction( key ); inc := 0; while (inc<m) and (not empty(r[i])) and (not deleted(r[i])) and (r[i].k<>key) do begin i := (i+inc+1) mod m; inc := inc + 2; end; 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;

Pascal source (336.ins.p)



© Addison-Wesley Publishing Co. Inc.