Skip to content

Commit 515c2f8

Browse files
killerswanbrson
authored andcommitted
---
yaml --- r: 40524 b: refs/heads/dist-snap c: 7b13ef7 h: refs/heads/master v: v3
1 parent c934ff2 commit 515c2f8

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
99
refs/heads/incoming: e90142e536c150df0d9b4b2f11352152177509b5
10-
refs/heads/dist-snap: a343e435d59e21188f6fc5918324c751a7eff6a9
10+
refs/heads/dist-snap: 7b13ef7d501daea5f56605659ae1f1e38371ab32
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/map.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,4 +773,25 @@ mod tests {
773773
assert map.get(~"b") == 2;
774774
assert map.get(~"c") == 3;
775775
}
776+
777+
#[test]
778+
fn test_insert_with_key() {
779+
let map = map::HashMap::<~str, uint>();
780+
781+
fn inc(k: ~str, v0: uint, v1: uint) -> uint {
782+
v0 + v1
783+
}
784+
785+
map.insert_with_key(inc, ~"cat", 1);
786+
map.insert_with_key(inc, ~"mongoose", 1);
787+
map.insert_with_key(inc, ~"cat", 7);
788+
map.insert_with_key(inc, ~"ferret", 3);
789+
map.insert_with_key(inc, ~"cat", 2);
790+
791+
assert 10 == option::get(map.find(~"cat"));
792+
assert 3 == option::get(map.find(~"ferret"));
793+
assert 1 == option::get(map.find(~"mongoose"));
794+
795+
assert None == map.find(~"unicorn");
796+
}
776797
}

branches/dist-snap/src/test/bench/shootout-k-nucleotide-pipes.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ fn find(mm: HashMap<~[u8], uint>, key: ~str) -> uint {
6969
// given a map, increment the counter for a key
7070
fn update_freq(mm: HashMap<~[u8], uint>, key: &[u8]) {
7171
let key = vec::slice(key, 0, key.len());
72-
match mm.find(key) {
73-
option::None => { mm.insert(key, 1u ); }
74-
option::Some(val) => { mm.insert(key, 1u + val); }
75-
}
72+
mm.insert_with_key(|k,v,v1| {v + v1}, key, 1);
7673
}
7774

7875
// given a ~[u8], for each window call a function

branches/dist-snap/src/test/bench/shootout-k-nucleotide.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ fn find(mm: HashMap<~[u8], uint>, key: ~str) -> uint {
6666
// given a map, increment the counter for a key
6767
fn update_freq(mm: HashMap<~[u8], uint>, key: &[u8]) {
6868
let key = vec::slice(key, 0, key.len());
69-
match mm.find(key) {
70-
option::None => { mm.insert(key, 1u ); }
71-
option::Some(val) => { mm.insert(key, 1u + val); }
72-
}
69+
mm.insert_with_key(|k,v,v1| {v + v1}, key, 1);
7370
}
7471

7572
// given a ~[u8], for each window call a function

0 commit comments

Comments
 (0)