home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Lookup an entry in the Hash Table. If found, return TRUE and set the VAR
- ; parameter FoundAt with the index of the entry at which the match was found.
- ; If not found, return FALSE, and add unmatched prefix/suffix to end of table.
- ;
- ;
- ; Register usage:
- ; AX - varies BL - holds target suffix character
- ; BH - If search fails, determines how to
- ; add the new entry
- ; CX - not used DX - holds size of 1 table entry (5)
- ; DI - varies SI - holds offset of 1st table entry
- ; ES - seg addr of hash table DS - program's data segment
- ;
- ;
- mov byte bl,[bp+<TargetSuffix] ;Target Suffix character
- mov word ax,[bp+<TargetPrefix] ;Index into table
- mov dx,5 ;5 byte table entries
- mul dx ;AX now an offset into table
- les di,[>HashTable] ;Hash table address
- mov si,di ;save offset in SI
- add di,ax ;es:di points to table entry
- ;
- mov bh,0 ;Chain empty flag (0=empty)
- es: cmp word [di],-1 ;Anything on the chain?
- jz NotFound ;Nope, search fails
- mov bh,1 ;Chain empty flag (1=not empty)
- ;
- es: mov word ax,[di] ;Get index of 1st entry in chain
- Loop: mov word [bp+<TargetPrefix],ax ;Save index for later
- mov dx,5
- mul dx ;convert index to offset
- mov di,si ;es:di points to start of table
- add di,ax ;es:di points to table entry
- ;
- es: cmp byte bl,[di+4] ;match on suffix?
- jz Found ;Yup, search succeeds
- ;
- es: cmp word [di+2],-1 ;any more entries in chain?
- jz NotFound ;nope, search fails
- ;
- es: mov word ax,[di+2] ;get index of next chain entry
- jmp short Loop ; and keep searching
- ;
- Found: mov byte [bp-1],1 ;return TRUE
- les di,[bp+<FoundAt] ;get address of Var parameter
- mov word ax,[bp+<TargetPrefix] ;get index of entry where found
- es: mov [di],ax ;and store it
- jmp short Done
- ;
- NotFound: mov word ax,[>FreeEntry] ;Index of next free table entry
- cmp word ax,>Tablesize ;Any room in table
- jb NotFull ;Yes
- mov byte [>TableFull],1 ;Set flag
- jmp short SkipAdd ;Exit without adding entry
- NotFull: cmp bh,0 ;Adding new entry
- jz First ;New entry is 1st one in the chain
- es: mov [di+2],ax ;Append new entry to chain
- jmp short InitNew
- First: es: mov [di],ax ;New entry is 1st one in chain
- InitNew: mov dx,5
- mul dx ;ax = offset of new entry in table
- mov di,si
- add di,ax ;es:di points at new entry
- mov ax,-1
- cld
- stosw ;Init FIRST ptr to -1
- stosw ;Init NEXT ptr to -1
- mov al,bl ;al=suffix for this new entry
- stosb ;Init SUFFIX field
- inc word [>FreeEntry] ;point FreeEntry to next empty slot
- SkipAdd: mov byte [bp-1],0 ;return FALSE
- les di,[bp+<FoundAt] ;get address of Var parameter
- es: mov word [di],-1 ;and store a -1 in it
- ;
- Done:
- ;
-