MAINDEBUG User's Guide, Appendix B

previous   next   top   contents   index   framed top   this page unframed


B. The MODULE SAMPLE

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 bucketSizeEND;


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 & eolEND END;

END "sample"

previous   next   top   contents   index   framed top   this page unframed

MAINDEBUG User's Guide, Appendix B