previous next top contents index framed top this page unframed
BEGIN "sample"
INTEGER bucketSize; # size of hash bucket
INTEGER PROCEDURE hash (STRING s);
BEGIN
INTEGER h,i,j;
h := length(s); i := h MIN 4; j := 1;
WHILE i .- 1 GEQ 0 DOB j .+ 2; h .+ cRead(s) * j END;
RETURN(h MOD bucketSize) END;
INITIAL PROCEDURE;
BEGIN
STRING s;
ttyWrite("Size of hash bucket: "); bucketSize := cvi(ttyRead);
DOB ttyWrite("Next key to be hashed (eol to stop): ");
IF NOT s := ttyRead THEN DONE;
ttyWrite(hash(s),eol & eol) END END;
END "sample"