@@ -35,16 +35,16 @@ pub trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
35
35
* If the map contains a value for the key, use the function
36
36
* to set a new value.
37
37
*/
38
- fn insert_with_key ( key : K , newval : V , ff : fn ( K , V , V ) -> V ) -> bool ;
38
+ fn update_with_key ( key : K , newval : V , ff : fn ( K , V , V ) -> V ) -> bool ;
39
39
40
40
/**
41
41
* Add a value to the map.
42
42
*
43
- * If the map contains a value for the key, use the function
44
- * to set a new value. (Like insert_with_key , but with a function
45
- * of only values.)
43
+ * If the map contains a value for the key, use the function to
44
+ * set a new value. (Like `insert_or_update_with_key` , but with a
45
+ * function of only values.)
46
46
*/
47
- fn insert_with ( key : K , newval : V , ff : fn ( V , V ) -> V ) -> bool ;
47
+ fn update ( key : K , newval : V , ff : fn ( V , V ) -> V ) -> bool ;
48
48
49
49
/// Returns true if the map contains a value for the specified key
50
50
pure fn contains_key ( key : K ) -> bool ;
@@ -281,7 +281,7 @@ pub mod chained {
281
281
}
282
282
}
283
283
284
- fn insert_with_key ( key : K , newval : V , ff : fn ( K , V , V ) -> V ) -> bool {
284
+ fn update_with_key ( key : K , newval : V , ff : fn ( K , V , V ) -> V ) -> bool {
285
285
/*
286
286
match self.find(key) {
287
287
None => return self.insert(key, val),
@@ -330,8 +330,8 @@ pub mod chained {
330
330
}
331
331
}
332
332
333
- fn insert_with ( key : K , newval : V , ff : fn ( V , V ) -> V ) -> bool {
334
- return self . insert_with_key ( key, newval, |_k, v, v1| ff ( v, v1) ) ;
333
+ fn update ( key : K , newval : V , ff : fn ( V , V ) -> V ) -> bool {
334
+ return self . update_with_key ( key, newval, |_k, v, v1| ff ( v, v1) ) ;
335
335
}
336
336
337
337
pure fn get ( k : K ) -> V {
@@ -517,15 +517,15 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
517
517
}
518
518
}
519
519
520
- fn insert_with_key ( key : K , newval : V , ff : fn ( K , V , V ) -> V ) -> bool {
520
+ fn update_with_key ( key : K , newval : V , ff : fn ( K , V , V ) -> V ) -> bool {
521
521
match self . find ( key) {
522
522
None => return self . insert ( key, newval) ,
523
523
Some ( copy orig) => return self . insert ( key, ff ( key, orig, newval) )
524
524
}
525
525
}
526
526
527
- fn insert_with ( key : K , newval : V , ff : fn ( V , V ) -> V ) -> bool {
528
- return self . insert_with_key ( key, newval, |_k, v, v1| ff ( v, v1) ) ;
527
+ fn update ( key : K , newval : V , ff : fn ( V , V ) -> V ) -> bool {
528
+ return self . update_with_key ( key, newval, |_k, v, v1| ff ( v, v1) ) ;
529
529
}
530
530
531
531
fn remove ( key : K ) -> bool {
@@ -833,7 +833,7 @@ mod tests {
833
833
}
834
834
835
835
#[test]
836
- fn test_insert_with_key () {
836
+ fn test_update_with_key () {
837
837
let map = map::HashMap::<~str, uint>();
838
838
839
839
// given a new key, initialize it with this new count, given
@@ -848,11 +848,11 @@ mod tests {
848
848
849
849
// count the number of several types of animal,
850
850
// adding in groups as we go
851
- map.insert_with (~" cat", 1 , addMoreToCount_simple) ;
852
- map. insert_with_key ( ~"mongoose", 1 , addMoreToCount) ;
853
- map. insert_with ( ~"cat", 7 , addMoreToCount_simple) ;
854
- map. insert_with_key ( ~"ferret", 3 , addMoreToCount) ;
855
- map. insert_with_key ( ~"cat", 2 , addMoreToCount) ;
851
+ map.update (~" cat", 1 , addMoreToCount_simple) ;
852
+ map. update_with_key ( ~"mongoose", 1 , addMoreToCount) ;
853
+ map. update ( ~"cat", 7 , addMoreToCount_simple) ;
854
+ map. update_with_key ( ~"ferret", 3 , addMoreToCount) ;
855
+ map. update_with_key ( ~"cat", 2 , addMoreToCount) ;
856
856
857
857
// check the total counts
858
858
assert 10 == option:: get ( map. find ( ~"cat") ) ;
0 commit comments