--- gforth/hash.fs 1998/12/19 13:43:17 1.23 +++ gforth/hash.fs 2001/09/04 09:17:02 1.28 @@ -1,6 +1,6 @@ \ Hashed dictionaries 15jul94py -\ Copyright (C) 1995,1998 Free Software Foundation, Inc. +\ Copyright (C) 1995,1998,2000 Free Software Foundation, Inc. \ This file is part of Gforth. @@ -16,7 +16,11 @@ \ You should have received a copy of the GNU General Public License \ along with this program; if not, write to the Free Software -\ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + +[IFUNDEF] erase +: erase ( addr len -- ) 0 fill ; +[THEN] [IFUNDEF] allocate : reserve-mem here swap allot ; @@ -32,6 +36,12 @@ \ compute hash key 15jul94py +has? ec [IF] [IFUNDEF] hash +: hash ( addr len -- key ) + over c@ swap 1- IF swap char+ c@ + ELSE nip THEN + [ Hashlen 1- ] literal and ; +[THEN] [THEN] + [IFUNDEF] hash : hash ( addr len -- key ) hashbits (hashkey1) ; @@ -42,12 +52,12 @@ Variable revealed \ Memory handling 10oct94py -Variable HashPointer +AVariable HashPointer Variable HashIndex -0 Value HashTable +0 AValue HashTable \ forward declarations -0 Value hashsearch-map +0 AValue hashsearch-map Defer hash-alloc ( addr -- addr ) \ DelFix and NewFix are from bigFORTH 15jul94py @@ -65,7 +75,7 @@ Defer hash-alloc ( addr -- addr ) cells HashTable + ; : hash-find ( addr len wordlist -- nfa / false ) - >r 2dup r> bucket @ (hashfind) ; + >r 2dup r> bucket @ (hashlfind) ; \ hash vocabularies 16jul94py @@ -97,7 +107,7 @@ Defer hash-alloc ( addr -- addr ) voclink BEGIN @ dup WHILE dup 0 wordlist-link - - dup wordlist-map @ hashsearch-map = + dup wordlist-map @ reveal-method @ ['] hash-reveal = IF inithash ELSE drop THEN REPEAT drop ; @@ -134,9 +144,9 @@ Defer hash-alloc ( addr -- addr ) IF inithash ELSE rehashall THEN ; -\ >rom ?! -align here ' hash-find A, ' hash-reveal A, ' (rehash) A, ' (rehash) A, -to hashsearch-map +const Create (hashsearch-map) +' hash-find A, ' hash-reveal A, ' (rehash) A, ' (rehash) A, +(hashsearch-map) to hashsearch-map \ hash allocate and vocabulary initialization 10oct94py