hashtables: moving hash-combine to hashtables.

db4
John Benediktsson 2011-10-02 20:28:51 -07:00
parent 8504b17aad
commit baceee8c50
2 changed files with 8 additions and 14 deletions

View File

@ -167,4 +167,11 @@ M: hashtable assoc-like
: ?set-at ( value key assoc/f -- assoc ) : ?set-at ( value key assoc/f -- assoc )
[ [ set-at ] keep ] [ associate ] if* ; [ [ 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 INSTANCE: hashtable assoc

View File

@ -168,21 +168,8 @@ M: word reset-word
} reset-props } reset-props
] tri ; ] 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 ) : <word> ( name vocab -- word )
2dup 2hash >fixnum (word) dup new-word ; 2dup 0 hash-combine hash-combine >fixnum (word) dup new-word ;
: <uninterned-word> ( name -- word ) : <uninterned-word> ( name -- word )
f \ <uninterned-word> counter >fixnum (word) f \ <uninterned-word> counter >fixnum (word)