]> gitweb.factorcode.org Git - factor.git/commitdiff
Finishing porting sets features to new-sets
authorDaniel Ehrenberg <littledan@Macintosh-122.local>
Fri, 26 Feb 2010 18:22:56 +0000 (13:22 -0500)
committerDaniel Ehrenberg <littledan@Macintosh-122.local>
Fri, 26 Feb 2010 18:22:56 +0000 (13:22 -0500)
core/new-sets/new-sets-tests.factor
core/new-sets/new-sets.factor

index 18960f86dbc57fb2814e5c3edc690019cdff569a..b644b9a80970a018049945086e65e3e6d77cd2a0 100644 (file)
@@ -47,5 +47,7 @@ IN: new-sets.tests
 [ { 1 2 3 } ] [ { 1 2 2 3 3 } { } set-like ] unit-test
 [ { 3 2 1 } ] [ { 3 3 2 2 1 } { } set-like ] unit-test
 
-[ { 1 2 1 } ] [ { 1 2 3 2 1 2 1 } duplicates ] unit-test
+[ { 1 2 1 } ] [ { 1 2 3 2 1 2 1 } duplicates ] unit-test
 [ f ] [ HS{ 1 2 3 1 2 1 } duplicates ] unit-test
+
+[ H{ { 3 HS{ 1 2 } } } ] [ H{ } clone 1 3 pick adjoin-at 2 3 pick adjoin-at ] unit-test
index 115e0d404a425a70da5ff15e5e9ee02fc69ac3c0..bc4e720c9cfa2d4ddd24973402e4e8452bb1625c 100644 (file)
@@ -61,12 +61,12 @@ M: set all-unique? drop t ;
 <PRIVATE
 
 : (prune) ( elt hash vec -- )
-    3dup drop key? [ 3drop ] [
-        [ drop dupd set-at ] [ nip push ] 3bi
+    3dup drop in? [ 3drop ] [
+        [ drop adjoin ] [ nip push ] 3bi
     ] if ; inline
 
 : prune ( seq -- newseq )
-    [ ] [ length <hashtable> ] [ length <vector> ] tri
+    [ f fast-set ] [ length <vector> ] bi
     [ [ (prune) ] 2curry each ] keep ;
 
 PRIVATE>
@@ -98,3 +98,9 @@ USE: vocabs.loader
 
 : combine ( sets -- set )
     f [ union ] reduce ;
+
+: gather ( seq quot -- newseq )
+    map concat members ; inline
+
+: adjoin-at ( value key assoc -- )
+    [ [ f fast-set ] unless* [ adjoin ] keep ] change-at ;