auto merge of #15668 : steveklabnik/rust/tree_set_example, r=alexcrichton

Someone asked for an example usage of this on IRC, so I tossed together the simplest one. Obviously, this isn't up to snuff, but it's better than nothing.
This commit is contained in:
bors 2014-07-17 08:01:21 +00:00
commit 9fc8394d3b
1 changed files with 32 additions and 0 deletions

View File

@ -11,6 +11,22 @@
//! An ordered map and set implemented as self-balancing binary search
//! trees. The only requirement for the types is that the key implements
//! `Ord`.
//!
//! ## Example
//!
//! ```{rust}
//! use std::collections::TreeSet;
//!
//! let mut tree_set = TreeSet::new();
//!
//! tree_set.insert(2i);
//! tree_set.insert(1i);
//! tree_set.insert(3i);
//!
//! for i in tree_set.iter() {
//! println!("{}", i) // prints 1, then 2, then 3
//! }
//! ```
use core::prelude::*;
@ -587,6 +603,22 @@ impl<'a, T> Iterator<&'a T> for RevSetItems<'a, T> {
/// A implementation of the `Set` trait on top of the `TreeMap` container. The
/// only requirement is that the type of the elements contained ascribes to the
/// `Ord` trait.
///
/// ## Example
///
/// ```{rust}
/// use std::collections::TreeSet;
///
/// let mut tree_set = TreeSet::new();
///
/// tree_set.insert(2i);
/// tree_set.insert(1i);
/// tree_set.insert(3i);
///
/// for i in tree_set.iter() {
/// println!("{}", i) // prints 1, then 2, then 3
/// }
/// ```
#[deriving(Clone)]
pub struct TreeSet<T> {
map: TreeMap<T, ()>