From baceee8c50189500e4a827d4bf4c1ee71c3ee8e5 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 2 Oct 2011 20:28:51 -0700 Subject: [PATCH] hashtables: moving hash-combine to hashtables. --- core/hashtables/hashtables.factor | 7 +++++++ core/words/words.factor | 15 +-------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/core/hashtables/hashtables.factor b/core/hashtables/hashtables.factor index 98218ecbe8..7883b2dfb9 100644 --- a/core/hashtables/hashtables.factor +++ b/core/hashtables/hashtables.factor @@ -167,4 +167,11 @@ M: hashtable assoc-like : ?set-at ( value key assoc/f -- assoc ) [ [ set-at ] keep ] [ associate ] if* ; +! 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 ( obj oldhash -- newhash ) + [ hashcode HEX: 13c6ef37 + ] dip + [ 6 shift ] [ -2 shift ] bi + + ; + INSTANCE: hashtable assoc diff --git a/core/words/words.factor b/core/words/words.factor index 80bb7fc7f7..56503d3692 100644 --- a/core/words/words.factor +++ b/core/words/words.factor @@ -168,21 +168,8 @@ M: word reset-word } reset-props ] tri ; - - : ( name vocab -- word ) - 2dup 2hash >fixnum (word) dup new-word ; + 2dup 0 hash-combine hash-combine >fixnum (word) dup new-word ; : ( name -- word ) f \ counter >fixnum (word)