diff --git a/core/hash-sets/hash-sets-docs.factor b/core/hash-sets/hash-sets-docs.factor index d59ebeca10..cee49ef930 100644 --- a/core/hash-sets/hash-sets-docs.factor +++ b/core/hash-sets/hash-sets-docs.factor @@ -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 } +{ $subsections >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: +{ $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." } ; diff --git a/core/hash-sets/hash-sets.factor b/core/hash-sets/hash-sets.factor index d032c66031..1ed514c3f2 100644 --- a/core/hash-sets/hash-sets.factor +++ b/core/hash-sets/hash-sets.factor @@ -8,7 +8,10 @@ IN: hash-sets ! In a better implementation, less memory would be used TUPLE: hash-set { table hashtable read-only } ; -: ( members -- hash-set ) +: ( capacity -- hash-set ) + 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 ] 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 ; +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 hash-set boa - [ (all-unique?) ] curry all? ; + dup length [ (all-unique?) ] curry all? ; diff --git a/core/syntax/syntax.factor b/core/syntax/syntax.factor index 32a187c12c..9b47d29a9e 100644 --- a/core/syntax/syntax.factor +++ b/core/syntax/syntax.factor @@ -104,7 +104,7 @@ IN: bootstrap.syntax "H{" [ \ } [ >hashtable ] parse-literal ] define-core-syntax "T{" [ parse-tuple-literal suffix! ] define-core-syntax "W{" [ \ } [ first ] parse-literal ] define-core-syntax - "HS{" [ \ } [ ] parse-literal ] define-core-syntax + "HS{" [ \ } [ >hash-set ] parse-literal ] define-core-syntax "POSTPONE:" [ scan-word suffix! ] define-core-syntax "\\" [ scan-word suffix! ] define-core-syntax diff --git a/extra/path-finding/path-finding.factor b/extra/path-finding/path-finding.factor index 1f6b4f5cc6..e46e654928 100644 --- a/extra/path-finding/path-finding.factor +++ b/extra/path-finding/path-finding.factor @@ -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<< - { } over astar>> in-closed-set<< + HS{ } clone over astar>> in-closed-set<< H{ } clone >>origin H{ } clone >>in-open-set >>open-set