-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs for SmallIntMap, TreeMap, TreeSet, TrieMap and TrieSet #12953
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,26 @@ use std::ptr; | |
// * union: | | ||
// These would be convenient since the methods work like `each` | ||
|
||
#[allow(missing_doc)] | ||
/// An ordered map implementation. | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust | ||
/// use collections::TreeMap; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example doesn't compile:
(and that's after I fixed the I think the |
||
/// | ||
/// let mut artists = TreeMap::new::<uint, ~str>(); | ||
/// | ||
/// // Add some elements to the map. | ||
/// artists.insert(1972, ~"ABBA"); | ||
/// artists.insert(1979, ~"Europe"); | ||
/// artists.insert(1986, ~"Roxette"); | ||
/// artists.insert(1992, ~"The Cardigans"); | ||
/// | ||
/// // Iterate over all values greater than a certain value. | ||
/// for (year, artist) in artists.upper_bound(1980) { | ||
/// println!("{} => {}", year, aritst); | ||
/// } | ||
/// ``` | ||
#[deriving(Clone)] | ||
pub struct TreeMap<K, V> { | ||
priv root: Option<~TreeNode<K, V>>, | ||
|
@@ -549,6 +568,33 @@ 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 | ||
/// `TotalOrd` trait. | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust | ||
/// use collections::TreeSet; | ||
/// | ||
/// let mut vecs = TreeSet::new(); | ||
/// | ||
/// // Add some elements to the set. | ||
/// vecs.insert(vec!(1, 2, 3)); | ||
/// vecs.insert(vec!(4, 5)); | ||
/// vecs.insert(vec!(6, 7, 8, 9)); | ||
/// vecs.insert(vec!(10, 11)); | ||
/// | ||
/// // Remove an element. | ||
/// vecs.remove(vec!(4, 5)); | ||
/// | ||
/// // Intersect with another set. | ||
/// let intersection = vecs.intersection( | ||
/// vec!(vec!(1, 2), vec!(6, 7, 8, 9), vec!(10, 11)).iter().collect() | ||
/// ); | ||
/// | ||
/// // Iterate over all values in the set. | ||
/// for vec in intersection { | ||
/// println!("{:}", vec); | ||
/// } | ||
/// ``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that having a set of vectors may be a bit confusing here. Perhaps a set of integers? The intersection method may also want to take an explicitly constructed |
||
#[deriving(Clone)] | ||
pub struct TreeSet<T> { | ||
priv map: TreeMap<T, ()> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you expand this a bit to talk a bit about the implementation and semantics of the tree? It looks like there's a comment above which may be able to move into this doc-comment.