Skip to content

Commit 73dc1e0

Browse files
committed
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.
1 parent acdce63 commit 73dc1e0

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/libcollections/hashmap.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,14 +1239,14 @@ impl<K: TotalEq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
12391239
/// Return the value corresponding to the key in the map, or insert
12401240
/// and return the value if it doesn't exist.
12411241
pub fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a mut V {
1242-
self.mangle(k, v, |_k, a| a, |_k, _v, _a| ())
1242+
self.find_with_or_insert_with(k, v, |_k, _v, _a| (), |_k, a| a)
12431243
}
12441244

12451245
/// Return the value corresponding to the key in the map, or create,
12461246
/// insert, and return a new value if it doesn't exist.
12471247
pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: |&K| -> V)
12481248
-> &'a mut V {
1249-
self.mangle(k, (), |k, _a| f(k), |_k, _v, _a| ())
1249+
self.find_with_or_insert_with(k, (), |_k, _v, _a| (), |k, _a| f(k))
12501250
}
12511251

12521252
/// 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> {
12581258
v: V,
12591259
f: |&K, &mut V|)
12601260
-> &'a mut V {
1261-
self.mangle(k, v, |_k, a| a, |k, v, _a| f(k, v))
1261+
self.find_with_or_insert_with(k, v, |k, v, _a| f(k, v), |_k, a| a)
12621262
}
12631263

12641264
/// 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> {
12821282
/// let new = vec!["a key", "b key", "z key"];
12831283
///
12841284
/// for k in new.move_iter() {
1285-
/// map.mangle(k, "new value",
1286-
/// // if the key doesn't exist in the map yet, add it in
1287-
/// // the obvious way.
1288-
/// |_k, v| vec![v],
1289-
/// // if the key does exist either prepend or append this
1290-
/// // new value based on the first letter of the key.
1291-
/// |key, already, new| {
1292-
/// if key.as_slice().starts_with("z") {
1293-
/// already.unshift(new);
1294-
/// } else {
1295-
/// already.push(new);
1296-
/// }
1297-
/// });
1285+
/// map.find_with_or_insert_with(
1286+
/// k, "new value",
1287+
/// // if the key does exist either prepend or append this
1288+
/// // new value based on the first letter of the key.
1289+
/// |key, already, new| {
1290+
/// if key.as_slice().starts_with("z") {
1291+
/// already.unshift(new);
1292+
/// } else {
1293+
/// already.push(new);
1294+
/// }
1295+
/// },
1296+
/// // if the key doesn't exist in the map yet, add it in
1297+
/// // the obvious way.
1298+
/// |_k, v| vec![v],
1299+
/// );
12981300
/// }
12991301
///
13001302
/// for (k, v) in map.iter() {
13011303
/// println!("{} -> {}", *k, *v);
13021304
/// }
13031305
/// ```
1304-
pub fn mangle<'a, A>(&'a mut self,
1305-
k: K,
1306-
a: A,
1307-
not_found: |&K, A| -> V,
1308-
found: |&K, &mut V, A|)
1309-
-> &'a mut V {
1306+
pub fn find_with_or_insert_with<'a, A>(&'a mut self,
1307+
k: K,
1308+
a: A,
1309+
found: |&K, &mut V, A|,
1310+
not_found: |&K, A| -> V)
1311+
-> &'a mut V {
13101312
let hash = self.make_hash(&k);
13111313
match self.search_hashed(&hash, &k) {
13121314
None => {

0 commit comments

Comments
 (0)