hash-sets: separate <hash-set> and >hash-set to match other containers. Fixes #154.
parent
f4a6e10818
commit
beb5b9bf64
|
@ -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." } ;
|
||||
|
|
|
@ -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? ;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue