hashtables: use cleavers in hashtables

db4
Eduardo Cavazos 2008-03-29 16:08:08 -06:00
parent a00e325b96
commit 8ea195d8ce
1 changed files with 10 additions and 6 deletions

View File

@ -95,11 +95,12 @@ IN: hashtables
[ swap pick (set-hash) drop f ] find-pair 2drop 2drop ; [ swap pick (set-hash) drop f ] find-pair 2drop 2drop ;
: hash-large? ( hash -- ? ) : hash-large? ( hash -- ? )
dup hash-count 3 fixnum*fast [ hash-count 3 fixnum*fast ]
swap hash-array array-capacity > ; [ hash-array array-capacity ] bi > ;
: hash-stale? ( hash -- ? ) : hash-stale? ( hash -- ? )
dup hash-deleted 10 fixnum*fast swap hash-count fixnum> ; [ hash-deleted 10 fixnum*fast ]
[ hash-count ] bi fixnum> ;
: grow-hash ( hash -- ) : grow-hash ( hash -- )
[ dup hash-array swap assoc-size 1+ ] keep [ dup hash-array swap assoc-size 1+ ] keep
@ -183,10 +184,13 @@ M: hashtable assoc-like
[ 3drop ] [ dupd dupd set-at swap push ] if ; inline [ 3drop ] [ dupd dupd set-at swap push ] if ; inline
: prune ( seq -- newseq ) : prune ( seq -- newseq )
dup length <hashtable> over length <vector> [ length <hashtable> ]
rot [ >r 2dup r> (prune) ] each nip ; [ length <vector> ]
[ ] tri
[ >r 2dup r> (prune) ] each nip ;
: all-unique? ( seq -- ? ) : all-unique? ( seq -- ? )
dup prune [ length ] 2apply = ; [ length ]
[ prune length ] bi = ;
INSTANCE: hashtable assoc INSTANCE: hashtable assoc