1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-18 07:24:16 +00:00

Slightly improve hash function

This commit is contained in:
David Schmenk 2024-01-01 14:36:49 -08:00
parent 3b8bad0abd
commit 8dd03a3413

View File

@ -683,7 +683,7 @@ def hashname(chars, len)#1
hash = 0 hash = 0
while len while len
hash = hash + ^chars hash = (hash << 1) ^ ^chars
chars++ chars++
len-- len--
loop loop
@ -713,19 +713,18 @@ def buildhashtbl#0
end end
def find(matchchars, matchlen)#1 def find(matchchars, matchlen)#1
word dentry word dentry
byte i, hash byte i
hash = hashname(matchchars, matchlen) dentry = hashtbl[hashname(matchchars, matchlen)]
matchchars-- matchchars--
dentry = hashtbl[hash]
while dentry while dentry
if ^dentry == matchlen if ^dentry == matchlen
for i = 1 to ^dentry for i = matchlen downto 1
if ^(matchchars + i) <> ^(dentry + i) if ^(matchchars + i) <> ^(dentry + i)
break break
fin fin
next next
if i > ^dentry if i == 0
return dentry return dentry
fin fin
fin fin
@ -813,7 +812,6 @@ end
// Execute code in CFA // Execute code in CFA
// //
def execword(dentry)#0 def execword(dentry)#0
when conio:keypressed() when conio:keypressed()
is $83 // CTRL-C is $83 // CTRL-C
getc // Clear KB getc // Clear KB