home *** CD-ROM | disk | FTP | other *** search
- 100 'Routine to do a table look-up using chained hashing
- 110 '
- 120 'TB = table of names to be entered/looked up.
- 130 'CH = table of chain pointers
- 140 'IX = index to entry of TB where the name was entered or found
- 150 'OV = pointer to the last entry used in the overflow table
- 160 'FD = flag reporting result of search: 0=not found, 1=found
- 170 'K$ = holds the current KEY being searched for
- 180 'MT = maximum total table size (primary and secondary)
- 190 '
- 200 FD = 0 'initialize result of search to "not found"
- 210 GOSUB 1000 'go hash the key in K$; the result is returned in IX
- 220 '
- 230 'examine first entry with correct hash value
- 240 '
- 250 IF TB(IX) = "" THEN TB(IX) = K$: RETURN 'it's empty - enter KEY and return
- 260 IF TB(IX) = K$ THEN FD = 1: RETURN 'found it - say so and return
- 270 '
- 280 'the first entry had some name other than KEY in it - step down the chain
- 290 '
- 300 IF CH(IX) <> 0 THEN IX = CH(IX): GOTO 260 'step down the chain
- 310 '
- 320 'We found the end of the chain, so enter the key and return with FD = 0
- 330 '
- 340 OV = OV + 1 'advance to next empty overflow entry
- 350 IF OV > MT THEN GOTO 2000 'goto the error routine and never return
- 360 TB(OV) = K$ 'enter KEY
- 370 CH(IX) = OV 'and add the new entry to the end of the chain
- 380 IX = OV 'set IX to tell the caller where we entered it
- 390 '
- 400 RETURN
-
-
-