Browse files

Reimplement set intersection

This can probably be done better, but this at least works.
  • Loading branch information...
1 parent 1040c9c commit 9b4d4e1e0f1df09badaf232506f16957a294caa6 @lizmat lizmat committed Sep 9, 2013
Showing with 13 additions and 5 deletions.
  1. +13 −5 src/core/Setty.pm
View
18 src/core/Setty.pm
@@ -146,14 +146,22 @@ only sub infix:<<"\x222A">>(|p) {
}
only sub infix:<(&)>(**@p) {
- my $base_set = @p ?? @p[0].Set !! set();
if @p.grep(Baggy) {
- my @bags = @p.map(*.Bag);
- Bag.new-fp($base_set.map({ ; $_ => [min] @bags>>.{$_} }));
+ my $keybag = @p ?? @p.shift.KeyBag !! KeyBag.new;
+ for @p.map(*.Bag) -> $bag {
+ $bag{$_}
+ ?? $keybag{$_} min= $bag{$_}
+ !! $keybag.delete($_)
+ for $keybag.keys;
+ }
+ Bag.new-fp($keybag.pairs);
}
else {
- my @sets = @p.map(*.Set);
- Set.new($base_set.grep: -> $k { @sets>>.{$k}.all });
+ my $keyset = @p ?? @p.shift.KeySet !! KeySet.new;
+ for @p.map(*.Set) -> $set {
+ $set{$_} || $keyset.delete($_) for $keyset.keys;
+ }
+ Set.new($keyset.keys);
}
}
# U+2229 INTERSECTION

0 comments on commit 9b4d4e1

Please sign in to comment.