From 8dd03a3413b60c0228cb24d5aeb521ff1ae8e964 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Mon, 1 Jan 2024 14:36:49 -0800 Subject: [PATCH] Slightly improve hash function --- src/toolsrc/plforth.pla | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/toolsrc/plforth.pla b/src/toolsrc/plforth.pla index 4248e92..67d603e 100644 --- a/src/toolsrc/plforth.pla +++ b/src/toolsrc/plforth.pla @@ -683,7 +683,7 @@ def hashname(chars, len)#1 hash = 0 while len - hash = hash + ^chars + hash = (hash << 1) ^ ^chars chars++ len-- loop @@ -713,19 +713,18 @@ def buildhashtbl#0 end def find(matchchars, matchlen)#1 word dentry - byte i, hash + byte i - hash = hashname(matchchars, matchlen) + dentry = hashtbl[hashname(matchchars, matchlen)] matchchars-- - dentry = hashtbl[hash] while dentry if ^dentry == matchlen - for i = 1 to ^dentry + for i = matchlen downto 1 if ^(matchchars + i) <> ^(dentry + i) break fin next - if i > ^dentry + if i == 0 return dentry fin fin @@ -813,7 +812,6 @@ end // Execute code in CFA // def execword(dentry)#0 - when conio:keypressed() is $83 // CTRL-C getc // Clear KB