hashtables: slightly faster grow logic.
parent
f46bf3ac5d
commit
f2eedb67ec
|
@ -88,16 +88,18 @@ TUPLE: hashtable
|
||||||
1 fixnum+fast set-slot ; inline
|
1 fixnum+fast set-slot ; inline
|
||||||
|
|
||||||
: (rehash) ( hash alist -- )
|
: (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 -- ? )
|
: hash-large? ( hash -- ? )
|
||||||
[ count>> 3 fixnum*fast 1 fixnum+fast ]
|
[ count>> 3 fixnum*fast 1 fixnum+fast ]
|
||||||
[ array>> length>> ] bi fixnum> ; inline
|
[ array>> length>> ] bi fixnum> ; inline
|
||||||
|
|
||||||
: grow-hash ( hash -- )
|
: grow-hash ( hash -- )
|
||||||
[ [ >alist ] [ assoc-size 1 + ] bi ] keep
|
{ hashtable } declare [
|
||||||
[ reset-hash ] keep
|
[ >alist { array } declare ]
|
||||||
swap (rehash) ;
|
[ assoc-size 1 + ]
|
||||||
|
[ reset-hash ] tri
|
||||||
|
] keep swap (rehash) ;
|
||||||
|
|
||||||
: ?grow-hash ( hash -- )
|
: ?grow-hash ( hash -- )
|
||||||
dup hash-large? [ grow-hash ] [ drop ] if ; inline
|
dup hash-large? [ grow-hash ] [ drop ] if ; inline
|
||||||
|
|
Loading…
Reference in New Issue