IN: hash-sets
ARTICLE: "hash-sets" "Hash sets"
-"The " { $vocab-link "hash-sets" } " vocabulary implements hashtable-backed sets. Hash sets form a class:"
+"The " { $vocab-link "hash-sets" } " vocabulary implements hashtable-like sets. Hash sets form a class:"
{ $subsections hash-set }
"Constructing new hash sets:"
{ $subsections <hash-set> >hash-set }
ABOUT: "hash-sets"
HELP: hash-set
-{ $class-description "The class of hashtable-based sets. These implement the " { $link "sets" } "." } ;
+{ $class-description "The class of hashtable-like sets. These implement the " { $link "sets" } "." } ;
HELP: <hash-set>
{ $values { "capacity" number } { "hash-set" hash-set } }
PRIVATE>
-: <hash-set> ( n -- hash )
+: <hash-set> ( capacity -- hash-set )
hash-set new [ reset-hash ] keep ; inline
-M: hash-set in? ( key hash -- ? )
+M: hash-set in?
key@ 2nip ;
-M: hash-set clear-set ( hash -- )
+M: hash-set clear-set
[ init-hash ] [ array>> [ drop ((empty)) ] map! drop ] bi ;
-M: hash-set delete ( key hash -- )
+M: hash-set delete
[ nip ] [ key@ ] 2bi [
[ ((tombstone)) ] 2dip set-nth-item
hash-deleted+
3drop
] if ;
-M: hash-set cardinality ( hash -- n )
+M: hash-set cardinality
[ count>> ] [ deleted>> ] bi - ; inline
-: rehash ( hash -- )
+: rehash ( hash-set -- )
[ members ] [ clear-set ] [ (rehash) ] tri ;
-M: hash-set adjoin ( key hash -- )
+M: hash-set adjoin ( key hash-set -- )
dup ?grow-hash (adjoin) ;
<PRIVATE