factor: rename set to unordered-set.
parent
16fac5981e
commit
28dcd0667a
|
@ -9,7 +9,7 @@ TUPLE: bit-set { table bit-array read-only } ;
|
||||||
: <bit-set> ( capacity -- bit-set )
|
: <bit-set> ( capacity -- bit-set )
|
||||||
<bit-array> bit-set boa ; inline
|
<bit-array> bit-set boa ; inline
|
||||||
|
|
||||||
INSTANCE: bit-set set
|
INSTANCE: bit-set unordered-set
|
||||||
|
|
||||||
M: bit-set in?
|
M: bit-set in?
|
||||||
over integer? [ table>> ?nth ] [ 2drop f ] if ; inline
|
over integer? [ table>> ?nth ] [ 2drop f ] if ; inline
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespaces quotations sequences sequences.generalizations
|
||||||
sequences.private sets sets.private stack-checker
|
sequences.private sets sets.private stack-checker
|
||||||
stack-checker.dependencies vectors words ;
|
stack-checker.dependencies vectors words ;
|
||||||
FROM: math => float ;
|
FROM: math => float ;
|
||||||
FROM: sets => set ;
|
|
||||||
IN: compiler.tree.propagation.transforms
|
IN: compiler.tree.propagation.transforms
|
||||||
|
|
||||||
\ equal? [
|
\ equal? [
|
||||||
|
@ -303,17 +302,17 @@ CONSTANT: lookup-table-at-max 256
|
||||||
: diff-quot ( seq -- quot: ( seq' -- seq'' ) )
|
: diff-quot ( seq -- quot: ( seq' -- seq'' ) )
|
||||||
[ tester ] keep '[ members [ @ ] reject _ set-like ] ;
|
[ tester ] keep '[ members [ @ ] reject _ set-like ] ;
|
||||||
|
|
||||||
M\ set diff [ diff-quot ] 1 define-partial-eval
|
M\ unordered-set diff [ diff-quot ] 1 define-partial-eval
|
||||||
|
|
||||||
: intersect-quot ( seq -- quot: ( seq' -- seq'' ) )
|
: intersect-quot ( seq -- quot: ( seq' -- seq'' ) )
|
||||||
[ tester ] keep '[ members _ filter _ set-like ] ;
|
[ tester ] keep '[ members _ filter _ set-like ] ;
|
||||||
|
|
||||||
M\ set intersect [ intersect-quot ] 1 define-partial-eval
|
M\ unordered-set intersect [ intersect-quot ] 1 define-partial-eval
|
||||||
|
|
||||||
: intersects?-quot ( seq -- quot: ( seq' -- seq'' ) )
|
: intersects?-quot ( seq -- quot: ( seq' -- seq'' ) )
|
||||||
tester '[ members _ any? ] ;
|
tester '[ members _ any? ] ;
|
||||||
|
|
||||||
M\ set intersects? [ intersects?-quot ] 1 define-partial-eval
|
M\ unordered-set intersects? [ intersects?-quot ] 1 define-partial-eval
|
||||||
|
|
||||||
: bit-quot ( #call -- quot/f )
|
: bit-quot ( #call -- quot/f )
|
||||||
in-d>> second value-info interval>> 0 fixnum-bits [a,b] interval-subset?
|
in-d>> second value-info interval>> 0 fixnum-bits [a,b] interval-subset?
|
||||||
|
|
|
@ -45,6 +45,6 @@ M: wrapped-hash-set members
|
||||||
M: wrapped-hash-set equal?
|
M: wrapped-hash-set equal?
|
||||||
over wrapped-hash-set? [ [ underlying>> ] same? ] [ 2drop f ] if ;
|
over wrapped-hash-set? [ [ underlying>> ] same? ] [ 2drop f ] if ;
|
||||||
|
|
||||||
INSTANCE: wrapped-hash-set set
|
INSTANCE: wrapped-hash-set unordered-set
|
||||||
|
|
||||||
{ "hash-sets.wrapped" "prettyprint" } "hash-sets.wrapped.prettyprint" require-when
|
{ "hash-sets.wrapped" "prettyprint" } "hash-sets.wrapped.prettyprint" require-when
|
||||||
|
|
|
@ -105,7 +105,7 @@ M: hashtable random
|
||||||
[ array-nth ] [ [ 1 + ] dip array-nth ] 2bi 2array
|
[ array-nth ] [ [ 1 + ] dip array-nth ] 2bi 2array
|
||||||
] if-zero ;
|
] if-zero ;
|
||||||
|
|
||||||
M: sets:set random members random ;
|
M: unordered-set random members random ;
|
||||||
|
|
||||||
M: hash-set random
|
M: hash-set random
|
||||||
dup cardinality [ drop f ] [
|
dup cardinality [ drop f ] [
|
||||||
|
|
|
@ -26,7 +26,7 @@ M: assoc summary
|
||||||
" entries" %
|
" entries" %
|
||||||
] "" make ;
|
] "" make ;
|
||||||
|
|
||||||
M: set summary
|
M: unordered-set summary
|
||||||
[
|
[
|
||||||
dup class-of name>> %
|
dup class-of name>> %
|
||||||
" with " %
|
" with " %
|
||||||
|
|
|
@ -55,7 +55,7 @@ HELP: usage.
|
||||||
{ $examples { $code "\\ reverse usage." } } ;
|
{ $examples { $code "\\ reverse usage." } } ;
|
||||||
|
|
||||||
HELP: quot-uses
|
HELP: quot-uses
|
||||||
{ $values { "obj" object } { "set" "a " { $link set } " of words" } }
|
{ $values { "obj" object } { "set" "a " { $link unordered-set } " of words" } }
|
||||||
{ $description "Outputs a set of words referenced by the quotation and any quotations it contains." } ;
|
{ $description "Outputs a set of words referenced by the quotation and any quotations it contains." } ;
|
||||||
|
|
||||||
{ usage usage. } related-words
|
{ usage usage. } related-words
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
USING: accessors assocs classes classes.algebra
|
USING: accessors assocs classes classes.algebra
|
||||||
classes.algebra.private classes.builtin classes.private
|
classes.algebra.private classes.builtin classes.private
|
||||||
combinators definitions kernel kernel.private math math.private
|
combinators definitions kernel kernel.private math math.private
|
||||||
quotations sequences words ;
|
quotations sequences sets words ;
|
||||||
FROM: sets => set= ;
|
|
||||||
IN: classes.union
|
IN: classes.union
|
||||||
|
|
||||||
PREDICATE: union-class < class
|
PREDICATE: union-class < class
|
||||||
|
|
|
@ -11,7 +11,7 @@ ARTICLE: "hash-sets" "Hash sets"
|
||||||
ABOUT: "hash-sets"
|
ABOUT: "hash-sets"
|
||||||
|
|
||||||
HELP: hash-set
|
HELP: hash-set
|
||||||
{ $class-description "The class of hashtable-like sets. These implement the " { $link set } " mixin." } ;
|
{ $class-description "The class of hashtable-like sets. These implement the " { $link unordered-set } " mixin." } ;
|
||||||
|
|
||||||
HELP: <hash-set>
|
HELP: <hash-set>
|
||||||
{ $values { "capacity" number } { "hash-set" hash-set } }
|
{ $values { "capacity" number } { "hash-set" hash-set } }
|
||||||
|
|
|
@ -134,7 +134,7 @@ M: hash-set equal?
|
||||||
M: hash-set set-like
|
M: hash-set set-like
|
||||||
drop dup hash-set? [ ?members >hash-set ] unless ; inline
|
drop dup hash-set? [ ?members >hash-set ] unless ; inline
|
||||||
|
|
||||||
INSTANCE: hash-set set
|
INSTANCE: hash-set unordered-set
|
||||||
|
|
||||||
! Overrides for performance
|
! Overrides for performance
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@ quotations sequences vectors ;
|
||||||
IN: sets
|
IN: sets
|
||||||
|
|
||||||
ARTICLE: "sets" "Sets"
|
ARTICLE: "sets" "Sets"
|
||||||
"A set is an unordered list of elements. Words for working with sets are in the " { $vocab-link "sets" } " vocabulary." $nl
|
"A set is an unordered collection of elements. Words for working with sets are in the " { $vocab-link "sets" } " vocabulary." $nl
|
||||||
"All sets are instances of a mixin class:"
|
"All sets are instances of a mixin class:"
|
||||||
{ $subsections
|
{ $subsections
|
||||||
set
|
unordered-set
|
||||||
set?
|
unordered-set?
|
||||||
}
|
}
|
||||||
{ $subsections "set-operations" "set-implementations" } ;
|
{ $subsections "set-operations" "set-implementations" } ;
|
||||||
|
|
||||||
|
@ -73,11 +73,11 @@ $nl
|
||||||
$nl
|
$nl
|
||||||
"As one particular example, " { $link POSTPONE: f } " is a representation of the empty set, since it is an empty sequence." ;
|
"As one particular example, " { $link POSTPONE: f } " is a representation of the empty set, since it is an empty sequence." ;
|
||||||
|
|
||||||
HELP: set
|
HELP: unordered-set
|
||||||
{ $class-description "The class of all sets. Custom implementations of the set protocol should be declared as instances of this mixin for all set implementation to work correctly." } ;
|
{ $class-description "The class of all sets. Custom implementations of the set protocol should be declared as instances of this mixin for all set implementation to work correctly." } ;
|
||||||
|
|
||||||
HELP: adjoin
|
HELP: adjoin
|
||||||
{ $values { "elt" object } { "set" set } }
|
{ $values { "elt" object } { "set" unordered-set } }
|
||||||
{ $description "Destructively adds " { $snippet "elt" } " to " { $snippet "set" } ". For sequences, this guarantees that this element is not duplicated, and that it is at the end of the sequence." $nl "Each mutable set type is expected to implement a method on this generic word." }
|
{ $description "Destructively adds " { $snippet "elt" } " to " { $snippet "set" } ". For sequences, this guarantees that this element is not duplicated, and that it is at the end of the sequence." $nl "Each mutable set type is expected to implement a method on this generic word." }
|
||||||
{ $examples
|
{ $examples
|
||||||
{ $example
|
{ $example
|
||||||
|
@ -92,26 +92,26 @@ HELP: adjoin
|
||||||
{ $side-effects "set" } ;
|
{ $side-effects "set" } ;
|
||||||
|
|
||||||
HELP: ?adjoin
|
HELP: ?adjoin
|
||||||
{ $values { "elt" object } { "set" set } { "?" boolean } }
|
{ $values { "elt" object } { "set" unordered-set } { "?" boolean } }
|
||||||
{ $description "A version of " { $link adjoin } " which returns whether the element was added to the set." }
|
{ $description "A version of " { $link adjoin } " which returns whether the element was added to the set." }
|
||||||
{ $notes "This is slightly less efficient than " { $link adjoin } " due to the initial membership test." } ;
|
{ $notes "This is slightly less efficient than " { $link adjoin } " due to the initial membership test." } ;
|
||||||
|
|
||||||
HELP: delete
|
HELP: delete
|
||||||
{ $values { "elt" object } { "set" set } }
|
{ $values { "elt" object } { "set" unordered-set } }
|
||||||
{ $description "Destructively removes " { $snippet "elt" } " from " { $snippet "set" } ". If the element is not present, this does nothing." $nl "Each mutable set type is expected to implement a method on this generic word." }
|
{ $description "Destructively removes " { $snippet "elt" } " from " { $snippet "set" } ". If the element is not present, this does nothing." $nl "Each mutable set type is expected to implement a method on this generic word." }
|
||||||
{ $side-effects "set" } ;
|
{ $side-effects "set" } ;
|
||||||
|
|
||||||
HELP: clear-set
|
HELP: clear-set
|
||||||
{ $values { "set" set } }
|
{ $values { "set" unordered-set } }
|
||||||
{ $contract "Removes all entries from the set." }
|
{ $contract "Removes all entries from the set." }
|
||||||
{ $side-effects "set" } ;
|
{ $side-effects "set" } ;
|
||||||
|
|
||||||
HELP: members
|
HELP: members
|
||||||
{ $values { "set" set } { "seq" sequence } }
|
{ $values { "set" unordered-set } { "seq" sequence } }
|
||||||
{ $description "Creates a sequence with a single copy of each member of the set." $nl "Each set type is expected to implement a method on this generic word." } ;
|
{ $description "Creates a sequence with a single copy of each member of the set." $nl "Each set type is expected to implement a method on this generic word." } ;
|
||||||
|
|
||||||
HELP: in?
|
HELP: in?
|
||||||
{ $values { "elt" object } { "set" set } { "?" boolean } }
|
{ $values { "elt" object } { "set" unordered-set } { "?" boolean } }
|
||||||
{ $description "Tests whether the element is a member of the set." $nl "Each set type is expected to implement a method on this generic word as part of the set protocol." } ;
|
{ $description "Tests whether the element is a member of the set." $nl "Each set type is expected to implement a method on this generic word as part of the set protocol." } ;
|
||||||
|
|
||||||
HELP: adjoin-at
|
HELP: adjoin-at
|
||||||
|
@ -120,14 +120,14 @@ HELP: adjoin-at
|
||||||
{ $side-effects "assoc" } ;
|
{ $side-effects "assoc" } ;
|
||||||
|
|
||||||
HELP: duplicates
|
HELP: duplicates
|
||||||
{ $values { "set" set } { "seq" sequence } }
|
{ $values { "set" unordered-set } { "seq" sequence } }
|
||||||
{ $description "Outputs a sequence consisting of elements which occur more than once in " { $snippet "set" } "." }
|
{ $description "Outputs a sequence consisting of elements which occur more than once in " { $snippet "set" } "." }
|
||||||
{ $examples
|
{ $examples
|
||||||
{ $example "USING: sets prettyprint ;" "{ 1 2 3 1 2 1 } duplicates ." "{ 1 2 1 }" }
|
{ $example "USING: sets prettyprint ;" "{ 1 2 3 1 2 1 } duplicates ." "{ 1 2 1 }" }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: all-unique?
|
HELP: all-unique?
|
||||||
{ $values { "set" set } { "?" boolean } }
|
{ $values { "set" unordered-set } { "?" boolean } }
|
||||||
{ $description "Tests whether a set contains any repeated elements." }
|
{ $description "Tests whether a set contains any repeated elements." }
|
||||||
{ $example
|
{ $example
|
||||||
"USING: sets prettyprint ;"
|
"USING: sets prettyprint ;"
|
||||||
|
@ -136,14 +136,14 @@ HELP: all-unique?
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: diff
|
HELP: diff
|
||||||
{ $values { "set1" set } { "set2" set } { "set" set } }
|
{ $values { "set1" unordered-set } { "set2" unordered-set } { "set" unordered-set } }
|
||||||
{ $description "Outputs a set consisting of elements present in " { $snippet "set1" } " but not " { $snippet "set2" } ", comparing elements for equality." $nl "This word has a default definition which works for all sets, but set implementations may override the default for efficiency."
|
{ $description "Outputs a set consisting of elements present in " { $snippet "set1" } " but not " { $snippet "set2" } ", comparing elements for equality." $nl "This word has a default definition which works for all sets, but set implementations may override the default for efficiency."
|
||||||
} { $examples
|
} { $examples
|
||||||
{ $example "USING: sets prettyprint ;" "{ 1 2 3 } { 2 3 4 } diff ." "{ 1 }" }
|
{ $example "USING: sets prettyprint ;" "{ 1 2 3 } { 2 3 4 } diff ." "{ 1 }" }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: intersect
|
HELP: intersect
|
||||||
{ $values { "set1" set } { "set2" set } { "set" set } }
|
{ $values { "set1" unordered-set } { "set2" unordered-set } { "set" unordered-set } }
|
||||||
{ $description "Outputs a set consisting of elements present in both " { $snippet "set1" } " and " { $snippet "set2" } "."
|
{ $description "Outputs a set consisting of elements present in both " { $snippet "set1" } " and " { $snippet "set2" } "."
|
||||||
"This word has a default definition which works for all sets, but set implementations may override the default for efficiency." }
|
"This word has a default definition which works for all sets, but set implementations may override the default for efficiency." }
|
||||||
{ $examples
|
{ $examples
|
||||||
|
@ -151,11 +151,11 @@ HELP: intersect
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: intersection
|
HELP: intersection
|
||||||
{ $values { "sets" sequence } { "set/f" { $maybe set } } }
|
{ $values { "sets" sequence } { "set/f" { $maybe unordered-set } } }
|
||||||
{ $description "Outputs the intersection of all the sets of the sequence " { $snippet "sets" } ", or " { $link f } " if " { $snippet "sets" } " is empty." } ;
|
{ $description "Outputs the intersection of all the sets of the sequence " { $snippet "sets" } ", or " { $link f } " if " { $snippet "sets" } " is empty." } ;
|
||||||
|
|
||||||
HELP: union
|
HELP: union
|
||||||
{ $values { "set1" set } { "set2" set } { "set" set } }
|
{ $values { "set1" unordered-set } { "set2" unordered-set } { "set" unordered-set } }
|
||||||
{ $description "Outputs a set consisting of elements present in either " { $snippet "set1" } " or " { $snippet "set2" } " which does not contain duplicate values." $nl "This word has a default definition which works for all sets, but set implementations may override the default for efficiency." }
|
{ $description "Outputs a set consisting of elements present in either " { $snippet "set1" } " or " { $snippet "set2" } " which does not contain duplicate values." $nl "This word has a default definition which works for all sets, but set implementations may override the default for efficiency." }
|
||||||
{ $examples
|
{ $examples
|
||||||
{ $example "USING: sets prettyprint ;" "{ 1 2 3 } { 2 3 4 } union ." "{ 1 2 3 4 }" }
|
{ $example "USING: sets prettyprint ;" "{ 1 2 3 } { 2 3 4 } union ." "{ 1 2 3 4 }" }
|
||||||
|
@ -164,32 +164,32 @@ HELP: union
|
||||||
{ diff intersect union } related-words
|
{ diff intersect union } related-words
|
||||||
|
|
||||||
HELP: union!
|
HELP: union!
|
||||||
{ $values { "set1" set } { "set2" set } }
|
{ $values { "set1" unordered-set } { "set2" unordered-set } }
|
||||||
{ $description "Adds all members from " { $snippet "set2" } " to " { $snippet "set1" } "." }
|
{ $description "Adds all members from " { $snippet "set2" } " to " { $snippet "set1" } "." }
|
||||||
{ $side-effects "set1" } ;
|
{ $side-effects "set1" } ;
|
||||||
|
|
||||||
HELP: diff!
|
HELP: diff!
|
||||||
{ $values { "set1" set } { "set2" set } }
|
{ $values { "set1" unordered-set } { "set2" unordered-set } }
|
||||||
{ $description "Removes all members from " { $snippet "set1" } " contained in " { $snippet "set2" } "." }
|
{ $description "Removes all members from " { $snippet "set1" } " contained in " { $snippet "set2" } "." }
|
||||||
{ $side-effects "set1" } ;
|
{ $side-effects "set1" } ;
|
||||||
|
|
||||||
HELP: intersect!
|
HELP: intersect!
|
||||||
{ $values { "set1" set } { "set2" set } }
|
{ $values { "set1" unordered-set } { "set2" unordered-set } }
|
||||||
{ $description "Removes all members from " { $snippet "set1" } " not contained in " { $snippet "set2" } "." }
|
{ $description "Removes all members from " { $snippet "set1" } " not contained in " { $snippet "set2" } "." }
|
||||||
{ $side-effects "set1" } ;
|
{ $side-effects "set1" } ;
|
||||||
|
|
||||||
HELP: intersects?
|
HELP: intersects?
|
||||||
{ $values { "set1" set } { "set2" set } { "?" boolean } }
|
{ $values { "set1" unordered-set } { "set2" unordered-set } { "?" boolean } }
|
||||||
{ $description "Tests if " { $snippet "set1" } " and " { $snippet "set2" } " have any elements in common." }
|
{ $description "Tests if " { $snippet "set1" } " and " { $snippet "set2" } " have any elements in common." }
|
||||||
{ $notes "If one of the sets is empty, the result is always " { $link f } "." } ;
|
{ $notes "If one of the sets is empty, the result is always " { $link f } "." } ;
|
||||||
|
|
||||||
HELP: subset?
|
HELP: subset?
|
||||||
{ $values { "set1" set } { "set2" set } { "?" boolean } }
|
{ $values { "set1" unordered-set } { "set2" unordered-set } { "?" boolean } }
|
||||||
{ $description "Tests if every element of " { $snippet "set1" } " is contained in " { $snippet "set2" } "." }
|
{ $description "Tests if every element of " { $snippet "set1" } " is contained in " { $snippet "set2" } "." }
|
||||||
{ $notes "If " { $snippet "set1" } " is empty, the result is always " { $link t } "." } ;
|
{ $notes "If " { $snippet "set1" } " is empty, the result is always " { $link t } "." } ;
|
||||||
|
|
||||||
HELP: set=
|
HELP: set=
|
||||||
{ $values { "set1" set } { "set2" set } { "?" boolean } }
|
{ $values { "set1" unordered-set } { "set2" unordered-set } { "?" boolean } }
|
||||||
{ $description "Tests if both sets contain the same elements, disregrading order and duplicates." } ;
|
{ $description "Tests if both sets contain the same elements, disregrading order and duplicates." } ;
|
||||||
|
|
||||||
HELP: gather
|
HELP: gather
|
||||||
|
@ -199,28 +199,28 @@ HELP: gather
|
||||||
{ $description "Maps a quotation onto a sequence, concatenates the results of the mapping, and removes duplicates." } ;
|
{ $description "Maps a quotation onto a sequence, concatenates the results of the mapping, and removes duplicates." } ;
|
||||||
|
|
||||||
HELP: set-like
|
HELP: set-like
|
||||||
{ $values { "set" set } { "exemplar" set } { "set'" set } }
|
{ $values { "set" unordered-set } { "exemplar" unordered-set } { "set'" unordered-set } }
|
||||||
{ $description "If the conversion is defined for the exemplar, converts the set into a set of the exemplar's class. This is not guaranteed to create a new set, for example if the input set and exemplar are of the same class." $nl "Set implementations may optionally implement a method on this generic word. The default implementation returns its input set." }
|
{ $description "If the conversion is defined for the exemplar, converts the set into a set of the exemplar's class. This is not guaranteed to create a new set, for example if the input set and exemplar are of the same class." $nl "Set implementations may optionally implement a method on this generic word. The default implementation returns its input set." }
|
||||||
{ $examples
|
{ $examples
|
||||||
{ $example "USING: sets prettyprint ;" "{ 1 2 3 } HS{ } set-like ." "HS{ 1 2 3 }" }
|
{ $example "USING: sets prettyprint ;" "{ 1 2 3 } HS{ } set-like ." "HS{ 1 2 3 }" }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: within
|
HELP: within
|
||||||
{ $values { "seq" sequence } { "set" set } { "subseq" sequence } }
|
{ $values { "seq" sequence } { "set" unordered-set } { "subseq" sequence } }
|
||||||
{ $description "Returns the subsequence of the given sequence consisting of members of the set. This may contain duplicates, if the sequence has duplicates." } ;
|
{ $description "Returns the subsequence of the given sequence consisting of members of the set. This may contain duplicates, if the sequence has duplicates." } ;
|
||||||
|
|
||||||
HELP: without
|
HELP: without
|
||||||
{ $values { "seq" sequence } { "set" set } { "subseq" sequence } }
|
{ $values { "seq" sequence } { "set" unordered-set } { "subseq" sequence } }
|
||||||
{ $description "Returns the subsequence of the given sequence consisting of things that are not members of the set. This may contain duplicates, if the sequence has duplicates." } ;
|
{ $description "Returns the subsequence of the given sequence consisting of things that are not members of the set. This may contain duplicates, if the sequence has duplicates." } ;
|
||||||
|
|
||||||
HELP: null?
|
HELP: null?
|
||||||
{ $values { "set" set } { "?" boolean } }
|
{ $values { "set" unordered-set } { "?" boolean } }
|
||||||
{ $description "Tests whether the given set is empty. This outputs " { $snippet "t" } " when given a null set of any type." } ;
|
{ $description "Tests whether the given set is empty. This outputs " { $snippet "t" } " when given a null set of any type." } ;
|
||||||
|
|
||||||
HELP: cardinality
|
HELP: cardinality
|
||||||
{ $values { "set" set } { "n" "a non-negative integer" } }
|
{ $values { "set" unordered-set } { "n" "a non-negative integer" } }
|
||||||
{ $description "Returns the number of elements in the set. All sets support this operation." } ;
|
{ $description "Returns the number of elements in the set. All sets support this operation." } ;
|
||||||
|
|
||||||
HELP: combine
|
HELP: combine
|
||||||
{ $values { "sets" "a sequence of sets" } { "set/f" { $maybe set } } }
|
{ $values { "sets" "a sequence of sets" } { "set/f" { $maybe unordered-set } } }
|
||||||
{ $description "Outputs the union of a sequence of sets, or " { $link f } " if the sequence is empty." } ;
|
{ $description "Outputs the union of a sequence of sets, or " { $link f } " if the sequence is empty." } ;
|
||||||
|
|
|
@ -111,18 +111,18 @@ IN: sets.tests
|
||||||
{ H{ { 3 H{ { 1 1 } { 2 2 } } } } } [ H{ } clone 1 3 pick conjoin-at 2 3 pick conjoin-at ] unit-test
|
{ H{ { 3 H{ { 1 1 } { 2 2 } } } } } [ H{ } clone 1 3 pick conjoin-at 2 3 pick conjoin-at ] unit-test
|
||||||
|
|
||||||
TUPLE: null-set ;
|
TUPLE: null-set ;
|
||||||
INSTANCE: null-set set
|
INSTANCE: null-set unordered-set
|
||||||
M: null-set members drop f ;
|
M: null-set members drop f ;
|
||||||
|
|
||||||
{ 0 } [ T{ null-set } cardinality ] unit-test
|
{ 0 } [ T{ null-set } cardinality ] unit-test
|
||||||
{ f } [ T{ null-set } members ] unit-test
|
{ f } [ T{ null-set } members ] unit-test
|
||||||
{ t } [ T{ null-set } T{ null-set } set-like T{ null-set } = ] unit-test
|
{ t } [ T{ null-set } T{ null-set } set-like T{ null-set } = ] unit-test
|
||||||
|
|
||||||
{ t } [ T{ null-set } set? ] unit-test
|
{ t } [ T{ null-set } unordered-set? ] unit-test
|
||||||
{ t } [ HS{ } set? ] unit-test
|
{ t } [ HS{ } unordered-set? ] unit-test
|
||||||
{ t } [ { } set? ] unit-test
|
{ t } [ { } unordered-set? ] unit-test
|
||||||
{ t } [ 5 <bit-set> set? ] unit-test
|
{ t } [ 5 <bit-set> unordered-set? ] unit-test
|
||||||
{ f } [ H{ } set? ] unit-test
|
{ f } [ H{ } unordered-set? ] unit-test
|
||||||
|
|
||||||
{ HS{ } } [ HS{ } [ clear-set ] keep ] unit-test
|
{ HS{ } } [ HS{ } [ clear-set ] keep ] unit-test
|
||||||
{ HS{ } } [ HS{ 1 2 3 } [ clear-set ] keep ] unit-test
|
{ HS{ } } [ HS{ 1 2 3 } [ clear-set ] keep ] unit-test
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
USING: assocs hashtables kernel math sequences vectors ;
|
USING: assocs hashtables kernel math sequences vectors ;
|
||||||
IN: sets
|
IN: sets
|
||||||
|
|
||||||
! Set protocol
|
! unordered-set protocol
|
||||||
MIXIN: set
|
! The word name ``set`` is for dynamic variables.
|
||||||
|
MIXIN: unordered-set
|
||||||
GENERIC: adjoin ( elt set -- )
|
GENERIC: adjoin ( elt set -- )
|
||||||
GENERIC: ?adjoin ( elt set -- ? )
|
GENERIC: ?adjoin ( elt set -- ? )
|
||||||
GENERIC: in? ( elt set -- ? )
|
GENERIC: in? ( elt set -- ? )
|
||||||
|
@ -35,15 +36,15 @@ M: f clear-set drop ; inline
|
||||||
! Defaults for some methods.
|
! Defaults for some methods.
|
||||||
! Override them for efficiency
|
! Override them for efficiency
|
||||||
|
|
||||||
M: set ?adjoin 2dup in? [ 2drop f ] [ adjoin t ] if ;
|
M: unordered-set ?adjoin 2dup in? [ 2drop f ] [ adjoin t ] if ;
|
||||||
|
|
||||||
M: set null? members null? ; inline
|
M: unordered-set null? members null? ; inline
|
||||||
|
|
||||||
M: set cardinality members length ;
|
M: unordered-set cardinality members length ;
|
||||||
|
|
||||||
M: set clear-set [ members ] keep [ delete ] curry each ;
|
M: unordered-set clear-set [ members ] keep [ delete ] curry each ;
|
||||||
|
|
||||||
M: set set-like drop ; inline
|
M: unordered-set set-like drop ; inline
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ M: set set-like drop ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
M: set union [ (union) ] keep set-like ;
|
M: unordered-set union [ (union) ] keep set-like ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
@ -76,11 +77,11 @@ M: set union [ (union) ] keep set-like ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
M: set intersect [ (intersect) ] keep set-like ;
|
M: unordered-set intersect [ (intersect) ] keep set-like ;
|
||||||
|
|
||||||
M: set diff [ (diff) ] keep set-like ;
|
M: unordered-set diff [ (diff) ] keep set-like ;
|
||||||
|
|
||||||
M: set intersects?
|
M: unordered-set intersects?
|
||||||
small/large sequence/tester any? ;
|
small/large sequence/tester any? ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -90,17 +91,17 @@ M: set intersects?
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
M: set subset?
|
M: unordered-set subset?
|
||||||
2dup [ cardinality ] bi@ > [ 2drop f ] [ (subset?) ] if ;
|
2dup [ cardinality ] bi@ > [ 2drop f ] [ (subset?) ] if ;
|
||||||
|
|
||||||
M: set set=
|
M: unordered-set set=
|
||||||
2dup [ cardinality ] bi@ eq? [ (subset?) ] [ 2drop f ] if ;
|
2dup [ cardinality ] bi@ eq? [ (subset?) ] [ 2drop f ] if ;
|
||||||
|
|
||||||
M: set fast-set ;
|
M: unordered-set fast-set ;
|
||||||
|
|
||||||
M: set duplicates drop f ;
|
M: unordered-set duplicates drop f ;
|
||||||
|
|
||||||
M: set all-unique? drop t ;
|
M: unordered-set all-unique? drop t ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ M: set all-unique? drop t ;
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
! Sequences are sets
|
! Sequences are sets
|
||||||
INSTANCE: sequence set
|
INSTANCE: sequence unordered-set
|
||||||
|
|
||||||
M: sequence in?
|
M: sequence in?
|
||||||
member? ; inline
|
member? ; inline
|
||||||
|
|
|
@ -7,7 +7,6 @@ hashtables hashtables.identity io.encodings.string
|
||||||
io.encodings.utf8 kernel libc linked-assocs locals make math
|
io.encodings.utf8 kernel libc linked-assocs locals make math
|
||||||
math.parser namespaces sequences sets strings yaml.config
|
math.parser namespaces sequences sets strings yaml.config
|
||||||
yaml.conversion yaml.ffi hash-sets.identity ;
|
yaml.conversion yaml.ffi hash-sets.identity ;
|
||||||
FROM: sets => set ;
|
|
||||||
IN: yaml
|
IN: yaml
|
||||||
|
|
||||||
ERROR: libyaml-parser-error
|
ERROR: libyaml-parser-error
|
||||||
|
@ -204,7 +203,7 @@ M: yaml-alias (deref-aliases) anchor>> of ;
|
||||||
M: sequence (deref-aliases)
|
M: sequence (deref-aliases)
|
||||||
[ (deref-aliases) ] with map! ;
|
[ (deref-aliases) ] with map! ;
|
||||||
|
|
||||||
M: set (deref-aliases)
|
M: unordered-set (deref-aliases)
|
||||||
[ members (deref-aliases) ] [ clear-set ] [ swap union! ] tri ;
|
[ members (deref-aliases) ] [ clear-set ] [ swap union! ] tri ;
|
||||||
|
|
||||||
: assoc-map! ( assoc quot -- assoc' )
|
: assoc-map! ( assoc quot -- assoc' )
|
||||||
|
@ -333,7 +332,7 @@ M: string (replace-aliases) nip ;
|
||||||
M: sequence (replace-aliases)
|
M: sequence (replace-aliases)
|
||||||
[ ?replace-aliases ] with map ;
|
[ ?replace-aliases ] with map ;
|
||||||
|
|
||||||
M: set (replace-aliases)
|
M: unordered-set (replace-aliases)
|
||||||
[ members (replace-aliases) ] keep set-like ;
|
[ members (replace-aliases) ] keep set-like ;
|
||||||
|
|
||||||
M: assoc (replace-aliases)
|
M: assoc (replace-aliases)
|
||||||
|
@ -362,7 +361,7 @@ M: string (replace-anchors) nip ;
|
||||||
M: sequence (replace-anchors)
|
M: sequence (replace-anchors)
|
||||||
[ ?replace-anchors ] with map ;
|
[ ?replace-anchors ] with map ;
|
||||||
|
|
||||||
M: set (replace-anchors)
|
M: unordered-set (replace-anchors)
|
||||||
[ members ?replace-anchors ] keep set-like ;
|
[ members ?replace-anchors ] keep set-like ;
|
||||||
|
|
||||||
M: assoc (replace-anchors)
|
M: assoc (replace-anchors)
|
||||||
|
@ -470,7 +469,7 @@ M: assoc emit-value ( emitter event anchor assoc -- )
|
||||||
[ nip emit-assoc-body ]
|
[ nip emit-assoc-body ]
|
||||||
[ 2drop emit-assoc-end ] 4tri ;
|
[ 2drop emit-assoc-end ] 4tri ;
|
||||||
|
|
||||||
M: set emit-value ( emitter event anchor set -- )
|
M: unordered-set emit-value ( emitter event anchor set -- )
|
||||||
[ drop YAML_SET_TAG f emit-assoc-start ]
|
[ drop YAML_SET_TAG f emit-assoc-start ]
|
||||||
[ nip emit-set-body ]
|
[ nip emit-set-body ]
|
||||||
[ 2drop emit-assoc-end ] 4tri ;
|
[ 2drop emit-assoc-end ] 4tri ;
|
||||||
|
|
Loading…
Reference in New Issue