Skip to content

Commit

Permalink
Add a doctest for the btreemap's entry method.
Browse files Browse the repository at this point in the history
Make some updates to the entry doctest.
  • Loading branch information
jbranchaud committed Dec 22, 2014
1 parent 34d6800 commit e8fcbfb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,30 @@ impl<K, V> BTreeMap<K, V> {

impl<K: Ord, V> BTreeMap<K, V> {
/// Gets the given key's corresponding entry in the map for in-place manipulation.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeMap;
/// use std::collections::btree_map::Entry;
///
/// let mut count: BTreeMap<&str, uint> = BTreeMap::new();
///
/// // count the number of occurrences of letters in the vec
/// for x in vec!["a","b","a","c","a","b"].iter() {
/// match count.entry(*x) {
/// Entry::Vacant(view) => {
/// view.set(1);
/// },
/// Entry::Occupied(mut view) => {
/// let v = view.get_mut();
/// *v += 1;
/// },
/// }
/// }
///
/// assert_eq!(count["a"], 3u);
/// ```
pub fn entry<'a>(&'a mut self, mut key: K) -> Entry<'a, K, V> {
// same basic logic of `swap` and `pop`, blended together
let mut stack = stack::PartialSearchStack::new(self);
Expand Down

0 comments on commit e8fcbfb

Please sign in to comment.