Skip to content

Move treemap libextra to libstd #10496

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 1 addition & 83 deletions src/libextra/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,86 +37,4 @@ pub trait Deque<T> : Mutable {

/// Remove the first element and return it, or None if the sequence is empty
fn pop_front(&mut self) -> Option<T>;
}

#[cfg(test)]
pub mod bench {
use std::container::MutableMap;
use std::{vec, rand};
use std::rand::Rng;
use test::BenchHarness;

pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
// setup
let mut rng = rand::XorShiftRng::new();

map.clear();
for _ in range(0, n) {
map.insert(rng.gen::<uint>() % n, 1);
}

// measure
do bh.iter {
let k = rng.gen::<uint>() % n;
map.insert(k, 1);
map.remove(&k);
}
}

pub fn insert_seq_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
// setup
map.clear();
for i in range(0u, n) {
map.insert(i*2, 1);
}

// measure
let mut i = 1;
do bh.iter {
map.insert(i, 1);
map.remove(&i);
i = (i + 2) % n;
}
}

pub fn find_rand_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
// setup
let mut rng = rand::XorShiftRng::new();
let mut keys = vec::from_fn(n, |_| rng.gen::<uint>() % n);

for k in keys.iter() {
map.insert(*k, 1);
}

rng.shuffle_mut(keys);

// measure
let mut i = 0;
do bh.iter {
map.find(&(keys[i]));
i = (i + 1) % n;
}
}

pub fn find_seq_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
// setup
for i in range(0u, n) {
map.insert(i, 1);
}

// measure
let mut i = 0;
do bh.iter {
map.find(&i);
i = (i + 1) % n;
}
}
}
}
4 changes: 2 additions & 2 deletions src/libextra/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use std::io::mem::MemWriter;
use std::num;
use std::str;
use std::to_str;
use std::treemap::TreeMap;

use serialize::Encodable;
use serialize;
use treemap::TreeMap;

/// Represents a json value
#[deriving(Clone, Eq)]
Expand Down Expand Up @@ -1312,8 +1312,8 @@ mod tests {
use super::*;

use std::io;
use std::treemap::TreeMap;
use serialize::Decodable;
use treemap::TreeMap;

#[deriving(Eq, Encodable, Decodable)]
enum Animal {
Expand Down
1 change: 0 additions & 1 deletion src/libextra/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ pub mod smallintmap;
pub mod sort;

pub mod dlist;
pub mod treemap;
pub mod btree;

// And ... other stuff
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use std::at_vec;
use std::hashmap::{HashMap, HashSet};
use std::trie::{TrieMap, TrieSet};
use std::vec;
use std::treemap::{TreeMap, TreeSet};
use ringbuf::RingBuf;
use container::Deque;
use dlist::DList;
use treemap::{TreeMap, TreeSet};

pub trait Encoder {
// Primitive types:
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/smallintmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ mod bench {

use super::*;
use test::BenchHarness;
use container::bench::*;
use std::container::bench::*;

// Find seq
#[bench]
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use stats::Stats;
use stats;
use term;
use time::precise_time_ns;
use treemap::TreeMap;

use std::treemap::TreeMap;
use std::clone::Clone;
use std::comm::{stream, SharedChan, GenericPort, GenericChan};
use std::io;
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/workcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use json;
use json::ToJson;
use serialize::{Encoder, Encodable, Decoder, Decodable};
use arc::{Arc,RWArc};
use treemap::TreeMap;
use std::treemap::TreeMap;
use std::cell::Cell;
use std::comm::{PortOne, oneshot};
use std::{str, task};
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
// "crate": { parsed crate ... },
// "plugins": { output of plugins ... }
// }
let mut json = ~extra::treemap::TreeMap::new();
let mut json = ~std::treemap::TreeMap::new();
json.insert(~"schema", json::String(SCHEMA_VERSION.to_owned()));
let plugins_json = ~res.move_iter().filter_map(|opt| opt).collect();

Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub use path_util::default_workspace;
pub use source_control::{safe_git_clone, git_clone_url};

use std::run;
use std::treemap::TreeMap;
use extra::arc::{Arc,RWArc};
use extra::workcache;
use extra::workcache::{Database, Logger, FreshnessMap};
use extra::treemap::TreeMap;

// A little sad -- duplicated from rustc::back::*
#[cfg(target_arch = "arm")]
Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/package_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use package_id::PkgId;
use std::io;
use std::io::fs;
use std::os;
use std::treemap::TreeMap;
use context::*;
use crate::Crate;
use messages::*;
Expand All @@ -26,7 +27,6 @@ use util::{compile_crate, DepMap};
use workcache_support;
use workcache_support::{digest_only_date, digest_file_with_date, crate_tag};
use extra::workcache;
use extra::treemap::TreeMap;

// An enumeration of the unpacked source of a package workspace.
// This contains a list of files found in the source workspace.
Expand Down
4 changes: 2 additions & 2 deletions src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ use std::io::fs;
use std::io::File;
use std::io::process;
use std::io::process::ProcessExit;
use std::treemap::TreeMap;
use std::run::ProcessOutput;
use extra::arc::Arc;
use extra::arc::RWArc;
use extra::tempfile::TempDir;
use extra::workcache;
use extra::workcache::{Database, Logger};
use extra::treemap::TreeMap;
use extra::getopts::groups::getopts;
use std::run::ProcessOutput;
use installed_packages::list_installed_packages;
use package_id::{PkgId};
use version::{ExactRevision, NoVersion, Version, Tagged};
Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::libc;
use std::os;
use std::io;
use std::io::fs;
use std::treemap::TreeMap;
use extra::workcache;
use rustc::driver::{driver, session};
use extra::getopts::groups::getopts;
Expand All @@ -33,7 +34,6 @@ use path_util::{system_library, target_build_dir};
use path_util::{default_workspace, built_library_in_workspace};
pub use target::{OutputType, Main, Lib, Bench, Test, JustOne, lib_name_of, lib_crate_filename};
pub use target::{Target, Build, Install};
use extra::treemap::TreeMap;
pub use target::{lib_name_of, lib_crate_filename, WhatToBuild, MaybeCustom, Inferred};
use workcache_support::{digest_file_with_date, digest_only_date};
use messages::error;
Expand Down
86 changes: 86 additions & 0 deletions src/libstd/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,89 @@ pub trait MutableSet<T>: Set<T> + Mutable {
/// present in the set.
fn remove(&mut self, value: &T) -> bool;
}

#[cfg(test)]
pub mod bench {
use super::MutableMap;
use iter::*;
use vec;
use vec::ImmutableVector;
use rand;
use rand::Rng;
use option::{None, Some};
use extra::test::BenchHarness;

pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
// setup
let mut rng = rand::XorShiftRng::new();

map.clear();
for _ in range(0, n) {
map.insert(rng.gen::<uint>() % n, 1);
}

// measure
do bh.iter {
let k = rng.gen::<uint>() % n;
map.insert(k, 1);
map.remove(&k);
}
}

pub fn insert_seq_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
// setup
map.clear();
for i in range(0u, n) {
map.insert(i*2, 1);
}

// measure
let mut i = 1;
do bh.iter {
map.insert(i, 1);
map.remove(&i);
i = (i + 2) % n;
}
}

pub fn find_rand_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
// setup
let mut rng = rand::XorShiftRng::new();
let mut keys = vec::from_fn(n, |_| rng.gen::<uint>() % n);

for k in keys.iter() {
map.insert(*k, 1);
}

rng.shuffle_mut(keys);

// measure
let mut i = 0;
do bh.iter {
map.find(&(keys[i]));
i = (i + 1) % n;
}
}

pub fn find_seq_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
// setup
for i in range(0u, n) {
map.insert(i, 1);
}

// measure
let mut i = 0;
do bh.iter {
map.find(&i);
i = (i + 1) % n;
}
}
}
5 changes: 5 additions & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ pub mod mem;
pub mod unstable;


// others
pub mod treemap;


/* For internal use, not exported */

mod unicode;
Expand Down Expand Up @@ -232,4 +236,5 @@ mod std {
pub use to_bytes;
pub use to_str;
pub use unstable;
pub use container; // for smalltreemap bench test
}
2 changes: 1 addition & 1 deletion src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ mod tests {
}
}

#[test]
#[test] #[ignore]
fn memory_map_file() {
use result::{Ok, Err};
use os::*;
Expand Down
24 changes: 17 additions & 7 deletions src/libextra/treemap.rs → src/libstd/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
//! `TotalOrd`.


use std::util::{swap, replace};
use std::iter::{Peekable};
use std::cmp::Ordering;
use container::{Container, Mutable, MutableMap, Set, MutableSet, Map};
use util::{swap, replace};
use cmp::{Ordering, TotalOrd, Eq, Ord, Greater, Less, Equal};
use option::{Option, None, Some};
use iter::{Peekable, Extendable, Iterator, FromIterator};
use vec::{ImmutableVector, MutableVector, OwnedVector};

// This is implemented as an AA tree, which is a simplified variation of
// a red-black tree where red (horizontal) nodes can only be added
Expand Down Expand Up @@ -882,9 +885,15 @@ impl<T: TotalOrd> Extendable<T> for TreeSet<T> {
mod test_treemap {

use super::*;
use iter::*;

use std::rand::Rng;
use std::rand;
use rand::Rng;
use rand;
use option::{Option, None, Some};
use cmp::{TotalOrd, Eq, Greater, Less};
use str::StrSlice;
use clone::Clone;
use num::Times;

#[test]
fn find_empty() {
Expand Down Expand Up @@ -1239,8 +1248,8 @@ mod test_treemap {
#[cfg(test)]
mod bench {

use super::*;
use test::BenchHarness;
use super::TreeMap;
use extra::test::BenchHarness;
use container::bench::*;

// Find seq
Expand Down Expand Up @@ -1300,6 +1309,7 @@ mod bench {
mod test_set {

use super::*;
use option::{Option, None, Some};

#[test]
fn test_clear() {
Expand Down
Loading