diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-03-13 17:07:23 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-03-13 19:33:10 -0400 |
| commit | becad9bb07423ed4d0d8b192cce83de99b535e86 (patch) | |
| tree | 75feb8f05655deac9dcfb28f45c7cdb8f029c9c5 /src/libstd/smallintmap.rs | |
| parent | 4d8ddff52a60d3785052f1e0a231cb95c98fdc24 (diff) | |
| download | rust-becad9bb07423ed4d0d8b192cce83de99b535e86.tar.gz rust-becad9bb07423ed4d0d8b192cce83de99b535e86.zip | |
add the mutate_values method to the Map trait
Diffstat (limited to 'src/libstd/smallintmap.rs')
| -rw-r--r-- | src/libstd/smallintmap.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 726e7c36abd..bdce257e347 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -85,7 +85,17 @@ impl<V> Map<uint, V> for SmallIntMap<V> { self.each(|&(_, v)| blk(v)) } - /// Return the value corresponding to the key in the map + /// Visit all key-value pairs in order + fn mutate_values(&mut self, it: &fn(&uint, &'self mut V) -> bool) { + for uint::range(0, self.v.len()) |i| { + match self.v[i] { + Some(ref mut elt) => if !it(&i, elt) { break }, + None => () + } + } + } + + /// Iterate over the map and mutate the contained values pure fn find(&self, key: &uint) -> Option<&self/V> { if *key < self.v.len() { match self.v[*key] { |
