Skip to content

Commit b53057f

Browse files
committed
test: Remove uses of oldmap::HashMap
1 parent 17459d0 commit b53057f

16 files changed

+88
-116
lines changed

src/test/auxiliary/issue-2631-a.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
extern mod std;
1515

16-
use std::oldmap::HashMap;
16+
use core::hashmap::linear::LinearMap;
1717

18-
pub type header_map = HashMap<~str, @mut ~[@~str]>;
18+
pub type header_map = LinearMap<~str, @mut ~[@~str]>;
1919

2020
// the unused ty param is necessary so this gets monomorphized
21-
pub fn request<T:Copy>(req: header_map) {
22-
let _x = copy *(copy *req.get(&~"METHOD"))[0u];
21+
pub fn request<T:Copy>(req: &header_map) {
22+
let _x = copy *(copy **req.get(&~"METHOD"))[0u];
2323
}

src/test/bench/core-std.rs

-20
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ extern mod std;
1414

1515
use std::time::precise_time_s;
1616
use std::oldmap;
17-
use std::oldmap::{Map, HashMap};
1817

1918
use core::io::{Reader, ReaderUtil};
2019
use core::rand::RngUtil;
@@ -29,7 +28,6 @@ fn main() {
2928

3029
bench!(shift_push);
3130
bench!(read_line);
32-
bench!(str_set);
3331
bench!(vec_plus);
3432
bench!(vec_append);
3533
bench!(vec_push_all);
@@ -73,24 +71,6 @@ fn read_line() {
7371
}
7472
}
7573

76-
fn str_set() {
77-
let r = rand::Rng();
78-
79-
let s = oldmap::HashMap();
80-
81-
for int::range(0, 1000) |_i| {
82-
oldmap::set_add(s, r.gen_str(10));
83-
}
84-
85-
let mut found = 0;
86-
for int::range(0, 1000) |_i| {
87-
match s.find(&r.gen_str(10)) {
88-
Some(_) => { found += 1; }
89-
None => { }
90-
}
91-
}
92-
}
93-
9474
fn vec_plus() {
9575
let r = rand::Rng();
9676

src/test/bench/graph500-bfs.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ An implementation of the Graph500 Breadth First Search problem in Rust.
2222
extern mod std;
2323
use std::arc;
2424
use std::time;
25-
use std::oldmap;
26-
use std::oldmap::Map;
27-
use std::oldmap::HashMap;
2825
use std::deque::Deque;
2926
use std::par;
27+
use core::hashmap::linear::{LinearMap, LinearSet};
3028
use core::io::WriterUtil;
3129
use core::int::abs;
3230
use core::rand::RngUtil;
@@ -82,27 +80,31 @@ fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] {
8280
}
8381

8482
fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
85-
let graph = do vec::from_fn(N) |_i| {
86-
oldmap::HashMap::<node_id, ()>()
83+
let mut graph = do vec::from_fn(N) |_i| {
84+
LinearSet::new()
8785
};
8886

8987
do vec::each(edges) |e| {
9088
match *e {
9189
(i, j) => {
92-
oldmap::set_add(graph[i], j);
93-
oldmap::set_add(graph[j], i);
90+
graph[i].insert(j);
91+
graph[j].insert(i);
9492
}
9593
}
9694
true
9795
}
9896

99-
do graph.map() |v| {
100-
oldmap::vec_from_set(*v)
97+
do vec::map_consume(graph) |mut v| {
98+
let mut vec = ~[];
99+
do v.consume |i| {
100+
vec.push(i);
101+
}
102+
vec
101103
}
102104
}
103105

104106
fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] {
105-
let keys = oldmap::HashMap::<node_id, ()>();
107+
let mut keys = LinearSet::new();
106108
let r = rand::Rng();
107109

108110
while keys.len() < n {
@@ -111,10 +113,14 @@ fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] {
111113
if graph[k].len() > 0u && vec::any(graph[k], |i| {
112114
*i != k as node_id
113115
}) {
114-
oldmap::set_add(keys, k as node_id);
116+
keys.insert(k as node_id);
115117
}
116118
}
117-
oldmap::vec_from_set(keys)
119+
let mut vec = ~[];
120+
do keys.consume |i| {
121+
vec.push(i);
122+
}
123+
return vec;
118124
}
119125

120126
/**

src/test/bench/shootout-chameneos-redux.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// chameneos
1212

1313
extern mod std;
14-
use std::oldmap;
15-
use std::oldmap::HashMap;
1614
use std::sort;
1715
use core::cell::Cell;
1816
use core::comm::*;

src/test/bench/shootout-k-nucleotide-pipes.rs

+20-17
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
#[legacy_modes];
1515

1616
extern mod std;
17-
use std::oldmap;
18-
use std::oldmap::HashMap;
1917
use std::sort;
18+
use core::hashmap::linear::LinearMap;
2019
use core::io::ReaderUtil;
2120
use core::comm::{stream, Port, Chan};
2221
use core::cmp::Ord;
2322

2423
// given a map, print a sorted version of it
25-
fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
24+
fn sort_and_fmt(mm: &LinearMap<~[u8], uint>, total: uint) -> ~str {
2625
fn pct(xx: uint, yy: uint) -> float {
2726
return (xx as float) * 100f / (yy as float);
2827
}
@@ -49,7 +48,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
4948
let mut pairs = ~[];
5049

5150
// map -> [(k,%)]
52-
for mm.each |&key, &val| {
51+
for mm.each |&(&key, &val)| {
5352
pairs.push((key, pct(val, total)));
5453
}
5554

@@ -68,17 +67,21 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
6867
}
6968

7069
// given a map, search for the frequency of a pattern
71-
fn find(mm: HashMap<~[u8], uint>, key: ~str) -> uint {
70+
fn find(mm: &LinearMap<~[u8], uint>, key: ~str) -> uint {
7271
match mm.find(&str::to_bytes(str::to_lower(key))) {
7372
option::None => { return 0u; }
74-
option::Some(num) => { return num; }
73+
option::Some(&num) => { return num; }
7574
}
7675
}
7776

7877
// given a map, increment the counter for a key
79-
fn update_freq(mm: HashMap<~[u8], uint>, key: &[u8]) {
78+
fn update_freq(mm: &mut LinearMap<~[u8], uint>, key: &[u8]) {
8079
let key = vec::slice(key, 0, key.len()).to_vec();
81-
mm.update(key, 1, |v,v1| { v+v1 });
80+
let newval = match mm.pop(&key) {
81+
Some(v) => v + 1,
82+
None => 1
83+
};
84+
mm.insert(key, newval);
8285
}
8386

8487
// given a ~[u8], for each window call a function
@@ -100,7 +103,7 @@ fn windows_with_carry(bb: &[u8], nn: uint,
100103
fn make_sequence_processor(sz: uint, from_parent: comm::Port<~[u8]>,
101104
to_parent: comm::Chan<~str>) {
102105

103-
let freqs: HashMap<~[u8], uint> = oldmap::HashMap();
106+
let mut freqs: LinearMap<~[u8], uint> = LinearMap::new();
104107
let mut carry: ~[u8] = ~[];
105108
let mut total: uint = 0u;
106109

@@ -112,19 +115,19 @@ fn make_sequence_processor(sz: uint, from_parent: comm::Port<~[u8]>,
112115
if line == ~[] { break; }
113116

114117
carry = windows_with_carry(carry + line, sz, |window| {
115-
update_freq(freqs, window);
118+
update_freq(&mut freqs, window);
116119
total += 1u;
117120
});
118121
}
119122

120123
let buffer = match sz {
121-
1u => { sort_and_fmt(freqs, total) }
122-
2u => { sort_and_fmt(freqs, total) }
123-
3u => { fmt!("%u\t%s", find(freqs, ~"GGT"), ~"GGT") }
124-
4u => { fmt!("%u\t%s", find(freqs, ~"GGTA"), ~"GGTA") }
125-
6u => { fmt!("%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT") }
126-
12u => { fmt!("%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT") }
127-
18u => { fmt!("%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT") }
124+
1u => { sort_and_fmt(&freqs, total) }
125+
2u => { sort_and_fmt(&freqs, total) }
126+
3u => { fmt!("%u\t%s", find(&freqs, ~"GGT"), ~"GGT") }
127+
4u => { fmt!("%u\t%s", find(&freqs, ~"GGTA"), ~"GGTA") }
128+
6u => { fmt!("%u\t%s", find(&freqs, ~"GGTATT"), ~"GGTATT") }
129+
12u => { fmt!("%u\t%s", find(&freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT") }
130+
18u => { fmt!("%u\t%s", find(&freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT") }
128131
_ => { ~"" }
129132
};
130133

src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
// except according to those terms.
1010

1111
//buggy.rs
12-
extern mod std;
13-
use std::oldmap::HashMap;
12+
13+
use core::hashmap::linear::LinearMap;
1414

1515
fn main() {
16-
let buggy_map :HashMap<uint, &uint> =
17-
HashMap::<uint, &uint>();
16+
let mut buggy_map :LinearMap<uint, &uint> =
17+
LinearMap::new::<uint, &uint>();
1818
buggy_map.insert(42, &*~1); //~ ERROR illegal borrow
1919

2020
// but it is ok if we use a temporary

src/test/compile-fail/for-loop-decl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
// error-pattern: mismatched types
1212
extern mod std;
13-
use std::oldmap::HashMap;
1413
use std::bitv;
14+
use core::hashmap::linear::LinearMap;
1515

1616
struct FnInfo {
17-
vars: HashMap<uint, VarInfo>
17+
vars: LinearMap<uint, VarInfo>
1818
}
1919

2020
struct VarInfo {
@@ -27,7 +27,7 @@ fn bitv_to_str(enclosing: FnInfo, v: ~bitv::Bitv) -> str {
2727

2828
// error is that the value type in the hash map is var_info, not a box
2929
for enclosing.vars.each_value |val| {
30-
if v.get(val) { s += "foo"; }
30+
if *v.get(val) { s += "foo"; }
3131
}
3232
return s;
3333
}

src/test/run-pass/extern-mod-syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// except according to those terms.
1212

1313
extern mod std;
14-
use std::oldmap::HashMap;
14+
use std::json::Object;
1515

1616
pub fn main() {
1717
io::println("Hello world!");

src/test/run-pass/hashmap-memory.rs

+17-27
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,10 @@
1616
This originally came from the word-count benchmark.
1717
*/
1818

19-
extern mod std;
20-
21-
use std::oldmap;
22-
use std::oldmap::HashMap;
23-
use core::comm::*;
24-
2519
pub fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, ~"1"); }
2620

2721
mod map_reduce {
28-
use std::oldmap;
29-
use std::oldmap::HashMap;
22+
use core::hashmap::linear::LinearMap;
3023
use core::comm::*;
3124

3225
pub type putter = @fn(~str, ~str);
@@ -44,23 +37,20 @@ mod map_reduce {
4437
}
4538

4639
fn map_task(ctrl: SharedChan<ctrl_proto>, input: ~str) {
47-
let intermediates = oldmap::HashMap();
48-
49-
fn emit(im: oldmap::HashMap<~str, int>, ctrl: SharedChan<ctrl_proto>, key: ~str,
50-
val: ~str) {
51-
let mut c;
52-
match im.find(&key) {
53-
Some(_c) => { c = _c }
54-
None => {
55-
let (pp, cc) = stream();
56-
error!("sending find_reducer");
57-
ctrl.send(find_reducer(str::to_bytes(key), cc));
58-
error!("receiving");
59-
c = pp.recv();
60-
error!(c);
61-
im.insert(key, c);
62-
}
40+
let intermediates = @mut LinearMap::new();
41+
42+
fn emit(im: &mut LinearMap<~str, int>, ctrl: SharedChan<ctrl_proto>, key: ~str,
43+
_val: ~str) {
44+
if im.contains_key(&key) {
45+
return;
6346
}
47+
let (pp, cc) = stream();
48+
error!("sending find_reducer");
49+
ctrl.send(find_reducer(str::to_bytes(key), cc));
50+
error!("receiving");
51+
let c = pp.recv();
52+
error!(c);
53+
im.insert(key, c);
6454
}
6555

6656
let ctrl_clone = ctrl.clone();
@@ -75,9 +65,9 @@ mod map_reduce {
7565
// This task becomes the master control task. It spawns others
7666
// to do the rest.
7767

78-
let mut reducers: oldmap::HashMap<~str, int>;
68+
let mut reducers: LinearMap<~str, int>;
7969

80-
reducers = oldmap::HashMap();
70+
reducers = LinearMap::new();
8171

8272
start_mappers(ctrl_chan, inputs.clone());
8373

@@ -89,7 +79,7 @@ mod map_reduce {
8979
find_reducer(k, cc) => {
9080
let mut c;
9181
match reducers.find(&str::from_bytes(k)) {
92-
Some(_c) => { c = _c; }
82+
Some(&_c) => { c = _c; }
9383
None => { c = 0; }
9484
}
9585
cc.send(c);

src/test/run-pass/issue-1696.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
// option. This file may not be copied, modified, or distributed
1111
// except according to those terms.
1212

13-
extern mod std;
14-
use std::oldmap::HashMap;
13+
use core::hashmap::linear::LinearMap;
1514

1615
pub fn main() {
17-
let m = HashMap();
16+
let mut m = LinearMap::new();
1817
m.insert(str::to_bytes(~"foo"), str::to_bytes(~"bar"));
1918
error!(m);
2019
}

src/test/run-pass/issue-2631-b.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
// aux-build:issue-2631-a.rs
1313

1414
extern mod req;
15-
extern mod std;
1615

1716
use req::*;
18-
use std::oldmap::HashMap;
17+
use core::hashmap::linear::LinearMap;
1918

2019
pub fn main() {
2120
let v = ~[@~"hi"];
22-
let m: req::header_map = HashMap();
21+
let mut m: req::header_map = LinearMap::new();
2322
m.insert(~"METHOD", @mut v);
24-
request::<int>(m);
23+
request::<int>(&m);
2524
}

src/test/run-pass/issue-2804-2.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
// Minimized version of issue-2804.rs. Both check that callee IDs don't
1414
// clobber the previous node ID in a macro expr
15-
extern mod std;
16-
use std::oldmap::HashMap;
1715

18-
fn add_interfaces(managed_ip: ~str, device: std::oldmap::HashMap<~str, int>) {
19-
error!("%s, %?", managed_ip, device[~"interfaces"]);
16+
use core::hashmap::linear::LinearMap;
17+
18+
fn add_interfaces(managed_ip: ~str, device: LinearMap<~str, int>) {
19+
error!("%s, %?", managed_ip, device.get(&~"interfaces"));
2020
}
2121

2222
pub fn main() {}

0 commit comments

Comments
 (0)