-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Improvements to BTreeSet
documentation.
#38208
Changes from all commits
cf56c1f
ae36934
4c4e8c4
fe0d092
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 |
---|---|---|
|
@@ -74,53 +74,89 @@ pub struct BTreeSet<T> { | |
map: BTreeMap<T, ()>, | ||
} | ||
|
||
/// An iterator over a BTreeSet's items. | ||
/// An iterator over a `BTreeSet`'s items. | ||
/// | ||
/// This structure is created by the [`iter`] method on [`BTreeSet`]. | ||
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. "iter()". |
||
/// | ||
/// [`BTreeSet`]: struct.BTreeSet.html | ||
/// [`iter`]: struct.BTreeSet.html#method.iter | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct Iter<'a, T: 'a> { | ||
iter: Keys<'a, T, ()>, | ||
} | ||
|
||
/// An owning iterator over a BTreeSet's items. | ||
/// An owning iterator over a `BTreeSet`'s items. | ||
/// | ||
/// This structure is created by the `into_iter` method on [`BTreeSet`] | ||
/// [`BTreeSet`] (provided by the `IntoIterator` trait). | ||
/// | ||
/// [`BTreeSet`]: struct.BTreeSet.html | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct IntoIter<T> { | ||
iter: ::btree_map::IntoIter<T, ()>, | ||
} | ||
|
||
/// An iterator over a sub-range of BTreeSet's items. | ||
/// An iterator over a sub-range of `BTreeSet`'s items. | ||
/// | ||
/// This structure is created by the [`range`] method on [`BTreeSet`]. | ||
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. "range()" |
||
/// | ||
/// [`BTreeSet`]: struct.BTreeSet.html | ||
/// [`range`]: struct.BTreeSet.html#method.range | ||
pub struct Range<'a, T: 'a> { | ||
iter: ::btree_map::Range<'a, T, ()>, | ||
} | ||
|
||
/// A lazy iterator producing elements in the set difference (in-order). | ||
/// | ||
/// This structure is created by the [`difference`] method on [`BTreeSet`]. | ||
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. "difference()" |
||
/// | ||
/// [`BTreeSet`]: struct.BTreeSet.html | ||
/// [`difference`]: struct.BTreeSet.html#method.difference | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct Difference<'a, T: 'a> { | ||
a: Peekable<Iter<'a, T>>, | ||
b: Peekable<Iter<'a, T>>, | ||
} | ||
|
||
/// A lazy iterator producing elements in the set symmetric difference (in-order). | ||
/// | ||
/// This structure is created by the [`symmetric_difference`] method on | ||
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. "symmetric_difference()" |
||
/// [`BTreeSet`]. | ||
/// | ||
/// [`BTreeSet`]: struct.BTreeSet.html | ||
/// [`symmetric_difference`]: struct.BTreeSet.html#method.symmetric_difference | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct SymmetricDifference<'a, T: 'a> { | ||
a: Peekable<Iter<'a, T>>, | ||
b: Peekable<Iter<'a, T>>, | ||
} | ||
|
||
/// A lazy iterator producing elements in the set intersection (in-order). | ||
/// | ||
/// This structure is created by the [`intersection`] method on [`BTreeSet`]. | ||
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. "intersection()" |
||
/// | ||
/// [`BTreeSet`]: struct.BTreeSet.html | ||
/// [`intersection`]: struct.BTreeSet.html#method.intersection | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct Intersection<'a, T: 'a> { | ||
a: Peekable<Iter<'a, T>>, | ||
b: Peekable<Iter<'a, T>>, | ||
} | ||
|
||
/// A lazy iterator producing elements in the set union (in-order). | ||
/// | ||
/// This structure is created by the [`union`] method on [`BTreeSet`]. | ||
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. "union()" |
||
/// | ||
/// [`BTreeSet`]: struct.BTreeSet.html | ||
/// [`union`]: struct.BTreeSet.html#method.union | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct Union<'a, T: 'a> { | ||
a: Peekable<Iter<'a, T>>, | ||
b: Peekable<Iter<'a, T>>, | ||
} | ||
|
||
impl<T: Ord> BTreeSet<T> { | ||
/// Makes a new BTreeSet with a reasonable choice of B. | ||
/// Makes a new `BTreeSet` with a reasonable choice of B. | ||
/// | ||
/// # Examples | ||
/// | ||
|
@@ -137,21 +173,32 @@ impl<T: Ord> BTreeSet<T> { | |
} | ||
|
||
impl<T> BTreeSet<T> { | ||
/// Gets an iterator over the BTreeSet's contents. | ||
/// Gets an iterator that visits the values in the `BTreeSet` in ascending order. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use std::collections::BTreeSet; | ||
/// | ||
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect(); | ||
/// let set: BTreeSet<usize> = [1, 2, 3].iter().cloned().collect(); | ||
/// let mut set_iter = set.iter(); | ||
/// assert_eq!(set_iter.next(), Some(&1)); | ||
/// assert_eq!(set_iter.next(), Some(&2)); | ||
/// assert_eq!(set_iter.next(), Some(&3)); | ||
/// assert_eq!(set_iter.next(), None); | ||
/// ``` | ||
/// | ||
/// for x in set.iter() { | ||
/// println!("{}", x); | ||
/// } | ||
/// Values returned by the iterator are returned in ascending order: | ||
/// | ||
/// let v: Vec<_> = set.iter().cloned().collect(); | ||
/// assert_eq!(v, [1, 2, 3, 4]); | ||
/// ``` | ||
/// use std::collections::BTreeSet; | ||
/// | ||
/// let set: BTreeSet<usize> = [3, 1, 2].iter().cloned().collect(); | ||
/// let mut set_iter = set.iter(); | ||
/// assert_eq!(set_iter.next(), Some(&1)); | ||
/// assert_eq!(set_iter.next(), Some(&2)); | ||
/// assert_eq!(set_iter.next(), Some(&3)); | ||
/// assert_eq!(set_iter.next(), None); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub fn iter(&self) -> Iter<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.
a
BTreeSet
's itemS?EDIT: Actually, it can be understood differently. Well, leaving this comment here anyway.