[Previous Algorithm]
[Next Algorithm]

Linear probing hashing: insertion

procedure insert( key : typekey; var r : dataarray ); var i, last : integer; begin i := hashfunction( key ) ; last := (i+m-1) mod m; while (i<>last) and (not empty(r[i])) and (not deleted(r[i])) and (r[i].k<>key) do i := (i+1) 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 (334.ins.c) Pascal source (334.ins.p)

© Addison-Wesley Publishing Co. Inc.