diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-03-24 20:40:17 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-03-24 21:40:16 -0400 |
| commit | 38f39ac540d2a8b42c650e3aae9eaa715d47c554 (patch) | |
| tree | 4c21510053d0949fdccd721272416da9b4f5adda /src/libstd | |
| parent | f0f4a00e88fc374b2b3096789a11bf429d42c3a9 (diff) | |
| download | rust-38f39ac540d2a8b42c650e3aae9eaa715d47c554.tar.gz rust-38f39ac540d2a8b42c650e3aae9eaa715d47c554.zip | |
expose find_mut in the Map trait
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/smallintmap.rs | 24 | ||||
| -rw-r--r-- | src/libstd/treemap.rs | 12 |
2 files changed, 18 insertions, 18 deletions
diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index fffd6c9ee4f..4ad8d38b072 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -108,6 +108,18 @@ impl<V> Map<uint, V> for SmallIntMap<V> { } } + /// Return a mutable reference to the value corresponding to the key + fn find_mut(&mut self, key: &uint) -> Option<&'self mut V> { + if *key < self.v.len() { + match self.v[*key] { + Some(ref mut value) => Some(value), + None => None + } + } else { + None + } + } + /// Insert a key-value pair into the map. An existing value for a /// key is replaced by the new value. Return true if the key did /// not already exist in the map. @@ -140,18 +152,6 @@ pub impl<V> SmallIntMap<V> { fn get(&self, key: &uint) -> &'self V { self.find(key).expect("key not present") } - - /// Return a mutable reference to the value corresponding to the key - fn find_mut(&mut self, key: &uint) -> Option<&'self mut V> { - if *key < self.v.len() { - match self.v[*key] { - Some(ref mut value) => Some(value), - None => None - } - } else { - None - } - } } pub impl<V:Copy> SmallIntMap<V> { diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index b77037ba3ad..fccf58ddb6f 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -152,6 +152,12 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> { } } + /// Return a mutable reference to the value corresponding to the key + #[inline(always)] + fn find_mut(&mut self, key: &K) -> Option<&'self mut V> { + find_mut(&mut self.root, key) + } + /// Insert a key-value pair into the map. An existing value for a /// key is replaced by the new value. Return true if the key did /// not already exist in the map. @@ -189,12 +195,6 @@ pub impl<K: TotalOrd, V> TreeMap<K, V> { fn iter(&self) -> TreeMapIterator<'self, K, V> { TreeMapIterator{stack: ~[], node: &self.root} } - - /// Return a mutable reference to the value corresponding to the key - #[inline(always)] - fn find_mut(&mut self, key: &K) -> Option<&'self mut V> { - find_mut(&mut self.root, key) - } } /// Lazy forward iterator over a map |
