hashtables: faster grow-hash by not calling >alist.
parent
8890bdc19a
commit
11e86ec53c
|
@ -97,12 +97,21 @@ TUPLE: hashtable
|
||||||
[ count>> 3 fixnum*fast 1 fixnum+fast ]
|
[ count>> 3 fixnum*fast 1 fixnum+fast ]
|
||||||
[ array>> length>> ] bi fixnum> ; inline
|
[ array>> length>> ] bi fixnum> ; inline
|
||||||
|
|
||||||
|
: each-pair ( array quot: ( key value -- ) -- )
|
||||||
|
[
|
||||||
|
[ length 2/ ] keep [
|
||||||
|
[ 1 fixnum-shift-fast ] dip [ array-nth ] 2keep
|
||||||
|
pick tombstone? [ 3drop ]
|
||||||
|
] curry
|
||||||
|
] dip [ [ 1 fixnum+fast ] dip array-nth ] prepose
|
||||||
|
[ if ] curry compose each-integer ; inline
|
||||||
|
|
||||||
: grow-hash ( hash -- )
|
: grow-hash ( hash -- )
|
||||||
{ hashtable } declare [
|
{ hashtable } declare [
|
||||||
[ >alist { array } declare ]
|
[ array>> ]
|
||||||
[ assoc-size 1 + ]
|
[ assoc-size 1 + ]
|
||||||
[ reset-hash ] tri
|
[ reset-hash ] tri
|
||||||
] keep (rehash) ;
|
] keep [ swapd (set-at) ] curry each-pair ;
|
||||||
|
|
||||||
: ?grow-hash ( hash -- )
|
: ?grow-hash ( hash -- )
|
||||||
dup hash-large? [ grow-hash ] [ drop ] if ; inline
|
dup hash-large? [ grow-hash ] [ drop ] if ; inline
|
||||||
|
@ -149,14 +158,8 @@ M: hashtable set-at ( value key hash -- )
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
M: hashtable >alist
|
M: hashtable >alist
|
||||||
[ array>> [ length 2/ ] keep ] [ assoc-size <vector> ] bi [
|
[ array>> ] [ assoc-size <vector> ] bi [
|
||||||
[
|
[ [ 2array ] dip push-unsafe ] curry each-pair
|
||||||
[
|
|
||||||
[ 1 fixnum-shift-fast ] dip
|
|
||||||
[ array-nth ] [ [ 1 fixnum+fast ] dip array-nth ] 2bi
|
|
||||||
] dip
|
|
||||||
pick tombstone? [ 3drop ] [ [ 2array ] dip push-unsafe ] if
|
|
||||||
] 2curry each-integer
|
|
||||||
] keep { } like ;
|
] keep { } like ;
|
||||||
|
|
||||||
M: hashtable clone
|
M: hashtable clone
|
||||||
|
|
Loading…
Reference in New Issue