]> gitweb.factorcode.org Git - factor.git/commitdiff
hash-sets: slightly faster filter-members.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 27 Mar 2013 00:24:38 +0000 (17:24 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 27 Mar 2013 00:42:41 +0000 (17:42 -0700)
core/hash-sets/hash-sets.factor

index 2d79b9068d8c47fc3c5170eb1de947202fa8e479..67d9ada30706152e26ddacd60bf0003bd8cf3a87 100644 (file)
@@ -147,12 +147,18 @@ INSTANCE: hash-set set
 : array/tester ( hash-set1 hash-set2 -- array quot )
     [ array>> ] dip [ in? ] curry ; inline
 
+: filter-members ( hash-set array quot: ( elt -- ? ) -- accum )
+    [ dup ] prepose rot cardinality <vector> [
+        [ push-unsafe ] curry [ [ drop ] if ] curry
+        compose each
+    ] keep ; inline
+
 PRIVATE>
 
 M: hash-set intersect
     over hash-set? [
-        small/large array/tester not-tombstones
-        filter >hash-set
+        small/large dupd array/tester not-tombstones
+        filter-members >hash-set
     ] [ (intersect) >hash-set ] if ;
 
 M: hash-set intersects?
@@ -168,8 +174,8 @@ M: hash-set union
 
 M: hash-set diff
     over hash-set? [
-        array/tester [ not ] compose not-tombstones
-        filter >hash-set
+        dupd array/tester [ not ] compose not-tombstones
+        filter-members >hash-set
     ] [ (diff) >hash-set ] if ;
 
 M: hash-set subset?