hash-sets: reuse (rehash).
parent
eca5253017
commit
23078f7bd7
|
@ -61,8 +61,11 @@ TUPLE: hash-set
|
||||||
: set-nth-item ( key seq n -- )
|
: set-nth-item ( key seq n -- )
|
||||||
2 fixnum+fast set-slot ; inline
|
2 fixnum+fast set-slot ; inline
|
||||||
|
|
||||||
: (rehash) ( hash seq -- )
|
: (adjoin) ( key hash -- )
|
||||||
swap [ dupd new-key@ set-nth-item ] curry each ; inline
|
dupd new-key@ set-nth-item ; inline
|
||||||
|
|
||||||
|
: (rehash) ( seq hash -- )
|
||||||
|
[ (adjoin) ] curry each ; inline
|
||||||
|
|
||||||
: hash-large? ( hash -- ? )
|
: hash-large? ( hash -- ? )
|
||||||
[ count>> 3 fixnum*fast 1 fixnum+fast ]
|
[ count>> 3 fixnum*fast 1 fixnum+fast ]
|
||||||
|
@ -73,7 +76,7 @@ TUPLE: hash-set
|
||||||
[ members { array } declare ]
|
[ members { array } declare ]
|
||||||
[ cardinality 1 + ]
|
[ cardinality 1 + ]
|
||||||
[ reset-hash ] tri
|
[ reset-hash ] tri
|
||||||
] keep swap (rehash) ;
|
] keep (rehash) ;
|
||||||
|
|
||||||
: ?grow-hash ( hash -- )
|
: ?grow-hash ( hash -- )
|
||||||
dup hash-large? [ grow-hash ] [ drop ] if ; inline
|
dup hash-large? [ grow-hash ] [ drop ] if ; inline
|
||||||
|
@ -101,7 +104,7 @@ M: hash-set cardinality ( hash -- n )
|
||||||
[ count>> ] [ deleted>> ] bi - ; inline
|
[ count>> ] [ deleted>> ] bi - ; inline
|
||||||
|
|
||||||
M: hash-set adjoin ( key hash -- )
|
M: hash-set adjoin ( key hash -- )
|
||||||
dup ?grow-hash dupd new-key@ set-nth-item ;
|
dup ?grow-hash (adjoin) ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
@ -128,7 +131,7 @@ M: hash-set equal?
|
||||||
over hash-set? [ set= ] [ 2drop f ] if ;
|
over hash-set? [ set= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
: >hash-set ( members -- hash-set )
|
: >hash-set ( members -- hash-set )
|
||||||
dup length <hash-set> [ [ adjoin ] curry each ] keep ;
|
dup length <hash-set> [ (rehash) ] keep ;
|
||||||
|
|
||||||
M: hash-set set-like
|
M: hash-set set-like
|
||||||
drop dup hash-set? [ ?members >hash-set ] unless ; inline
|
drop dup hash-set? [ ?members >hash-set ] unless ; inline
|
||||||
|
|
Loading…
Reference in New Issue