提交 26047f15 编写于 作者: J Jonas Hietala 提交者: Alex Crichton

Move intersection above difference and symmetric_differance.

So all comes in the order union, intersection, difference and
symmetric_difference.
上级 b05f6050
......@@ -1124,8 +1124,8 @@ pub fn union<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
}
}
/// Iterator over each uint stored in the `self` setminus `other`.
/// See [difference_with](#method.difference_with) for an efficient in-place version.
/// Iterator over each uint stored in `self` intersect `other`.
/// See [intersect_with](#method.intersect_with) for an efficient in-place version.
///
/// # Example
///
......@@ -1136,32 +1136,25 @@ pub fn union<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
///
/// // Print 2, 4 in arbitrary order
/// for x in a.difference(&b) {
/// println!("{}", x);
/// }
///
/// // Note that difference is not symmetric,
/// // and `b - a` means something else.
/// // This prints 0
/// for x in b.difference(&a) {
/// // Print 2
/// for x in a.intersection(&b) {
/// println!("{}", x);
/// }
/// ```
#[inline]
pub fn difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Take<TwoBitPositions<'a>> {
let min = cmp::min(self.capacity(), other.capacity());
TwoBitPositions {
set: self,
other: other,
merge: |w1, w2| w1 & !w2,
merge: |w1, w2| w1 & w2,
current_word: 0,
next_idx: 0
}
}.take(min)
}
/// Iterator over each uint stored in the symmetric difference of `self` and `other`.
/// See [symmetric_difference_with](#method.symmetric_difference_with) for
/// an efficient in-place version.
/// Iterator over each uint stored in the `self` setminus `other`.
/// See [difference_with](#method.difference_with) for an efficient in-place version.
///
/// # Example
///
......@@ -1172,24 +1165,32 @@ pub fn difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
///
/// // Print 0, 1, 4 in arbitrary order
/// for x in a.symmetric_difference(&b) {
/// // Print 2, 4 in arbitrary order
/// for x in a.difference(&b) {
/// println!("{}", x);
/// }
///
/// // Note that difference is not symmetric,
/// // and `b - a` means something else.
/// // This prints 0
/// for x in b.difference(&a) {
/// println!("{}", x);
/// }
/// ```
#[inline]
pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
pub fn difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
TwoBitPositions {
set: self,
other: other,
merge: |w1, w2| w1 ^ w2,
merge: |w1, w2| w1 & !w2,
current_word: 0,
next_idx: 0
}
}
/// Iterator over each uint stored in `self` intersect `other`.
/// See [intersect_with](#method.intersect_with) for an efficient in-place version.
/// Iterator over each uint stored in the symmetric difference of `self` and `other`.
/// See [symmetric_difference_with](#method.symmetric_difference_with) for
/// an efficient in-place version.
///
/// # Example
///
......@@ -1200,21 +1201,20 @@ pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
///
/// // Print 2
/// for x in a.intersection(&b) {
/// // Print 0, 1, 4 in arbitrary order
/// for x in a.symmetric_difference(&b) {
/// println!("{}", x);
/// }
/// ```
#[inline]
pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Take<TwoBitPositions<'a>> {
let min = cmp::min(self.capacity(), other.capacity());
pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
TwoBitPositions {
set: self,
other: other,
merge: |w1, w2| w1 & w2,
merge: |w1, w2| w1 ^ w2,
current_word: 0,
next_idx: 0
}.take(min)
}
}
/// Union in-place with the specified other bit vector.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册