From 83b11b401f1a5c41e5f9c365b7bef39c902acd5b Mon Sep 17 00:00:00 2001 From: John Benediktsson <mrjbq7@gmail.com> Date: Sun, 2 Oct 2011 18:42:55 -0700 Subject: [PATCH] words: since word names can be tuples (i'm looking at you smalltalk), use a combining hash function inspired by boost::hash_combine. --- core/words/words.factor | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/words/words.factor b/core/words/words.factor index c791829ede..80bb7fc7f7 100644 --- a/core/words/words.factor +++ b/core/words/words.factor @@ -168,8 +168,21 @@ M: word reset-word } reset-props ] tri ; +<PRIVATE + +! borrowed from boost::hash_combine, but the +! magic number is 2^29/phi instead of 2^32/phi +! due to max fixnum value on 32-bit machines +: hash-combine ( hash seed -- newhash ) + [ HEX: 13c6ef37 + ] dip [ 6 shift ] [ -2 shift ] bi + + ; + +: 2hash ( obj1 obj2 -- hash ) + [ hashcode ] bi@ 0 hash-combine hash-combine ; + +PRIVATE> + : <word> ( name vocab -- word ) - 2dup swap ":" glue hashcode >fixnum (word) dup new-word ; + 2dup 2hash >fixnum (word) dup new-word ; : <uninterned-word> ( name -- word ) f \ <uninterned-word> counter >fixnum (word)