From daaf0904596d3f28f07f6273a9a1548f9b8b5a14 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 26 Mar 2013 16:24:45 -0700 Subject: [PATCH] hash-sets: faster intersect and diff, when both are hash-sets. --- core/hash-sets/hash-sets.factor | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/hash-sets/hash-sets.factor b/core/hash-sets/hash-sets.factor index 9c40b4c2a2..2d79b9068d 100644 --- a/core/hash-sets/hash-sets.factor +++ b/core/hash-sets/hash-sets.factor @@ -149,7 +149,11 @@ INSTANCE: hash-set set PRIVATE> -M: hash-set intersect (intersect) >hash-set ; +M: hash-set intersect + over hash-set? [ + small/large array/tester not-tombstones + filter >hash-set + ] [ (intersect) >hash-set ] if ; M: hash-set intersects? over hash-set? [ @@ -160,11 +164,13 @@ M: hash-set union over hash-set? [ small/large [ array>> ] [ clone ] bi* [ [ adjoin ] curry each-member ] keep - ] [ - (union) >hash-set - ] if ; + ] [ (union) >hash-set ] if ; -M: hash-set diff (diff) >hash-set ; +M: hash-set diff + over hash-set? [ + array/tester [ not ] compose not-tombstones + filter >hash-set + ] [ (diff) >hash-set ] if ; M: hash-set subset? over hash-set? [