Permalink
Browse files

sets: minor improvements to sequence-as-sets.

  • Loading branch information...
1 parent 11464e1 commit d4af92f93307338ccde5fe91b7c35a324d814ea5 @mrjbq7 mrjbq7 committed Aug 24, 2012
Showing with 16 additions and 6 deletions.
  1. +3 −3 core/hash-sets/hash-sets.factor
  2. +13 −3 core/sets/sets.factor
@@ -19,19 +19,19 @@ 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: hash-set intersect small/large sequence/tester filter >hash-set ;
-M: hash-set union [ members ] bi@ append >hash-set ;
+M: hash-set union (union) >hash-set ;
M: hash-set diff sequence/tester [ not ] compose filter >hash-set ;
M: sequence fast-set >hash-set ;
M: f fast-set drop H{ } clone hash-set boa ;
M: sequence duplicates
- f fast-set [ ?adjoin not ] curry filter ;
+ dup length <hash-set> [ ?adjoin not ] curry filter ;
<PRIVATE
View
@@ -34,8 +34,18 @@ M: set cardinality members length ;
M: set set-like drop ; inline
+<PRIVATE
+
+: ?members ( set -- seq )
+ dup sequence? [ members ] unless ; inline
+
+: (union) ( set1 set2 -- seq )
+ [ ?members ] bi@ append ; inline
+
+PRIVATE>
+
M: set union
- [ [ members ] bi@ append ] keep set-like ;
+ [ (union) ] keep set-like ;
<PRIVATE
@@ -113,11 +123,11 @@ M: sequence null?
empty? ; inline
M: sequence cardinality
- pruned length ;
+ fast-set cardinality ;
: combine ( sets -- set/f )
[ f ]
- [ [ [ members ] map concat ] [ first ] bi set-like ]
+ [ [ [ ?members ] map concat ] [ first ] bi set-like ]
if-empty ;
: gather ( ... seq quot: ( ... elt -- ... elt' ) -- ... newseq )

0 comments on commit d4af92f

Please sign in to comment.