Skip to content

more work on the map trait and TreeMap/LinearMap #4594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 24, 2013
Merged
30 changes: 15 additions & 15 deletions src/libcargo/cargo.rc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use core::*;
use core::dvec::DVec;
use core::io::WriterUtil;
use core::result::{Ok, Err};
use core::send_map::linear::LinearMap;
use core::hashmap::linear::LinearMap;
use std::getopts::{optflag, optopt, opt_present};
use std::map::HashMap;
use std::{map, json, tempfile, term, sort, getopts};
Expand Down Expand Up @@ -465,19 +465,19 @@ fn parse_source(name: ~str, j: &json::Json) -> @Source {

match *j {
json::Object(j) => {
let mut url = match j.find(&~"url") {
let mut url = match j.find_copy(&~"url") {
Some(json::String(u)) => u,
_ => fail ~"needed 'url' field in source"
};
let method = match j.find(&~"method") {
let method = match j.find_copy(&~"method") {
Some(json::String(u)) => u,
_ => assume_source_method(url)
};
let key = match j.find(&~"key") {
let key = match j.find_copy(&~"key") {
Some(json::String(u)) => Some(u),
_ => None
};
let keyfp = match j.find(&~"keyfp") {
let keyfp = match j.find_copy(&~"keyfp") {
Some(json::String(u)) => Some(u),
_ => None
};
Expand Down Expand Up @@ -512,7 +512,7 @@ fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, @Source>) {
}

fn load_one_source_package(src: @Source, p: &json::Object) {
let name = match p.find(&~"name") {
let name = match p.find_copy(&~"name") {
Some(json::String(n)) => {
if !valid_pkg_name(n) {
warn(~"malformed source json: "
Expand All @@ -529,7 +529,7 @@ fn load_one_source_package(src: @Source, p: &json::Object) {
}
};

let uuid = match p.find(&~"uuid") {
let uuid = match p.find_copy(&~"uuid") {
Some(json::String(n)) => {
if !is_uuid(n) {
warn(~"malformed source json: "
Expand All @@ -545,15 +545,15 @@ fn load_one_source_package(src: @Source, p: &json::Object) {
}
};

let url = match p.find(&~"url") {
let url = match p.find_copy(&~"url") {
Some(json::String(n)) => n,
_ => {
warn(~"malformed source json: " + src.name + ~" (missing url)");
return;
}
};

let method = match p.find(&~"method") {
let method = match p.find_copy(&~"method") {
Some(json::String(n)) => n,
_ => {
warn(~"malformed source json: "
Expand All @@ -562,13 +562,13 @@ fn load_one_source_package(src: @Source, p: &json::Object) {
}
};

let reference = match p.find(&~"ref") {
let reference = match p.find_copy(&~"ref") {
Some(json::String(n)) => Some(n),
_ => None
};

let mut tags = ~[];
match p.find(&~"tags") {
match p.find_copy(&~"tags") {
Some(json::List(js)) => {
for js.each |j| {
match *j {
Expand All @@ -580,7 +580,7 @@ fn load_one_source_package(src: @Source, p: &json::Object) {
_ => ()
}

let description = match p.find(&~"description") {
let description = match p.find_copy(&~"description") {
Some(json::String(n)) => n,
_ => {
warn(~"malformed source json: " + src.name
Expand Down Expand Up @@ -1617,7 +1617,7 @@ fn dump_cache(c: &Cargo) {
need_dir(&c.root);

let out = c.root.push("cache.json");
let _root = json::Object(~LinearMap());
let _root = json::Object(~LinearMap::new());

if os::path_exists(&out) {
copy_warn(&out, &c.root.push("cache.json.old"));
Expand All @@ -1638,10 +1638,10 @@ fn dump_sources(c: &Cargo) {

match io::buffered_file_writer(&out) {
result::Ok(writer) => {
let mut hash = ~LinearMap();
let mut hash = ~LinearMap::new();

for c.sources.each |k, v| {
let mut chash = ~LinearMap();
let mut chash = ~LinearMap::new();

chash.insert(~"url", json::String(v.url));
chash.insert(~"method", json::String(v.method));
Expand Down
5 changes: 5 additions & 0 deletions src/libcore/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];

use option::Option;

pub trait Container {
/// Return the number of elements in the container
pure fn len(&self) -> uint;
Expand All @@ -39,6 +41,9 @@ pub trait Map<K, V>: Mutable {
/// Visit all values
pure fn each_value(&self, f: fn(&V) -> bool);

/// Return the value corresponding to the key in the map
pure fn find(&self, key: &K) -> Option<&self/V>;

/// Insert a key-value pair into the map. An existing value for a
/// key is replaced by the new value. Return true if the key did
/// not already exist in the map.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub mod dvec_iter;
pub mod dlist;
#[path="iter-trait.rs"] #[merge = "iter-trait/dlist.rs"]
pub mod dlist_iter;
pub mod send_map;
pub mod hashmap;


/* Tasks and communication */
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use io;
use libc::{size_t, uintptr_t};
use option::{None, Option, Some};
use ptr;
use send_map::linear::LinearSet;
use hashmap::linear::LinearSet;
use stackwalk;
use sys;

Expand Down
Loading