Struct collections::BTreeSetExperimental
[-]
[+]
[src]
pub struct BTreeSet<T> {
// some fields omitted
}A set based on a B-Tree.
See BTreeMap's documentation for a detailed discussion of this collection's performance benefits and drawbacks.
Methods
impl<T: Ord> BTreeSet<T>
fn new() -> BTreeSet<T>
Makes a new BTreeSet with a reasonable choice of B.
fn with_b(b: uint) -> BTreeSet<T>
Makes a new BTreeSet with the given B.
B cannot be less than 2.
impl<T> BTreeSet<T>
fn iter<'a>(&'a self) -> Items<'a, T>
Gets an iterator over the BTreeSet's contents.
fn into_iter(self) -> MoveItems<T>
Gets an iterator for moving out the BtreeSet's contents.
impl<T: Ord> BTreeSet<T>
fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> DifferenceItems<'a, T>
Visits the values representing the difference, in ascending order.
fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>) -> SymDifferenceItems<'a, T>
Visits the values representing the symmetric difference, in ascending order.
fn intersection<'a>(&'a self, other: &'a BTreeSet<T>) -> IntersectionItems<'a, T>
Visits the values representing the intersection, in ascending order.
fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> UnionItems<'a, T>
Visits the values representing the union, in ascending order.
fn len(&self) -> uint
Return the number of elements in the set
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut v = BTreeSet::new(); assert_eq!(v.len(), 0); v.insert(1i); assert_eq!(v.len(), 1); }use std::collections::BTreeSet; let mut v = BTreeSet::new(); assert_eq!(v.len(), 0); v.insert(1i); assert_eq!(v.len(), 1);
fn is_empty(&self) -> bool
Returns true if the set contains no elements
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut v = BTreeSet::new(); assert!(v.is_empty()); v.insert(1i); assert!(!v.is_empty()); }use std::collections::BTreeSet; let mut v = BTreeSet::new(); assert!(v.is_empty()); v.insert(1i); assert!(!v.is_empty());
fn clear(&mut self)
Clears the set, removing all values.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut v = BTreeSet::new(); v.insert(1i); v.clear(); assert!(v.is_empty()); }use std::collections::BTreeSet; let mut v = BTreeSet::new(); v.insert(1i); v.clear(); assert!(v.is_empty());
fn contains(&self, value: &T) -> bool
Returns true if the set contains a value.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let set: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); assert_eq!(set.contains(&1), true); assert_eq!(set.contains(&4), false); }use std::collections::BTreeSet; let set: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); assert_eq!(set.contains(&1), true); assert_eq!(set.contains(&4), false);
fn is_disjoint(&self, other: &BTreeSet<T>) -> bool
Returns true if the set has no elements in common with other.
This is equivalent to checking for an empty intersection.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let a: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); let mut b: BTreeSet<int> = BTreeSet::new(); assert_eq!(a.is_disjoint(&b), true); b.insert(4); assert_eq!(a.is_disjoint(&b), true); b.insert(1); assert_eq!(a.is_disjoint(&b), false); }use std::collections::BTreeSet; let a: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); let mut b: BTreeSet<int> = BTreeSet::new(); assert_eq!(a.is_disjoint(&b), true); b.insert(4); assert_eq!(a.is_disjoint(&b), true); b.insert(1); assert_eq!(a.is_disjoint(&b), false);
fn is_subset(&self, other: &BTreeSet<T>) -> bool
Returns true if the set is a subset of another.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let sup: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); let mut set: BTreeSet<int> = BTreeSet::new(); assert_eq!(set.is_subset(&sup), true); set.insert(2); assert_eq!(set.is_subset(&sup), true); set.insert(4); assert_eq!(set.is_subset(&sup), false); }use std::collections::BTreeSet; let sup: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); let mut set: BTreeSet<int> = BTreeSet::new(); assert_eq!(set.is_subset(&sup), true); set.insert(2); assert_eq!(set.is_subset(&sup), true); set.insert(4); assert_eq!(set.is_subset(&sup), false);
fn is_superset(&self, other: &BTreeSet<T>) -> bool
Returns true if the set is a superset of another.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let sub: BTreeSet<int> = [1i, 2].iter().map(|&x| x).collect(); let mut set: BTreeSet<int> = BTreeSet::new(); assert_eq!(set.is_superset(&sub), false); set.insert(0); set.insert(1); assert_eq!(set.is_superset(&sub), false); set.insert(2); assert_eq!(set.is_superset(&sub), true); }use std::collections::BTreeSet; let sub: BTreeSet<int> = [1i, 2].iter().map(|&x| x).collect(); let mut set: BTreeSet<int> = BTreeSet::new(); assert_eq!(set.is_superset(&sub), false); set.insert(0); set.insert(1); assert_eq!(set.is_superset(&sub), false); set.insert(2); assert_eq!(set.is_superset(&sub), true);
fn insert(&mut self, value: T) -> bool
Adds a value to the set. Returns true if the value was not already
present in the set.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut set = BTreeSet::new(); assert_eq!(set.insert(2i), true); assert_eq!(set.insert(2i), false); assert_eq!(set.len(), 1); }use std::collections::BTreeSet; let mut set = BTreeSet::new(); assert_eq!(set.insert(2i), true); assert_eq!(set.insert(2i), false); assert_eq!(set.len(), 1);
fn remove(&mut self, value: &T) -> bool
Removes a value from the set. Returns true if the value was
present in the set.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut set = BTreeSet::new(); set.insert(2i); assert_eq!(set.remove(&2), true); assert_eq!(set.remove(&2), false); }use std::collections::BTreeSet; let mut set = BTreeSet::new(); set.insert(2i); assert_eq!(set.remove(&2), true); assert_eq!(set.remove(&2), false);
impl<T: Ord> BTreeSet<T>
fn new() -> BTreeSet<T>
Makes a new BTreeSet with a reasonable choice of B.
fn with_b(b: uint) -> BTreeSet<T>
Makes a new BTreeSet with the given B.
B cannot be less than 2.
impl<T> BTreeSet<T>
fn iter<'a>(&'a self) -> Items<'a, T>
Gets an iterator over the BTreeSet's contents.
fn into_iter(self) -> MoveItems<T>
Gets an iterator for moving out the BtreeSet's contents.
impl<T: Ord> BTreeSet<T>
fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> DifferenceItems<'a, T>
Visits the values representing the difference, in ascending order.
fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>) -> SymDifferenceItems<'a, T>
Visits the values representing the symmetric difference, in ascending order.
fn intersection<'a>(&'a self, other: &'a BTreeSet<T>) -> IntersectionItems<'a, T>
Visits the values representing the intersection, in ascending order.
fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> UnionItems<'a, T>
Visits the values representing the union, in ascending order.
fn len(&self) -> uint
Return the number of elements in the set
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut v = BTreeSet::new(); assert_eq!(v.len(), 0); v.insert(1i); assert_eq!(v.len(), 1); }use std::collections::BTreeSet; let mut v = BTreeSet::new(); assert_eq!(v.len(), 0); v.insert(1i); assert_eq!(v.len(), 1);
fn is_empty(&self) -> bool
Returns true if the set contains no elements
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut v = BTreeSet::new(); assert!(v.is_empty()); v.insert(1i); assert!(!v.is_empty()); }use std::collections::BTreeSet; let mut v = BTreeSet::new(); assert!(v.is_empty()); v.insert(1i); assert!(!v.is_empty());
fn clear(&mut self)
Clears the set, removing all values.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut v = BTreeSet::new(); v.insert(1i); v.clear(); assert!(v.is_empty()); }use std::collections::BTreeSet; let mut v = BTreeSet::new(); v.insert(1i); v.clear(); assert!(v.is_empty());
fn contains(&self, value: &T) -> bool
Returns true if the set contains a value.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let set: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); assert_eq!(set.contains(&1), true); assert_eq!(set.contains(&4), false); }use std::collections::BTreeSet; let set: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); assert_eq!(set.contains(&1), true); assert_eq!(set.contains(&4), false);
fn is_disjoint(&self, other: &BTreeSet<T>) -> bool
Returns true if the set has no elements in common with other.
This is equivalent to checking for an empty intersection.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let a: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); let mut b: BTreeSet<int> = BTreeSet::new(); assert_eq!(a.is_disjoint(&b), true); b.insert(4); assert_eq!(a.is_disjoint(&b), true); b.insert(1); assert_eq!(a.is_disjoint(&b), false); }use std::collections::BTreeSet; let a: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); let mut b: BTreeSet<int> = BTreeSet::new(); assert_eq!(a.is_disjoint(&b), true); b.insert(4); assert_eq!(a.is_disjoint(&b), true); b.insert(1); assert_eq!(a.is_disjoint(&b), false);
fn is_subset(&self, other: &BTreeSet<T>) -> bool
Returns true if the set is a subset of another.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let sup: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); let mut set: BTreeSet<int> = BTreeSet::new(); assert_eq!(set.is_subset(&sup), true); set.insert(2); assert_eq!(set.is_subset(&sup), true); set.insert(4); assert_eq!(set.is_subset(&sup), false); }use std::collections::BTreeSet; let sup: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); let mut set: BTreeSet<int> = BTreeSet::new(); assert_eq!(set.is_subset(&sup), true); set.insert(2); assert_eq!(set.is_subset(&sup), true); set.insert(4); assert_eq!(set.is_subset(&sup), false);
fn is_superset(&self, other: &BTreeSet<T>) -> bool
Returns true if the set is a superset of another.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let sub: BTreeSet<int> = [1i, 2].iter().map(|&x| x).collect(); let mut set: BTreeSet<int> = BTreeSet::new(); assert_eq!(set.is_superset(&sub), false); set.insert(0); set.insert(1); assert_eq!(set.is_superset(&sub), false); set.insert(2); assert_eq!(set.is_superset(&sub), true); }use std::collections::BTreeSet; let sub: BTreeSet<int> = [1i, 2].iter().map(|&x| x).collect(); let mut set: BTreeSet<int> = BTreeSet::new(); assert_eq!(set.is_superset(&sub), false); set.insert(0); set.insert(1); assert_eq!(set.is_superset(&sub), false); set.insert(2); assert_eq!(set.is_superset(&sub), true);
fn insert(&mut self, value: T) -> bool
Adds a value to the set. Returns true if the value was not already
present in the set.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut set = BTreeSet::new(); assert_eq!(set.insert(2i), true); assert_eq!(set.insert(2i), false); assert_eq!(set.len(), 1); }use std::collections::BTreeSet; let mut set = BTreeSet::new(); assert_eq!(set.insert(2i), true); assert_eq!(set.insert(2i), false); assert_eq!(set.len(), 1);
fn remove(&mut self, value: &T) -> bool
Removes a value from the set. Returns true if the value was
present in the set.
Example
extern crate collections; fn main() { use std::collections::BTreeSet; let mut set = BTreeSet::new(); set.insert(2i); assert_eq!(set.remove(&2), true); assert_eq!(set.remove(&2), false); }use std::collections::BTreeSet; let mut set = BTreeSet::new(); set.insert(2i); assert_eq!(set.remove(&2), true); assert_eq!(set.remove(&2), false);