Skip to content

Commit 7babcde

Browse files
committed
Move intersection above difference and symmetric_differance.
So all comes in the order union, intersection, difference and symmetric_difference.
1 parent b4febd4 commit 7babcde

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/libcollections/bitv.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,8 @@ impl BitvSet {
11241124
}
11251125
}
11261126

1127-
/// Iterator over each uint stored in the `self` setminus `other`.
1128-
/// See [difference_with](#method.difference_with) for an efficient in-place version.
1127+
/// Iterator over each uint stored in `self` intersect `other`.
1128+
/// See [intersect_with](#method.intersect_with) for an efficient in-place version.
11291129
///
11301130
/// # Example
11311131
///
@@ -1136,32 +1136,25 @@ impl BitvSet {
11361136
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
11371137
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
11381138
///
1139-
/// // Print 2, 4 in arbitrary order
1140-
/// for x in a.difference(&b) {
1141-
/// println!("{}", x);
1142-
/// }
1143-
///
1144-
/// // Note that difference is not symmetric,
1145-
/// // and `b - a` means something else.
1146-
/// // This prints 0
1147-
/// for x in b.difference(&a) {
1139+
/// // Print 2
1140+
/// for x in a.intersection(&b) {
11481141
/// println!("{}", x);
11491142
/// }
11501143
/// ```
11511144
#[inline]
1152-
pub fn difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
1145+
pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Take<TwoBitPositions<'a>> {
1146+
let min = cmp::min(self.capacity(), other.capacity());
11531147
TwoBitPositions {
11541148
set: self,
11551149
other: other,
1156-
merge: |w1, w2| w1 & !w2,
1150+
merge: |w1, w2| w1 & w2,
11571151
current_word: 0,
11581152
next_idx: 0
1159-
}
1153+
}.take(min)
11601154
}
11611155

1162-
/// Iterator over each uint stored in the symmetric difference of `self` and `other`.
1163-
/// See [symmetric_difference_with](#method.symmetric_difference_with) for
1164-
/// an efficient in-place version.
1156+
/// Iterator over each uint stored in the `self` setminus `other`.
1157+
/// See [difference_with](#method.difference_with) for an efficient in-place version.
11651158
///
11661159
/// # Example
11671160
///
@@ -1172,24 +1165,32 @@ impl BitvSet {
11721165
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
11731166
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
11741167
///
1175-
/// // Print 0, 1, 4 in arbitrary order
1176-
/// for x in a.symmetric_difference(&b) {
1168+
/// // Print 2, 4 in arbitrary order
1169+
/// for x in a.difference(&b) {
1170+
/// println!("{}", x);
1171+
/// }
1172+
///
1173+
/// // Note that difference is not symmetric,
1174+
/// // and `b - a` means something else.
1175+
/// // This prints 0
1176+
/// for x in b.difference(&a) {
11771177
/// println!("{}", x);
11781178
/// }
11791179
/// ```
11801180
#[inline]
1181-
pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
1181+
pub fn difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
11821182
TwoBitPositions {
11831183
set: self,
11841184
other: other,
1185-
merge: |w1, w2| w1 ^ w2,
1185+
merge: |w1, w2| w1 & !w2,
11861186
current_word: 0,
11871187
next_idx: 0
11881188
}
11891189
}
11901190

1191-
/// Iterator over each uint stored in `self` intersect `other`.
1192-
/// See [intersect_with](#method.intersect_with) for an efficient in-place version.
1191+
/// Iterator over each uint stored in the symmetric difference of `self` and `other`.
1192+
/// See [symmetric_difference_with](#method.symmetric_difference_with) for
1193+
/// an efficient in-place version.
11931194
///
11941195
/// # Example
11951196
///
@@ -1200,21 +1201,20 @@ impl BitvSet {
12001201
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
12011202
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
12021203
///
1203-
/// // Print 2
1204-
/// for x in a.intersection(&b) {
1204+
/// // Print 0, 1, 4 in arbitrary order
1205+
/// for x in a.symmetric_difference(&b) {
12051206
/// println!("{}", x);
12061207
/// }
12071208
/// ```
12081209
#[inline]
1209-
pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Take<TwoBitPositions<'a>> {
1210-
let min = cmp::min(self.capacity(), other.capacity());
1210+
pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
12111211
TwoBitPositions {
12121212
set: self,
12131213
other: other,
1214-
merge: |w1, w2| w1 & w2,
1214+
merge: |w1, w2| w1 ^ w2,
12151215
current_word: 0,
12161216
next_idx: 0
1217-
}.take(min)
1217+
}
12181218
}
12191219

12201220
/// Union in-place with the specified other bit vector.

0 commit comments

Comments
 (0)