From d75c61d1c9d6b709dff9760ffdfba1b80098f908 Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Thu, 2 Sep 2010 03:53:19 +0200 Subject: [PATCH] [Set] implemented .symmetricdifference and (^) --- src/core/Set.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/Set.pm b/src/core/Set.pm index 0b3adfb9b7f..9cbb5dfdfc5 100644 --- a/src/core/Set.pm +++ b/src/core/Set.pm @@ -54,6 +54,13 @@ class Set does Associative { self.new(grep { !contains(@otherset, $_) }, @!elems); } + multi method symmetricdifference(%otherset) { + self.symmetricdifference(%otherset.keys); + } + multi method symmetricdifference(@otherset) { + self.difference(@otherset).union(Set.new(@otherset).difference(self)); + } + multi method subsetorequal(@otherset) { ?contains(@otherset, all(@!elems)); } @@ -100,6 +107,11 @@ our multi sub infix:<(-)>( %a, %b) { Set.new( %a).difference(%b) } our multi sub infix:<(-)>( @a, %b) { Set.new(|@a).difference(%b) } our multi sub infix:<(-)>( @a, @b) { Set.new(|@a).difference(@b) } +our multi sub infix:<(^)>(Set $a, %b) { $a.symmetricdifference(%b) } +our multi sub infix:<(^)>( %a, %b) { Set.new( %a).symmetricdifference(%b) } +our multi sub infix:<(^)>( @a, %b) { Set.new(|@a).symmetricdifference(%b) } +our multi sub infix:<(^)>( @a, @b) { Set.new(|@a).symmetricdifference(@b) } + our multi sub infix:<(<=)>(Set $a, %b) { $a.subsetorequal(%b) } our multi sub infix:<(<=)>( %a, %b) { Set.new( %a).subsetorequal(%b) } our multi sub infix:<(<=)>( @a, %b) { Set.new(|@a).subsetorequal(%b) }