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<Q>(&self, value: &Q) -> bool where Q: BorrowFrom<T> + Ord

Returns true if the set contains a value.

The value may be any borrowed form of the set's value type, but the ordering on the borrowed form must match the ordering on the value type.

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<Q>(&mut self, value: &Q) -> bool where Q: BorrowFrom<T> + Ord

Removes a value from the set. Returns true if the value was present in the set.

The value may be any borrowed form of the set's value type, but the ordering on the borrowed form must match the ordering on the value type.

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<Q>(&self, value: &Q) -> bool where Q: BorrowFrom<T> + Ord

Returns true if the set contains a value.

The value may be any borrowed form of the set's value type, but the ordering on the borrowed form must match the ordering on the value type.

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<Q>(&mut self, value: &Q) -> bool where Q: BorrowFrom<T> + Ord

Removes a value from the set. Returns true if the value was present in the set.

The value may be any borrowed form of the set's value type, but the ordering on the borrowed form must match the ordering on the value type.

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);

Trait Implementations

impl<T: Ord> FromIterator<T> for BTreeSet<T>

fn from_iter<Iter: Iterator<T>>(iter: Iter) -> BTreeSet<T>

impl<T: Ord> Extend<T> for BTreeSet<T>

fn extend<Iter: Iterator<T>>(&mut self, iter: Iter)

impl<T: Ord> Default for BTreeSet<T>

fn default() -> BTreeSet<T>

impl<T: Show> Show for BTreeSet<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: Ord> FromIterator<T> for BTreeSet<T>

fn from_iter<Iter: Iterator<T>>(iter: Iter) -> BTreeSet<T>

impl<T: Ord> Extend<T> for BTreeSet<T>

fn extend<Iter: Iterator<T>>(&mut self, iter: Iter)

impl<T: Ord> Default for BTreeSet<T>

fn default() -> BTreeSet<T>

impl<T: Show> Show for BTreeSet<T>

fn fmt(&self, f: &mut Formatter) -> Result

Derived Implementations

impl<T: PartialOrd> PartialOrd for BTreeSet<T>

fn partial_cmp(&self, __arg_0: &BTreeSet<T>) -> Option<Ordering>

fn lt(&self, __arg_0: &BTreeSet<T>) -> bool

fn le(&self, __arg_0: &BTreeSet<T>) -> bool

fn gt(&self, __arg_0: &BTreeSet<T>) -> bool

fn ge(&self, __arg_0: &BTreeSet<T>) -> bool

impl<T: Ord> Ord for BTreeSet<T>

fn cmp(&self, __arg_0: &BTreeSet<T>) -> Ordering

impl<T: Eq> Eq for BTreeSet<T>

impl<T: PartialEq> PartialEq for BTreeSet<T>

fn eq(&self, __arg_0: &BTreeSet<T>) -> bool

fn ne(&self, __arg_0: &BTreeSet<T>) -> bool

impl<__S: Writer, T: Hash<__S>> Hash<__S> for BTreeSet<T>

fn hash(&self, __arg_0: &mut __S)

impl<T: Clone> Clone for BTreeSet<T>

fn clone(&self) -> BTreeSet<T>

fn clone_from(&mut self, source: &Self)

impl<T: PartialOrd> PartialOrd for BTreeSet<T>

fn partial_cmp(&self, __arg_0: &BTreeSet<T>) -> Option<Ordering>

fn lt(&self, __arg_0: &BTreeSet<T>) -> bool

fn le(&self, __arg_0: &BTreeSet<T>) -> bool

fn gt(&self, __arg_0: &BTreeSet<T>) -> bool

fn ge(&self, __arg_0: &BTreeSet<T>) -> bool

impl<T: Ord> Ord for BTreeSet<T>

fn cmp(&self, __arg_0: &BTreeSet<T>) -> Ordering

impl<T: Eq> Eq for BTreeSet<T>

impl<T: PartialEq> PartialEq for BTreeSet<T>

fn eq(&self, __arg_0: &BTreeSet<T>) -> bool

fn ne(&self, __arg_0: &BTreeSet<T>) -> bool

impl<__S: Writer, T: Hash<__S>> Hash<__S> for BTreeSet<T>

fn hash(&self, __arg_0: &mut __S)

impl<T: Clone> Clone for BTreeSet<T>

fn clone(&self) -> BTreeSet<T>

fn clone_from(&mut self, source: &Self)