hashtables: slightly faster grow logic.

db4
John Benediktsson 2013-03-07 20:51:46 -08:00
parent f46bf3ac5d
commit f2eedb67ec
1 changed files with 6 additions and 4 deletions

View File

@ -88,16 +88,18 @@ TUPLE: hashtable
1 fixnum+fast set-slot ; inline
: (rehash) ( hash alist -- )
swap [ swapd set-at ] curry assoc-each ; inline
swap [ swapd dupd new-key@ set-nth-pair ] curry assoc-each ; inline
: hash-large? ( hash -- ? )
[ count>> 3 fixnum*fast 1 fixnum+fast ]
[ array>> length>> ] bi fixnum> ; inline
: grow-hash ( hash -- )
[ [ >alist ] [ assoc-size 1 + ] bi ] keep
[ reset-hash ] keep
swap (rehash) ;
{ hashtable } declare [
[ >alist { array } declare ]
[ assoc-size 1 + ]
[ reset-hash ] tri
] keep swap (rehash) ;
: ?grow-hash ( hash -- )
dup hash-large? [ grow-hash ] [ drop ] if ; inline