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


Linear probing hashing: insertion (Pascal version available)


void insert( key, r ) typekey key; dataarray r; { extern int n; int i, last; i = hashfunction( key ) ; last = (i+m-1) % m; while ( i!=last && !empty(r[i]) && !deleted(r[i]) && r[i].k!=key ) i = (i+1) % m; if (empty(r[i]) || deleted(r[i])) { /*** insert here ***/ r[i].k = key; n++; } else Error /*** table full, or key already in table ***/; }

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



© Addison-Wesley Publishing Co. Inc.