提交 b53057f4 编写于 作者: A Alex Crichton

test: Remove uses of oldmap::HashMap

上级 17459d0b
......@@ -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];
}
......@@ -14,7 +14,6 @@
use std::time::precise_time_s;
use std::oldmap;
use std::oldmap::{Map, HashMap};
use core::io::{Reader, ReaderUtil};
use core::rand::RngUtil;
......@@ -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);
......@@ -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();
......
......@@ -22,11 +22,9 @@
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;
......@@ -82,27 +80,31 @@ fn choose_edge(i: node_id, j: node_id, scale: uint, r: @rand::Rng)
}
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 {
......@@ -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;
}
/**
......
......@@ -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::*;
......
......@@ -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);
}
......@@ -49,7 +48,7 @@ fn sortKV<TT:Copy + Ord,UU:Copy + Ord>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
let mut pairs = ~[];
// map -> [(k,%)]
for mm.each |&key, &val| {
for mm.each |&(&key, &val)| {
pairs.push((key, pct(val, total)));
}
......@@ -68,17 +67,21 @@ fn sortKV<TT:Copy + Ord,UU:Copy + Ord>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
}
// 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
......@@ -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;
......@@ -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") }
_ => { ~"" }
};
......
......@@ -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
......
......@@ -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 {
......@@ -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;
}
......
......@@ -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!");
......
......@@ -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);
......@@ -44,23 +37,20 @@ fn start_mappers(ctrl: SharedChan<ctrl_proto>, inputs: ~[~str]) {
}
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();
......@@ -75,9 +65,9 @@ pub fn map_reduce(inputs: ~[~str]) {
// 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());
......@@ -89,7 +79,7 @@ pub fn map_reduce(inputs: ~[~str]) {
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);
......
......@@ -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);
}
......@@ -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);
}
......@@ -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() {}
......@@ -11,8 +11,7 @@
// except according to those terms.
extern mod std;
use core::io::WriterUtil;
use std::oldmap::HashMap;
use core::hashmap::linear::LinearMap;
use std::json;
enum object {
......@@ -59,19 +58,20 @@ fn add_interface(store: int, managed_ip: ~str, data: std::json::Json) -> (~str,
}
}
fn add_interfaces(store: int, managed_ip: ~str, device: std::oldmap::HashMap<~str, std::json::Json>) -> ~[(~str, object)]
fn add_interfaces(store: int, managed_ip: ~str, device: LinearMap<~str, std::json::Json>) -> ~[(~str, object)]
{
match device[~"interfaces"]
match device.get(&~"interfaces")
{
std::json::List(interfaces) =>
&std::json::List(ref interfaces) =>
{
do vec::map(interfaces) |interface| {
do interfaces.map |interface| {
add_interface(store, copy managed_ip, copy *interface)
}
}
_ =>
{
error!("Expected list for %s interfaces but found %?", managed_ip, device[~"interfaces"]);
error!("Expected list for %s interfaces but found %?", managed_ip,
device.get(&~"interfaces"));
~[]
}
}
......
......@@ -10,12 +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 std::oldmap;
use core::hashmap::linear::LinearMap;
pub fn main() {
let buggy_map :HashMap<uint, &uint> = HashMap::<uint, &uint>();
let mut buggy_map: LinearMap<uint, &uint> = LinearMap::new::<uint, &uint>();
let x = ~1;
buggy_map.insert(42, &*x);
}
......@@ -14,7 +14,6 @@
extern mod std;
use core::io::{WriterUtil};
use std::oldmap::*;
#[cfg(test)]
fn check_strs(actual: &str, expected: &str) -> bool
......@@ -30,7 +29,7 @@ fn check_strs(actual: &str, expected: &str) -> bool
#[test]
fn tester()
{
let table = HashMap();
let mut table = core::hashmap::linear::LinearMap();
table.insert(@~"one", 1);
table.insert(@~"two", 2);
fail_unless!(check_strs(table.to_str(), ~"xxx")); // not sure what expected should be
......
......@@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
use core::hashmap::linear::LinearMap;
pub fn main() {
let x = std::oldmap::HashMap();
let mut x = LinearMap::new();
x.insert((@"abc", 0), 0);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册