Skip to content

Commit

Permalink
test: Remove uses of oldmap::HashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Mar 26, 2013
1 parent 17459d0 commit b53057f
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 116 deletions.
8 changes: 4 additions & 4 deletions src/test/auxiliary/issue-2631-a.rs
Expand Up @@ -13,11 +13,11 @@

extern mod std;

use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;

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

// the unused ty param is necessary so this gets monomorphized
pub fn request<T:Copy>(req: header_map) {
let _x = copy *(copy *req.get(&~"METHOD"))[0u];
pub fn request<T:Copy>(req: &header_map) {
let _x = copy *(copy **req.get(&~"METHOD"))[0u];
}
20 changes: 0 additions & 20 deletions src/test/bench/core-std.rs
Expand Up @@ -14,7 +14,6 @@ extern mod std;

use std::time::precise_time_s;
use std::oldmap;
use std::oldmap::{Map, HashMap};

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

bench!(shift_push);
bench!(read_line);
bench!(str_set);
bench!(vec_plus);
bench!(vec_append);
bench!(vec_push_all);
Expand Down Expand Up @@ -73,24 +71,6 @@ fn read_line() {
}
}

fn str_set() {
let r = rand::Rng();

let s = oldmap::HashMap();

for int::range(0, 1000) |_i| {
oldmap::set_add(s, r.gen_str(10));
}

let mut found = 0;
for int::range(0, 1000) |_i| {
match s.find(&r.gen_str(10)) {
Some(_) => { found += 1; }
None => { }
}
}
}

fn vec_plus() {
let r = rand::Rng();

Expand Down
30 changes: 18 additions & 12 deletions src/test/bench/graph500-bfs.rs
Expand Up @@ -22,11 +22,9 @@ An implementation of the Graph500 Breadth First Search problem in Rust.
extern mod std;
use std::arc;
use std::time;
use std::oldmap;
use std::oldmap::Map;
use std::oldmap::HashMap;
use std::deque::Deque;
use std::par;
use core::hashmap::linear::{LinearMap, LinearSet};
use core::io::WriterUtil;
use core::int::abs;
use core::rand::RngUtil;
Expand Down Expand Up @@ -82,27 +80,31 @@ fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] {
}

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

do vec::each(edges) |e| {
match *e {
(i, j) => {
oldmap::set_add(graph[i], j);
oldmap::set_add(graph[j], i);
graph[i].insert(j);
graph[j].insert(i);
}
}
true
}

do graph.map() |v| {
oldmap::vec_from_set(*v)
do vec::map_consume(graph) |mut v| {
let mut vec = ~[];
do v.consume |i| {
vec.push(i);
}
vec
}
}

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

while keys.len() < n {
Expand All @@ -111,10 +113,14 @@ fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] {
if graph[k].len() > 0u && vec::any(graph[k], |i| {
*i != k as node_id
}) {
oldmap::set_add(keys, k as node_id);
keys.insert(k as node_id);
}
}
oldmap::vec_from_set(keys)
let mut vec = ~[];
do keys.consume |i| {
vec.push(i);
}
return vec;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/test/bench/shootout-chameneos-redux.rs
Expand Up @@ -11,8 +11,6 @@
// chameneos

extern mod std;
use std::oldmap;
use std::oldmap::HashMap;
use std::sort;
use core::cell::Cell;
use core::comm::*;
Expand Down
37 changes: 20 additions & 17 deletions src/test/bench/shootout-k-nucleotide-pipes.rs
Expand Up @@ -14,15 +14,14 @@
#[legacy_modes];

extern mod std;
use std::oldmap;
use std::oldmap::HashMap;
use std::sort;
use core::hashmap::linear::LinearMap;
use core::io::ReaderUtil;
use core::comm::{stream, Port, Chan};
use core::cmp::Ord;

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

// map -> [(k,%)]
for mm.each |&key, &val| {
for mm.each |&(&key, &val)| {
pairs.push((key, pct(val, total)));
}

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

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

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

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

let freqs: HashMap<~[u8], uint> = oldmap::HashMap();
let mut freqs: LinearMap<~[u8], uint> = LinearMap::new();
let mut carry: ~[u8] = ~[];
let mut total: uint = 0u;

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

carry = windows_with_carry(carry + line, sz, |window| {
update_freq(freqs, window);
update_freq(&mut freqs, window);
total += 1u;
});
}

let buffer = match sz {
1u => { sort_and_fmt(freqs, total) }
2u => { sort_and_fmt(freqs, total) }
3u => { fmt!("%u\t%s", find(freqs, ~"GGT"), ~"GGT") }
4u => { fmt!("%u\t%s", find(freqs, ~"GGTA"), ~"GGTA") }
6u => { fmt!("%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT") }
12u => { fmt!("%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT") }
18u => { fmt!("%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT") }
1u => { sort_and_fmt(&freqs, total) }
2u => { sort_and_fmt(&freqs, total) }
3u => { fmt!("%u\t%s", find(&freqs, ~"GGT"), ~"GGT") }
4u => { fmt!("%u\t%s", find(&freqs, ~"GGTA"), ~"GGTA") }
6u => { fmt!("%u\t%s", find(&freqs, ~"GGTATT"), ~"GGTATT") }
12u => { fmt!("%u\t%s", find(&freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT") }
18u => { fmt!("%u\t%s", find(&freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT") }
_ => { ~"" }
};

Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs
Expand Up @@ -9,12 +9,12 @@
// except according to those terms.

//buggy.rs
extern mod std;
use std::oldmap::HashMap;

use core::hashmap::linear::LinearMap;

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

// but it is ok if we use a temporary
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/for-loop-decl.rs
Expand Up @@ -10,11 +10,11 @@

// error-pattern: mismatched types
extern mod std;
use std::oldmap::HashMap;
use std::bitv;
use core::hashmap::linear::LinearMap;

struct FnInfo {
vars: HashMap<uint, VarInfo>
vars: LinearMap<uint, VarInfo>
}

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

// error is that the value type in the hash map is var_info, not a box
for enclosing.vars.each_value |val| {
if v.get(val) { s += "foo"; }
if *v.get(val) { s += "foo"; }
}
return s;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/extern-mod-syntax.rs
Expand Up @@ -11,7 +11,7 @@
// except according to those terms.

extern mod std;
use std::oldmap::HashMap;
use std::json::Object;

pub fn main() {
io::println("Hello world!");
Expand Down
44 changes: 17 additions & 27 deletions src/test/run-pass/hashmap-memory.rs
Expand Up @@ -16,17 +16,10 @@
This originally came from the word-count benchmark.
*/

extern mod std;

use std::oldmap;
use std::oldmap::HashMap;
use core::comm::*;

pub fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, ~"1"); }

mod map_reduce {
use std::oldmap;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;
use core::comm::*;

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

fn map_task(ctrl: SharedChan<ctrl_proto>, input: ~str) {
let intermediates = oldmap::HashMap();

fn emit(im: oldmap::HashMap<~str, int>, ctrl: SharedChan<ctrl_proto>, key: ~str,
val: ~str) {
let mut c;
match im.find(&key) {
Some(_c) => { c = _c }
None => {
let (pp, cc) = stream();
error!("sending find_reducer");
ctrl.send(find_reducer(str::to_bytes(key), cc));
error!("receiving");
c = pp.recv();
error!(c);
im.insert(key, c);
}
let intermediates = @mut LinearMap::new();

fn emit(im: &mut LinearMap<~str, int>, ctrl: SharedChan<ctrl_proto>, key: ~str,
_val: ~str) {
if im.contains_key(&key) {
return;
}
let (pp, cc) = stream();
error!("sending find_reducer");
ctrl.send(find_reducer(str::to_bytes(key), cc));
error!("receiving");
let c = pp.recv();
error!(c);
im.insert(key, c);
}

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

let mut reducers: oldmap::HashMap<~str, int>;
let mut reducers: LinearMap<~str, int>;

reducers = oldmap::HashMap();
reducers = LinearMap::new();

start_mappers(ctrl_chan, inputs.clone());

Expand All @@ -89,7 +79,7 @@ mod map_reduce {
find_reducer(k, cc) => {
let mut c;
match reducers.find(&str::from_bytes(k)) {
Some(_c) => { c = _c; }
Some(&_c) => { c = _c; }
None => { c = 0; }
}
cc.send(c);
Expand Down
5 changes: 2 additions & 3 deletions src/test/run-pass/issue-1696.rs
Expand Up @@ -10,11 +10,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern mod std;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;

pub fn main() {
let m = HashMap();
let mut m = LinearMap::new();
m.insert(str::to_bytes(~"foo"), str::to_bytes(~"bar"));
error!(m);
}
7 changes: 3 additions & 4 deletions src/test/run-pass/issue-2631-b.rs
Expand Up @@ -12,14 +12,13 @@
// aux-build:issue-2631-a.rs

extern mod req;
extern mod std;

use req::*;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;

pub fn main() {
let v = ~[@~"hi"];
let m: req::header_map = HashMap();
let mut m: req::header_map = LinearMap::new();
m.insert(~"METHOD", @mut v);
request::<int>(m);
request::<int>(&m);
}
8 changes: 4 additions & 4 deletions src/test/run-pass/issue-2804-2.rs
Expand Up @@ -12,11 +12,11 @@

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

fn add_interfaces(managed_ip: ~str, device: std::oldmap::HashMap<~str, int>) {
error!("%s, %?", managed_ip, device[~"interfaces"]);
use core::hashmap::linear::LinearMap;

fn add_interfaces(managed_ip: ~str, device: LinearMap<~str, int>) {
error!("%s, %?", managed_ip, device.get(&~"interfaces"));
}

pub fn main() {}

0 comments on commit b53057f

Please sign in to comment.