diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2014-07-16 18:11:40 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2014-07-16 18:11:40 -0400 |
| commit | ace3a77f7407690f725ee50f3f42f26a95ed6835 (patch) | |
| tree | 02d3748782eeca9789a5dd5f85bbf724dcaa6543 | |
| parent | 61e84a5dcaf923ee4f8c98e8b7911650cf215f54 (diff) | |
| download | rust-ace3a77f7407690f725ee50f3f42f26a95ed6835.tar.gz rust-ace3a77f7407690f725ee50f3f42f26a95ed6835.zip | |
Add TreeSet example.
| -rw-r--r-- | src/libcollections/treemap.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index 3d4973373e2..c2211d08bfa 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -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, ()> |
