expose find_mut in the Map trait

This commit is contained in:
Daniel Micay
2013-03-24 20:40:17 -04:00
parent f0f4a00e88
commit 38f39ac540
6 changed files with 38 additions and 36 deletions

View File

@@ -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> {