-USING: help.markup help.syntax sequences ;
+USING: help.markup help.syntax math sequences ;
IN: hash-sets
ARTICLE: "hash-sets" "Hash sets"
"The " { $vocab-link "hash-sets" } " vocabulary implements hashtable-backed sets. Hash sets form a class:"
-{ $subsection hash-set }
+{ $subsections hash-set }
"Constructing new hash sets:"
-{ $subsection <hash-set> }
+{ $subsections <hash-set> >hash-set }
"The syntax for hash sets is described in " { $link "syntax-hash-sets" } "." ;
ABOUT: "hash-sets"
{ $class-description "The class of hashtable-based sets. These implement the " { $link "sets" } "." } ;
HELP: <hash-set>
+{ $values { "capacity" number } { "hash-set" hash-set } }
+{ $description "Creates a new hash set capable of storing " { $snippet "capacity" } " elements before growing." } ;
+
+HELP: >hash-set
{ $values { "members" sequence } { "hash-set" hash-set } }
{ $description "Creates a new hash set with the given members." } ;
! In a better implementation, less memory would be used
TUPLE: hash-set { table hashtable read-only } ;
-: <hash-set> ( members -- hash-set )
+: <hash-set> ( capacity -- hash-set )
+ <hashtable> hash-set boa ; inline
+
+: >hash-set ( members -- hash-set )
unique hash-set boa ; inline
INSTANCE: hash-set set
M: hash-set adjoin table>> dupd set-at ; inline
M: hash-set delete table>> delete-at ; inline
M: hash-set members table>> keys ; inline
-M: hash-set set-like drop dup hash-set? [ members <hash-set> ] unless ;
+M: hash-set set-like drop dup hash-set? [ members >hash-set ] unless ;
M: hash-set clone table>> clone hash-set boa ;
M: hash-set null? table>> assoc-empty? ;
M: hash-set cardinality table>> assoc-size ;
-M: sequence fast-set <hash-set> ;
+M: sequence fast-set >hash-set ;
M: f fast-set drop H{ } clone hash-set boa ;
M: sequence duplicates
PRIVATE>
M: sequence all-unique?
- dup length <hashtable> hash-set boa
- [ (all-unique?) ] curry all? ;
+ dup length <hash-set> [ (all-unique?) ] curry all? ;
"H{" [ \ } [ >hashtable ] parse-literal ] define-core-syntax
"T{" [ parse-tuple-literal suffix! ] define-core-syntax
"W{" [ \ } [ first <wrapper> ] parse-literal ] define-core-syntax
- "HS{" [ \ } [ <hash-set> ] parse-literal ] define-core-syntax
+ "HS{" [ \ } [ >hash-set ] parse-literal ] define-core-syntax
"POSTPONE:" [ scan-word suffix! ] define-core-syntax
"\\" [ scan-word <wrapper> suffix! ] define-core-syntax
: (init) ( from to astar -- )
swap >>goal
H{ } clone over astar>> g<<
- { } <hash-set> over astar>> in-closed-set<<
+ HS{ } clone over astar>> in-closed-set<<
H{ } clone >>origin
H{ } clone >>in-open-set
<min-heap> >>open-set