switch LinearMap to current constructor convention
This commit is contained in:
parent
591eefd740
commit
7f0fa143bc
6 changed files with 37 additions and 33 deletions
|
@ -1617,7 +1617,7 @@ fn dump_cache(c: &Cargo) {
|
||||||
need_dir(&c.root);
|
need_dir(&c.root);
|
||||||
|
|
||||||
let out = c.root.push("cache.json");
|
let out = c.root.push("cache.json");
|
||||||
let _root = json::Object(~LinearMap());
|
let _root = json::Object(~LinearMap::new());
|
||||||
|
|
||||||
if os::path_exists(&out) {
|
if os::path_exists(&out) {
|
||||||
copy_warn(&out, &c.root.push("cache.json.old"));
|
copy_warn(&out, &c.root.push("cache.json.old"));
|
||||||
|
@ -1638,10 +1638,10 @@ fn dump_sources(c: &Cargo) {
|
||||||
|
|
||||||
match io::buffered_file_writer(&out) {
|
match io::buffered_file_writer(&out) {
|
||||||
result::Ok(writer) => {
|
result::Ok(writer) => {
|
||||||
let mut hash = ~LinearMap();
|
let mut hash = ~LinearMap::new();
|
||||||
|
|
||||||
for c.sources.each |k, v| {
|
for c.sources.each |k, v| {
|
||||||
let mut chash = ~LinearMap();
|
let mut chash = ~LinearMap::new();
|
||||||
|
|
||||||
chash.insert(~"url", json::String(v.url));
|
chash.insert(~"url", json::String(v.url));
|
||||||
chash.insert(~"method", json::String(v.method));
|
chash.insert(~"method", json::String(v.method));
|
||||||
|
|
|
@ -352,6 +352,10 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K:Hash IterBytes Eq,V> LinearMap<K,V> {
|
impl<K:Hash IterBytes Eq,V> LinearMap<K,V> {
|
||||||
|
static fn new() -> LinearMap<K, V> {
|
||||||
|
linear_map_with_capacity(INITIAL_CAPACITY)
|
||||||
|
}
|
||||||
|
|
||||||
fn pop(&mut self, k: &K) -> Option<V> {
|
fn pop(&mut self, k: &K) -> Option<V> {
|
||||||
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
||||||
self.pop_internal(hash, k)
|
self.pop_internal(hash, k)
|
||||||
|
@ -405,7 +409,7 @@ pub mod linear {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K:Hash IterBytes Eq, V: Copy> LinearMap<K,V> {
|
impl<K:Hash IterBytes Eq, V: Copy> LinearMap<K, V> {
|
||||||
pure fn find_copy(&const self, k: &K) -> Option<V> {
|
pure fn find_copy(&const self, k: &K) -> Option<V> {
|
||||||
match self.bucket_for_key(self.buckets, k) {
|
match self.bucket_for_key(self.buckets, k) {
|
||||||
FoundEntry(idx) => {
|
FoundEntry(idx) => {
|
||||||
|
@ -504,7 +508,7 @@ pub mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn inserts() {
|
pub fn inserts() {
|
||||||
let mut m = ~LinearMap();
|
let mut m = LinearMap::new();
|
||||||
assert m.insert(1, 2);
|
assert m.insert(1, 2);
|
||||||
assert m.insert(2, 4);
|
assert m.insert(2, 4);
|
||||||
assert *m.get(&1) == 2;
|
assert *m.get(&1) == 2;
|
||||||
|
@ -513,7 +517,7 @@ pub mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn overwrite() {
|
pub fn overwrite() {
|
||||||
let mut m = ~LinearMap();
|
let mut m = LinearMap::new();
|
||||||
assert m.insert(1, 2);
|
assert m.insert(1, 2);
|
||||||
assert *m.get(&1) == 2;
|
assert *m.get(&1) == 2;
|
||||||
assert !m.insert(1, 3);
|
assert !m.insert(1, 3);
|
||||||
|
@ -553,7 +557,7 @@ pub mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn pops() {
|
pub fn pops() {
|
||||||
let mut m = ~LinearMap();
|
let mut m = LinearMap::new();
|
||||||
m.insert(1, 2);
|
m.insert(1, 2);
|
||||||
assert m.pop(&1) == Some(2);
|
assert m.pop(&1) == Some(2);
|
||||||
assert m.pop(&1) == None;
|
assert m.pop(&1) == None;
|
||||||
|
@ -561,7 +565,7 @@ pub mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn swaps() {
|
pub fn swaps() {
|
||||||
let mut m = ~LinearMap();
|
let mut m = LinearMap::new();
|
||||||
assert m.swap(1, 2) == None;
|
assert m.swap(1, 2) == None;
|
||||||
assert m.swap(1, 3) == Some(2);
|
assert m.swap(1, 3) == Some(2);
|
||||||
assert m.swap(1, 4) == Some(3);
|
assert m.swap(1, 4) == Some(3);
|
||||||
|
@ -569,10 +573,10 @@ pub mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn consumes() {
|
pub fn consumes() {
|
||||||
let mut m = ~LinearMap();
|
let mut m = LinearMap::new();
|
||||||
assert m.insert(1, 2);
|
assert m.insert(1, 2);
|
||||||
assert m.insert(2, 3);
|
assert m.insert(2, 3);
|
||||||
let mut m2 = ~LinearMap();
|
let mut m2 = LinearMap::new();
|
||||||
do m.consume |k, v| {
|
do m.consume |k, v| {
|
||||||
m2.insert(k, v);
|
m2.insert(k, v);
|
||||||
}
|
}
|
||||||
|
@ -598,7 +602,7 @@ pub mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn find() {
|
pub fn find() {
|
||||||
let mut m = ~LinearMap();
|
let mut m = LinearMap::new();
|
||||||
assert m.find(&1).is_none();
|
assert m.find(&1).is_none();
|
||||||
m.insert(1, 2);
|
m.insert(1, 2);
|
||||||
match m.find(&1) {
|
match m.find(&1) {
|
||||||
|
@ -609,12 +613,12 @@ pub mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_eq() {
|
pub fn test_eq() {
|
||||||
let mut m1 = ~LinearMap();
|
let mut m1 = LinearMap::new();
|
||||||
m1.insert(1, 2);
|
m1.insert(1, 2);
|
||||||
m1.insert(2, 3);
|
m1.insert(2, 3);
|
||||||
m1.insert(3, 4);
|
m1.insert(3, 4);
|
||||||
|
|
||||||
let mut m2 = ~LinearMap();
|
let mut m2 = LinearMap::new();
|
||||||
m2.insert(1, 2);
|
m2.insert(1, 2);
|
||||||
m2.insert(2, 3);
|
m2.insert(2, 3);
|
||||||
|
|
||||||
|
@ -627,7 +631,7 @@ pub mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_expand() {
|
pub fn test_expand() {
|
||||||
let mut m = ~LinearMap();
|
let mut m = LinearMap::new();
|
||||||
|
|
||||||
assert m.len() == 0;
|
assert m.len() == 0;
|
||||||
assert m.is_empty();
|
assert m.is_empty();
|
||||||
|
|
|
@ -24,7 +24,7 @@ use core::float;
|
||||||
use core::io::{WriterUtil, ReaderUtil};
|
use core::io::{WriterUtil, ReaderUtil};
|
||||||
use core::io;
|
use core::io;
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
use core::hashmap::linear;
|
use core::hashmap::linear::LinearMap;
|
||||||
use core::str;
|
use core::str;
|
||||||
use core::to_str;
|
use core::to_str;
|
||||||
use core::vec;
|
use core::vec;
|
||||||
|
@ -40,7 +40,7 @@ pub enum Json {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type List = ~[Json];
|
pub type List = ~[Json];
|
||||||
pub type Object = linear::LinearMap<~str, Json>;
|
pub type Object = LinearMap<~str, Json>;
|
||||||
|
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
line: uint,
|
line: uint,
|
||||||
|
@ -671,7 +671,7 @@ priv impl Parser {
|
||||||
self.bump();
|
self.bump();
|
||||||
self.parse_whitespace();
|
self.parse_whitespace();
|
||||||
|
|
||||||
let mut values = ~linear::LinearMap();
|
let mut values = ~LinearMap::new();
|
||||||
|
|
||||||
if self.ch == '}' {
|
if self.ch == '}' {
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -1175,9 +1175,9 @@ impl <A: ToJson> ~[A]: ToJson {
|
||||||
fn to_json() -> Json { List(self.map(|elt| elt.to_json())) }
|
fn to_json() -> Json { List(self.map(|elt| elt.to_json())) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <A: ToJson Copy> linear::LinearMap<~str, A>: ToJson {
|
impl <A: ToJson Copy> LinearMap<~str, A>: ToJson {
|
||||||
fn to_json() -> Json {
|
fn to_json() -> Json {
|
||||||
let mut d = linear::LinearMap();
|
let mut d = LinearMap::new();
|
||||||
for self.each() |key, value| {
|
for self.each() |key, value| {
|
||||||
d.insert(copy *key, value.to_json());
|
d.insert(copy *key, value.to_json());
|
||||||
}
|
}
|
||||||
|
@ -1188,7 +1188,7 @@ impl <A: ToJson Copy> linear::LinearMap<~str, A>: ToJson {
|
||||||
/*
|
/*
|
||||||
impl <A: ToJson Copy> @std::map::HashMap<~str, A>: ToJson {
|
impl <A: ToJson Copy> @std::map::HashMap<~str, A>: ToJson {
|
||||||
fn to_json() -> Json {
|
fn to_json() -> Json {
|
||||||
let mut d = linear::LinearMap();
|
let mut d = LinearMap::new();
|
||||||
for self.each_ref |key, value| {
|
for self.each_ref |key, value| {
|
||||||
d.insert(copy *key, value.to_json());
|
d.insert(copy *key, value.to_json());
|
||||||
}
|
}
|
||||||
|
@ -1223,10 +1223,10 @@ mod tests {
|
||||||
use json::*;
|
use json::*;
|
||||||
|
|
||||||
use core::result;
|
use core::result;
|
||||||
use core::hashmap::linear;
|
use core::hashmap::linear::LinearMap;
|
||||||
|
|
||||||
fn mk_object(items: &[(~str, Json)]) -> Json {
|
fn mk_object(items: &[(~str, Json)]) -> Json {
|
||||||
let mut d = ~linear::LinearMap();
|
let mut d = LinearMap::new();
|
||||||
|
|
||||||
for items.each |item| {
|
for items.each |item| {
|
||||||
match *item {
|
match *item {
|
||||||
|
|
|
@ -242,7 +242,7 @@ pub fn encode_form_urlencoded(m: &LinearMap<~str, ~[~str]>) -> ~str {
|
||||||
*/
|
*/
|
||||||
pub fn decode_form_urlencoded(s: &[u8]) -> LinearMap<~str, ~[~str]> {
|
pub fn decode_form_urlencoded(s: &[u8]) -> LinearMap<~str, ~[~str]> {
|
||||||
do io::with_bytes_reader(s) |rdr| {
|
do io::with_bytes_reader(s) |rdr| {
|
||||||
let mut m = LinearMap();
|
let mut m = LinearMap::new();
|
||||||
let mut key = ~"";
|
let mut key = ~"";
|
||||||
let mut value = ~"";
|
let mut value = ~"";
|
||||||
let mut parsing_key = true;
|
let mut parsing_key = true;
|
||||||
|
@ -1053,18 +1053,18 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_encode_form_urlencoded() {
|
fn test_encode_form_urlencoded() {
|
||||||
let mut m = LinearMap();
|
let mut m = LinearMap::new();
|
||||||
assert encode_form_urlencoded(&m) == ~"";
|
assert encode_form_urlencoded(&m) == ~"";
|
||||||
|
|
||||||
m.insert(~"", ~[]);
|
m.insert(~"", ~[]);
|
||||||
m.insert(~"foo", ~[]);
|
m.insert(~"foo", ~[]);
|
||||||
assert encode_form_urlencoded(&m) == ~"";
|
assert encode_form_urlencoded(&m) == ~"";
|
||||||
|
|
||||||
let mut m = LinearMap();
|
let mut m = LinearMap::new();
|
||||||
m.insert(~"foo", ~[~"bar", ~"123"]);
|
m.insert(~"foo", ~[~"bar", ~"123"]);
|
||||||
assert encode_form_urlencoded(&m) == ~"foo=bar&foo=123";
|
assert encode_form_urlencoded(&m) == ~"foo=bar&foo=123";
|
||||||
|
|
||||||
let mut m = LinearMap();
|
let mut m = LinearMap::new();
|
||||||
m.insert(~"foo bar", ~[~"abc", ~"12 = 34"]);
|
m.insert(~"foo bar", ~[~"abc", ~"12 = 34"]);
|
||||||
assert encode_form_urlencoded(&m) == ~"foo+bar=abc&foo+bar=12+%3D+34";
|
assert encode_form_urlencoded(&m) == ~"foo+bar=abc&foo+bar=12+%3D+34";
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ pub impl<S: Encoder> WorkMap: Encodable<S> {
|
||||||
pub impl<D: Decoder> WorkMap: Decodable<D> {
|
pub impl<D: Decoder> WorkMap: Decodable<D> {
|
||||||
static fn decode(&self, d: &D) -> WorkMap {
|
static fn decode(&self, d: &D) -> WorkMap {
|
||||||
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
|
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
|
||||||
let mut w = LinearMap();
|
let mut w = LinearMap::new();
|
||||||
for v.each |&(k,v)| {
|
for v.each |&(k,v)| {
|
||||||
w.insert(copy k, copy v);
|
w.insert(copy k, copy v);
|
||||||
}
|
}
|
||||||
|
@ -348,8 +348,8 @@ impl @Mut<Prep> : TPrep {
|
||||||
let blk = blk.unwrap();
|
let blk = blk.unwrap();
|
||||||
let chan = ~mut Some(move chan);
|
let chan = ~mut Some(move chan);
|
||||||
do task::spawn |move blk, move chan| {
|
do task::spawn |move blk, move chan| {
|
||||||
let exe = Exec { discovered_inputs: LinearMap(),
|
let exe = Exec{discovered_inputs: LinearMap::new(),
|
||||||
discovered_outputs: LinearMap() };
|
discovered_outputs: LinearMap::new()};
|
||||||
let chan = option::swap_unwrap(&mut *chan);
|
let chan = option::swap_unwrap(&mut *chan);
|
||||||
let v = blk(&exe);
|
let v = blk(&exe);
|
||||||
send_one(move chan, (move exe, move v));
|
send_one(move chan, (move exe, move v));
|
||||||
|
@ -411,10 +411,10 @@ fn test() {
|
||||||
use io::WriterUtil;
|
use io::WriterUtil;
|
||||||
|
|
||||||
let db = @Mut(Database { db_filename: Path("db.json"),
|
let db = @Mut(Database { db_filename: Path("db.json"),
|
||||||
db_cache: LinearMap(),
|
db_cache: LinearMap::new(),
|
||||||
db_dirty: false });
|
db_dirty: false });
|
||||||
let lg = @Mut(Logger { a: () });
|
let lg = @Mut(Logger { a: () });
|
||||||
let cfg = @LinearMap();
|
let cfg = @LinearMap::new();
|
||||||
let cx = @Context::new(db, lg, cfg);
|
let cx = @Context::new(db, lg, cfg);
|
||||||
let w:Work<~str> = do cx.prep("test1") |prep| {
|
let w:Work<~str> = do cx.prep("test1") |prep| {
|
||||||
let pth = Path("foo.c");
|
let pth = Path("foo.c");
|
||||||
|
|
|
@ -178,10 +178,10 @@ fn main() {
|
||||||
let rng = rand::seeded_rng(&seed);
|
let rng = rand::seeded_rng(&seed);
|
||||||
let mut results = empty_results();
|
let mut results = empty_results();
|
||||||
int_benchmarks::<@Mut<LinearMap<uint, uint>>>(
|
int_benchmarks::<@Mut<LinearMap<uint, uint>>>(
|
||||||
|| @Mut(LinearMap()),
|
|| @Mut(LinearMap::new()),
|
||||||
rng, num_keys, &mut results);
|
rng, num_keys, &mut results);
|
||||||
str_benchmarks::<@Mut<LinearMap<~str, uint>>>(
|
str_benchmarks::<@Mut<LinearMap<~str, uint>>>(
|
||||||
|| @Mut(LinearMap()),
|
|| @Mut(LinearMap::new()),
|
||||||
rng, num_keys, &mut results);
|
rng, num_keys, &mut results);
|
||||||
write_results("libstd::map::hashmap", &results);
|
write_results("libstd::map::hashmap", &results);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue