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


Double hashing: insertion (Pascal version available)


void insert( key, r ) typekey key; dataarray r; { extern int n; int i, inc, last; i = hashfunction( key ) ; inc = increment( key ); last = (i+(m-1)*inc) % m; while ( i!=last && !empty(r[i]) && !deleted(r[i]) && r[i].k!=key ) i = (i+inc) % 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 (335.ins.c) Pascal source (335.ins.p)



© Addison-Wesley Publishing Co. Inc.