about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Morgan <me@chrismorgan.info>2014-05-15 10:13:36 +1000
committerChris Morgan <me@chrismorgan.info>2014-05-15 10:13:36 +1000
commit73dc1e016d342d46f1fdeffb9aab75c5ecc5a20b (patch)
treedc40fd6aeb0205457f1b6f629d236a8d4a350c6d
parentacdce638528618c9f1113b651e296031c7c2a85c (diff)
downloadrust-73dc1e016d342d46f1fdeffb9aab75c5ecc5a20b.tar.gz
rust-73dc1e016d342d46f1fdeffb9aab75c5ecc5a20b.zip
Rename HashMap.mangle to find_with_or_insert_with.
This also entails swapping the order of the find and insert callbacks so
that their order matches the order of the terms in the method name.
-rw-r--r--src/libcollections/hashmap.rs46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/libcollections/hashmap.rs b/src/libcollections/hashmap.rs
index 64a70c93b05..35a89fe5dc5 100644
--- a/src/libcollections/hashmap.rs
+++ b/src/libcollections/hashmap.rs
@@ -1239,14 +1239,14 @@ impl<K: TotalEq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
     /// Return the value corresponding to the key in the map, or insert
     /// and return the value if it doesn't exist.
     pub fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a mut V {
-        self.mangle(k, v, |_k, a| a, |_k, _v, _a| ())
+        self.find_with_or_insert_with(k, v, |_k, _v, _a| (), |_k, a| a)
     }
 
     /// Return the value corresponding to the key in the map, or create,
     /// insert, and return a new value if it doesn't exist.
     pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: |&K| -> V)
                                -> &'a mut V {
-        self.mangle(k, (), |k, _a| f(k), |_k, _v, _a| ())
+        self.find_with_or_insert_with(k, (), |_k, _v, _a| (), |k, _a| f(k))
     }
 
     /// Insert a key-value pair into the map if the key is not already present.
@@ -1258,7 +1258,7 @@ impl<K: TotalEq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
                                  v: V,
                                  f: |&K, &mut V|)
                                  -> &'a mut V {
-        self.mangle(k, v, |_k, a| a, |k, v, _a| f(k, v))
+        self.find_with_or_insert_with(k, v, |k, v, _a| f(k, v), |_k, a| a)
     }
 
     /// Modify and return the value corresponding to the key in the map, or
@@ -1282,31 +1282,33 @@ impl<K: TotalEq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
     /// let new = vec!["a key", "b key", "z key"];
     ///
     /// for k in new.move_iter() {
-    ///     map.mangle(k, "new value",
-    ///                // if the key doesn't exist in the map yet, add it in
-    ///                // the obvious way.
-    ///                |_k, v| vec![v],
-    ///                // if the key does exist either prepend or append this
-    ///                // new value based on the first letter of the key.
-    ///                |key, already, new| {
-    ///                    if key.as_slice().starts_with("z") {
-    ///                        already.unshift(new);
-    ///                    } else {
-    ///                        already.push(new);
-    ///                    }
-    ///                });
+    ///     map.find_with_or_insert_with(
+    ///         k, "new value",
+    ///         // if the key does exist either prepend or append this
+    ///         // new value based on the first letter of the key.
+    ///         |key, already, new| {
+    ///             if key.as_slice().starts_with("z") {
+    ///                 already.unshift(new);
+    ///             } else {
+    ///                 already.push(new);
+    ///             }
+    ///         },
+    ///         // if the key doesn't exist in the map yet, add it in
+    ///         // the obvious way.
+    ///         |_k, v| vec![v],
+    ///     );
     /// }
     ///
     /// for (k, v) in map.iter() {
     ///     println!("{} -> {}", *k, *v);
     /// }
     /// ```
-    pub fn mangle<'a, A>(&'a mut self,
-                         k: K,
-                         a: A,
-                         not_found: |&K, A| -> V,
-                         found: |&K, &mut V, A|)
-                        -> &'a mut V {
+    pub fn find_with_or_insert_with<'a, A>(&'a mut self,
+                                           k: K,
+                                           a: A,
+                                           found: |&K, &mut V, A|,
+                                           not_found: |&K, A| -> V)
+                                          -> &'a mut V {
         let hash = self.make_hash(&k);
         match self.search_hashed(&hash, &k) {
             None => {