@@ -1239,14 +1239,14 @@ impl<K: TotalEq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1239
1239
/// Return the value corresponding to the key in the map, or insert
1240
1240
/// and return the value if it doesn't exist.
1241
1241
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 )
1243
1243
}
1244
1244
1245
1245
/// Return the value corresponding to the key in the map, or create,
1246
1246
/// insert, and return a new value if it doesn't exist.
1247
1247
pub fn find_or_insert_with < ' a > ( & ' a mut self , k : K , f: |& K | -> V )
1248
1248
-> & ' 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 ) )
1250
1250
}
1251
1251
1252
1252
/// 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> {
1258
1258
v : V ,
1259
1259
f : |& K , & mut V |)
1260
1260
-> & ' 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 )
1262
1262
}
1263
1263
1264
1264
/// 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> {
1282
1282
/// let new = vec!["a key", "b key", "z key"];
1283
1283
///
1284
1284
/// 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
+ /// );
1298
1300
/// }
1299
1301
///
1300
1302
/// for (k, v) in map.iter() {
1301
1303
/// println!("{} -> {}", *k, *v);
1302
1304
/// }
1303
1305
/// ```
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 {
1310
1312
let hash = self . make_hash ( & k) ;
1311
1313
match self . search_hashed ( & hash, & k) {
1312
1314
None => {
0 commit comments