summary refs log tree commit diff
path: root/src/libstd/smallintmap.rs
diff options
context:
space:
mode:
authorKevin Cantu <me@kevincantu.org>2012-11-11 01:01:37 -0800
committerBrian Anderson <banderson@mozilla.com>2012-11-25 12:41:11 -0800
commita343e435d59e21188f6fc5918324c751a7eff6a9 (patch)
tree27998530694299076c231cb98266881981629310 /src/libstd/smallintmap.rs
parent455d73cb861bb0aca989fc8aca19c025ebf6f4ed (diff)
downloadrust-a343e435d59e21188f6fc5918324c751a7eff6a9.tar.gz
rust-a343e435d59e21188f6fc5918324c751a7eff6a9.zip
Add an insert_with_key function to the Map trait
Diffstat (limited to 'src/libstd/smallintmap.rs')
-rw-r--r--src/libstd/smallintmap.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs
index 9dc216a2155..8439d214ca0 100644
--- a/src/libstd/smallintmap.rs
+++ b/src/libstd/smallintmap.rs
@@ -103,6 +103,13 @@ impl<V: Copy> SmallIntMap<V>: map::Map<uint, V> {
     pure fn find(key: uint) -> Option<V> { find(self, key) }
     fn rehash() { fail }
 
+    fn insert_with_key(ff: fn(uint, V, V) -> V, key: uint, val: V) -> bool {
+        match self.find(key) {
+            None            => return self.insert(key, val),
+            Some(copy orig) => return self.insert(key, ff(key, orig, val)),
+        }
+    }
+
     pure fn each(it: fn(key: uint, value: V) -> bool) {
         self.each_ref(|k, v| it(*k, *v))
     }