]> gitweb.factorcode.org Git - factor.git/commitdiff
hash-sets: separate <hash-set> and >hash-set to match other containers. Fixes #154.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 19 Oct 2011 18:35:25 +0000 (11:35 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 19 Oct 2011 18:35:25 +0000 (11:35 -0700)
core/hash-sets/hash-sets-docs.factor
core/hash-sets/hash-sets.factor
core/syntax/syntax.factor
extra/path-finding/path-finding.factor

index d59ebeca1037685f4bbac001a5282276d39cf380..cee49ef930cba41e129ef5b71c09d54f48064ac6 100644 (file)
@@ -1,11 +1,11 @@
-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"
@@ -14,5 +14,9 @@ HELP: hash-set
 { $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." } ;
index d032c660315379a9334d689773ca512695a017cc..1ed514c3f25b412e4723a4271cdb0b3ad285778b 100644 (file)
@@ -8,7 +8,10 @@ IN: hash-sets
 ! 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
@@ -16,12 +19,12 @@ M: hash-set in? table>> key? ; inline
 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
@@ -35,5 +38,4 @@ 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? ;
index 32a187c12c0faf113314491f34ca8bfd319d4e0c..9b47d29a9e38944cf499586927859f64ef5c30a5 100644 (file)
@@ -104,7 +104,7 @@ IN: bootstrap.syntax
     "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
index 1f6b4f5cc6424ba5112280a5a20c886e97fe2a45..e46e6549284f4d327b5b7877c25c5dc1fdc73728 100644 (file)
@@ -58,7 +58,7 @@ TUPLE: (astar) astar goal origin in-open-set open-set ;
 : (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