hash-sets: faster grow-hash by not calling members.
parent
5bf5cb3446
commit
8890bdc19a
|
@ -71,12 +71,18 @@ TUPLE: hash-set
|
||||||
[ count>> 3 fixnum*fast 1 fixnum+fast ]
|
[ count>> 3 fixnum*fast 1 fixnum+fast ]
|
||||||
[ array>> length>> 1 fixnum-shift-fast ] bi fixnum> ; inline
|
[ array>> length>> 1 fixnum-shift-fast ] bi fixnum> ; inline
|
||||||
|
|
||||||
|
: each-member ( array quot: ( elt -- ) -- )
|
||||||
|
[
|
||||||
|
[ length ] keep
|
||||||
|
[ array-nth dup tombstone? [ drop ] ] curry
|
||||||
|
] dip [ if ] curry compose each-integer ; inline
|
||||||
|
|
||||||
: grow-hash ( hash -- )
|
: grow-hash ( hash -- )
|
||||||
{ hash-set } declare [
|
{ hash-set } declare [
|
||||||
[ members { array } declare ]
|
[ array>> ]
|
||||||
[ cardinality 1 + ]
|
[ cardinality 1 + ]
|
||||||
[ reset-hash ] tri
|
[ reset-hash ] tri
|
||||||
] keep (rehash) ;
|
] keep [ (adjoin) ] curry each-member ;
|
||||||
|
|
||||||
: ?grow-hash ( hash -- )
|
: ?grow-hash ( hash -- )
|
||||||
dup hash-large? [ grow-hash ] [ drop ] if ; inline
|
dup hash-large? [ grow-hash ] [ drop ] if ; inline
|
||||||
|
@ -110,11 +116,8 @@ M: hash-set adjoin ( key hash-set -- )
|
||||||
dup ?grow-hash (adjoin) ;
|
dup ?grow-hash (adjoin) ;
|
||||||
|
|
||||||
M: hash-set members
|
M: hash-set members
|
||||||
[ array>> [ length ] keep ] [ cardinality <vector> ] bi [
|
[ array>> ] [ cardinality <vector> ] bi [
|
||||||
[
|
[ push-unsafe ] curry each-member
|
||||||
[ array-nth ] dip over tombstone?
|
|
||||||
[ 2drop ] [ push-unsafe ] if
|
|
||||||
] 2curry each-integer
|
|
||||||
] keep { } like ;
|
] keep { } like ;
|
||||||
|
|
||||||
M: hash-set clone
|
M: hash-set clone
|
||||||
|
|
Loading…
Reference in New Issue