libcollections: convert TrieSet
binops to by value
This commit is contained in:
parent
dff2b395d2
commit
308460400b
@ -462,6 +462,8 @@ impl Extend<uint> for TrieSet {
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(stage0): Remove impl after a snapshot
|
||||
#[cfg(stage0)]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
impl BitOr<TrieSet, TrieSet> for TrieSet {
|
||||
/// Returns the union of `self` and `rhs` as a new `TrieSet`.
|
||||
@ -483,6 +485,30 @@ impl BitOr<TrieSet, TrieSet> for TrieSet {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
impl<'a, 'b> BitOr<&'b TrieSet, TrieSet> for &'a TrieSet {
|
||||
/// Returns the union of `self` and `rhs` as a new `TrieSet`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TrieSet;
|
||||
///
|
||||
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: TrieSet = vec![3, 4, 5].into_iter().collect();
|
||||
///
|
||||
/// let set: TrieSet = &a | &b;
|
||||
/// let v: Vec<uint> = set.iter().collect();
|
||||
/// assert_eq!(v, vec![1u, 2, 3, 4, 5]);
|
||||
/// ```
|
||||
fn bitor(self, rhs: &TrieSet) -> TrieSet {
|
||||
self.union(rhs).collect()
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(stage0): Remove impl after a snapshot
|
||||
#[cfg(stage0)]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
impl BitAnd<TrieSet, TrieSet> for TrieSet {
|
||||
/// Returns the intersection of `self` and `rhs` as a new `TrieSet`.
|
||||
@ -504,6 +530,30 @@ impl BitAnd<TrieSet, TrieSet> for TrieSet {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
impl<'a, 'b> BitAnd<&'b TrieSet, TrieSet> for &'a TrieSet {
|
||||
/// Returns the intersection of `self` and `rhs` as a new `TrieSet`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TrieSet;
|
||||
///
|
||||
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: TrieSet = vec![2, 3, 4].into_iter().collect();
|
||||
///
|
||||
/// let set: TrieSet = &a & &b;
|
||||
/// let v: Vec<uint> = set.iter().collect();
|
||||
/// assert_eq!(v, vec![2u, 3]);
|
||||
/// ```
|
||||
fn bitand(self, rhs: &TrieSet) -> TrieSet {
|
||||
self.intersection(rhs).collect()
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(stage0): Remove impl after a snapshot
|
||||
#[cfg(stage0)]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
impl BitXor<TrieSet, TrieSet> for TrieSet {
|
||||
/// Returns the symmetric difference of `self` and `rhs` as a new `TrieSet`.
|
||||
@ -525,6 +575,30 @@ impl BitXor<TrieSet, TrieSet> for TrieSet {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
impl<'a, 'b> BitXor<&'b TrieSet, TrieSet> for &'a TrieSet {
|
||||
/// Returns the symmetric difference of `self` and `rhs` as a new `TrieSet`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TrieSet;
|
||||
///
|
||||
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: TrieSet = vec![3, 4, 5].into_iter().collect();
|
||||
///
|
||||
/// let set: TrieSet = &a ^ &b;
|
||||
/// let v: Vec<uint> = set.iter().collect();
|
||||
/// assert_eq!(v, vec![1u, 2, 4, 5]);
|
||||
/// ```
|
||||
fn bitxor(self, rhs: &TrieSet) -> TrieSet {
|
||||
self.symmetric_difference(rhs).collect()
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(stage0): Remove impl after a snapshot
|
||||
#[cfg(stage0)]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
impl Sub<TrieSet, TrieSet> for TrieSet {
|
||||
/// Returns the difference of `self` and `rhs` as a new `TrieSet`.
|
||||
@ -546,6 +620,28 @@ impl Sub<TrieSet, TrieSet> for TrieSet {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
impl<'a, 'b> Sub<&'b TrieSet, TrieSet> for &'a TrieSet {
|
||||
/// Returns the difference of `self` and `rhs` as a new `TrieSet`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TrieSet;
|
||||
///
|
||||
/// let a: TrieSet = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: TrieSet = vec![3, 4, 5].into_iter().collect();
|
||||
///
|
||||
/// let set: TrieSet = &a - &b;
|
||||
/// let v: Vec<uint> = set.iter().collect();
|
||||
/// assert_eq!(v, vec![1u, 2]);
|
||||
/// ```
|
||||
fn sub(self, rhs: &TrieSet) -> TrieSet {
|
||||
self.difference(rhs).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// A forward iterator over a set.
|
||||
pub struct SetItems<'a> {
|
||||
iter: Entries<'a, ()>
|
||||
@ -837,7 +933,7 @@ mod test {
|
||||
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
|
||||
let b: TrieSet = vec![3, 4, 5].into_iter().collect();
|
||||
|
||||
let set: TrieSet = a | b;
|
||||
let set: TrieSet = &a | &b;
|
||||
let v: Vec<uint> = set.iter().collect();
|
||||
assert_eq!(v, vec![1u, 2, 3, 4, 5]);
|
||||
}
|
||||
@ -847,7 +943,7 @@ mod test {
|
||||
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
|
||||
let b: TrieSet = vec![2, 3, 4].into_iter().collect();
|
||||
|
||||
let set: TrieSet = a & b;
|
||||
let set: TrieSet = &a & &b;
|
||||
let v: Vec<uint> = set.iter().collect();
|
||||
assert_eq!(v, vec![2u, 3]);
|
||||
}
|
||||
@ -857,7 +953,7 @@ mod test {
|
||||
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
|
||||
let b: TrieSet = vec![3, 4, 5].into_iter().collect();
|
||||
|
||||
let set: TrieSet = a ^ b;
|
||||
let set: TrieSet = &a ^ &b;
|
||||
let v: Vec<uint> = set.iter().collect();
|
||||
assert_eq!(v, vec![1u, 2, 4, 5]);
|
||||
}
|
||||
@ -867,7 +963,7 @@ mod test {
|
||||
let a: TrieSet = vec![1, 2, 3].into_iter().collect();
|
||||
let b: TrieSet = vec![3, 4, 5].into_iter().collect();
|
||||
|
||||
let set: TrieSet = a - b;
|
||||
let set: TrieSet = &a - &b;
|
||||
let v: Vec<uint> = set.iter().collect();
|
||||
assert_eq!(v, vec![1u, 2]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user