Skip to content

Commit

Permalink
hash-sets: faster grow-hash by not calling members.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Mar 21, 2013
1 parent e36ba8b commit a75d852
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions core/hash-sets/hash-sets.factor
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ TUPLE: hash-set
[ count>> 3 fixnum*fast 1 fixnum+fast ]
[ 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 -- )
{ hash-set } declare [
[ members { array } declare ]
[ array>> ]
[ cardinality 1 + ]
[ reset-hash ] tri
] keep (rehash) ;
] keep [ (adjoin) ] curry each-member ;

: ?grow-hash ( hash -- )
dup hash-large? [ grow-hash ] [ drop ] if ; inline
Expand Down Expand Up @@ -110,11 +116,8 @@ M: hash-set adjoin ( key hash-set -- )
dup ?grow-hash (adjoin) ;

M: hash-set members
[ array>> [ length ] keep ] [ cardinality <vector> ] bi [
[
[ array-nth ] dip over tombstone?
[ 2drop ] [ push-unsafe ] if
] 2curry each-integer
[ array>> ] [ cardinality <vector> ] bi [
[ push-unsafe ] curry each-member
] keep { } like ;

M: hash-set clone
Expand Down

0 comments on commit a75d852

Please sign in to comment.