File tree Expand file tree Collapse file tree 4 files changed +102
-0
lines changed Expand file tree Collapse file tree 4 files changed +102
-0
lines changed Original file line number Diff line number Diff line change @@ -1131,6 +1131,32 @@ where
1131
1131
out. union ( self )
1132
1132
}
1133
1133
1134
+ /// Construct the relative complement between two maps by discarding keys
1135
+ /// which occur in `other`.
1136
+ ///
1137
+ /// Time: O(m log n) where m is the size of the other map
1138
+ ///
1139
+ /// # Examples
1140
+ ///
1141
+ /// ```
1142
+ /// # #[macro_use] extern crate im;
1143
+ /// # use im::ordmap::OrdMap;
1144
+ /// # fn main() {
1145
+ /// let map1 = ordmap!{1 => 1, 3 => 4};
1146
+ /// let map2 = ordmap!{2 => 2, 3 => 5};
1147
+ /// let expected = ordmap!{1 => 1, 2 => 2};
1148
+ /// assert_eq!(expected, map1.relative_complement(map2));
1149
+ /// # }
1150
+ /// ```
1151
+ #[ inline]
1152
+ #[ must_use]
1153
+ pub fn relative_complement ( mut self , other : Self ) -> Self {
1154
+ for ( key, _) in other {
1155
+ let _ = self . remove ( & key) ;
1156
+ }
1157
+ self
1158
+ }
1159
+
1134
1160
/// Construct the intersection of two maps, keeping the values
1135
1161
/// from the current map.
1136
1162
///
Original file line number Diff line number Diff line change @@ -537,6 +537,31 @@ where
537
537
self
538
538
}
539
539
540
+ /// Construct the relative complement between two sets, that is the set
541
+ /// of values in `self` that do not occur in `other`.
542
+ ///
543
+ /// Time: O(m log n) where m is the size of the other set
544
+ ///
545
+ /// # Examples
546
+ ///
547
+ /// ```
548
+ /// # #[macro_use] extern crate im;
549
+ /// # use im::ordset::OrdSet;
550
+ /// # fn main() {
551
+ /// let set1 = ordset!{1, 2};
552
+ /// let set2 = ordset!{2, 3};
553
+ /// let expected = ordset!{1};
554
+ /// assert_eq!(expected, set1.relative_complement(set2));
555
+ /// # }
556
+ /// ```
557
+ #[ must_use]
558
+ pub fn relative_complement ( mut self , other : Self ) -> Self {
559
+ for value in other {
560
+ let _ = self . remove ( & value) ;
561
+ }
562
+ self
563
+ }
564
+
540
565
/// Construct the intersection of two sets.
541
566
///
542
567
/// Time: O(n log n)
Original file line number Diff line number Diff line change @@ -1095,6 +1095,32 @@ where
1095
1095
out. union ( self )
1096
1096
}
1097
1097
1098
+ /// Construct the relative complement between two maps by discarding keys
1099
+ /// which occur in `other`.
1100
+ ///
1101
+ /// Time: O(m log n) where m is the size of the other map
1102
+ ///
1103
+ /// # Examples
1104
+ ///
1105
+ /// ```
1106
+ /// # #[macro_use] extern crate im;
1107
+ /// # use im::ordmap::OrdMap;
1108
+ /// # fn main() {
1109
+ /// let map1 = ordmap!{1 => 1, 3 => 4};
1110
+ /// let map2 = ordmap!{2 => 2, 3 => 5};
1111
+ /// let expected = ordmap!{1 => 1, 2 => 2};
1112
+ /// assert_eq!(expected, map1.relative_complement(map2));
1113
+ /// # }
1114
+ /// ```
1115
+ #[ inline]
1116
+ #[ must_use]
1117
+ pub fn relative_complement ( mut self , other : Self ) -> Self {
1118
+ for ( key, _) in other {
1119
+ let _ = self . remove ( & key) ;
1120
+ }
1121
+ self
1122
+ }
1123
+
1098
1124
/// Construct the intersection of two maps, keeping the values
1099
1125
/// from the current map.
1100
1126
///
Original file line number Diff line number Diff line change @@ -637,6 +637,31 @@ where
637
637
self
638
638
}
639
639
640
+ /// Construct the relative complement between two sets, that is the set
641
+ /// of values in `self` that do not occur in `other`.
642
+ ///
643
+ /// Time: O(m log n) where m is the size of the other set
644
+ ///
645
+ /// # Examples
646
+ ///
647
+ /// ```
648
+ /// # #[macro_use] extern crate im;
649
+ /// # use im::ordset::OrdSet;
650
+ /// # fn main() {
651
+ /// let set1 = ordset!{1, 2};
652
+ /// let set2 = ordset!{2, 3};
653
+ /// let expected = ordset!{1};
654
+ /// assert_eq!(expected, set1.relative_complement(set2));
655
+ /// # }
656
+ /// ```
657
+ #[ must_use]
658
+ pub fn relative_complement ( mut self , other : Self ) -> Self {
659
+ for value in other {
660
+ let _ = self . remove ( & value) ;
661
+ }
662
+ self
663
+ }
664
+
640
665
/// Construct the intersection of two sets.
641
666
///
642
667
/// Time: O(n log n)
You can’t perform that action at this time.
0 commit comments