auto merge of #12010 : HeroesGrave/rust/libcollection, r=alexcrichton

Part of #8784

Changes:
- Everything labeled under collections in libextra has been moved into a new crate 'libcollection'.
- Renamed container.rs to deque.rs, since it was no longer 'container traits for extra', just a deque trait.
- Crates that depend on the collections have been updated and dependencies sorted.
- I think I changed all the imports in the tests to make sure it works. I'm not entirely sure, as near the end of the tests there was yet another `use` that I forgot to change, and when I went to try again, it started rebuilding everything, which I don't currently have time for. 

There will probably be incompatibility between this and the other pull requests that are splitting up libextra. I'm happy to rebase once those have been merged.

The tests I didn't get to run should pass. But I can redo them another time if they don't.
This commit is contained in:
bors 2014-02-06 23:46:35 -08:00
commit 21b856d2dc
36 changed files with 117 additions and 72 deletions

View File

@ -50,21 +50,22 @@
################################################################################ ################################################################################
TARGET_CRATES := std extra green rustuv native flate arena glob term semver \ TARGET_CRATES := std extra green rustuv native flate arena glob term semver \
uuid serialize sync getopts uuid serialize sync getopts collections
HOST_CRATES := syntax rustc rustdoc HOST_CRATES := syntax rustc rustdoc
CRATES := $(TARGET_CRATES) $(HOST_CRATES) CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc TOOLS := compiletest rustdoc rustc
DEPS_std := native:rustrt DEPS_std := native:rustrt
DEPS_extra := std term sync serialize getopts DEPS_extra := std term sync serialize getopts collections
DEPS_green := std DEPS_green := std
DEPS_rustuv := std native:uv native:uv_support DEPS_rustuv := std native:uv native:uv_support
DEPS_native := std DEPS_native := std
DEPS_syntax := std extra term serialize DEPS_syntax := std extra term serialize collections
DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts \
DEPS_rustdoc := rustc native:sundown serialize sync getopts collections
DEPS_rustdoc := rustc native:sundown serialize sync getopts collections
DEPS_flate := std native:miniz DEPS_flate := std native:miniz
DEPS_arena := std extra DEPS_arena := std collections
DEPS_glob := std DEPS_glob := std
DEPS_serialize := std DEPS_serialize := std
DEPS_term := std DEPS_term := std
@ -72,6 +73,7 @@ DEPS_semver := std
DEPS_uuid := std serialize DEPS_uuid := std serialize
DEPS_sync := std DEPS_sync := std
DEPS_getopts := std DEPS_getopts := std
DEPS_collections := std serialize
TOOL_DEPS_compiletest := extra green rustuv getopts TOOL_DEPS_compiletest := extra green rustuv getopts
TOOL_DEPS_rustdoc := rustdoc green rustuv TOOL_DEPS_rustdoc := rustdoc green rustuv

View File

@ -38,6 +38,7 @@ li {list-style-type: none; }
* [The Rust compiler, `librustc`](rustc/index.html) * [The Rust compiler, `librustc`](rustc/index.html)
* [The `arena` allocation library](arena/index.html) * [The `arena` allocation library](arena/index.html)
* [The `collections` library](collections/index.html)
* [The `flate` compression library](flate/index.html) * [The `flate` compression library](flate/index.html)
* [The `getopts` argument parsing library](getopts/index.html) * [The `getopts` argument parsing library](getopts/index.html)
* [The `glob` file path matching library](glob/index.html) * [The `glob` file path matching library](glob/index.html)

View File

@ -881,7 +881,7 @@ use foo::baz::foobaz; // good: foo is at the root of the crate
mod foo { mod foo {
extern mod extra; extern mod extra;
use foo::extra::list; // good: foo is at crate root use foo::extra::time; // good: foo is at crate root
// use extra::*; // bad: extra is not at the crate root // use extra::*; // bad: extra is not at the crate root
use self::baz::foobaz; // good: self refers to module 'foo' use self::baz::foobaz; // good: self refers to module 'foo'
use foo::bar::foobar; // good: foo is at crate root use foo::bar::foobar; // good: foo is at crate root

View File

@ -22,10 +22,12 @@
#[allow(missing_doc)]; #[allow(missing_doc)];
#[feature(managed_boxes)]; #[feature(managed_boxes)];
extern mod extra; extern mod collections;
use extra::list::{List, Cons, Nil}; #[cfg(test)] extern mod extra;
use extra::list;
use collections::list::{List, Cons, Nil};
use collections::list;
use std::cast::{transmute, transmute_mut, transmute_mut_region}; use std::cast::{transmute, transmute_mut, transmute_mut_region};
use std::cast; use std::cast;

View File

@ -44,7 +44,7 @@ pub mod bench {
use std::container::MutableMap; use std::container::MutableMap;
use std::{vec, rand}; use std::{vec, rand};
use std::rand::Rng; use std::rand::Rng;
use test::BenchHarness; use extra::test::BenchHarness;
pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint, pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M, map: &mut M,

View File

@ -28,7 +28,7 @@ use std::util;
use std::iter::Rev; use std::iter::Rev;
use std::iter; use std::iter;
use container::Deque; use deque::Deque;
use serialize::{Encodable, Decodable, Encoder, Decoder}; use serialize::{Encodable, Decodable, Encoder, Decoder};
@ -657,7 +657,7 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for DList<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use container::Deque; use deque::Deque;
use extra::test; use extra::test;
use std::rand; use std::rand;
use super::{DList, Node, ListInsertion}; use super::{DList, Node, ListInsertion};

46
src/libcollections/lib.rs Normal file
View File

@ -0,0 +1,46 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/*!
* Collection types.
*/
#[crate_id = "collections#0.10-pre"];
#[crate_type = "rlib"];
#[crate_type = "dylib"];
#[license = "MIT/ASL2"];
#[feature(macro_rules, managed_boxes)];
#[cfg(test)] extern mod extra;
extern mod serialize;
pub use bitv::Bitv;
pub use btree::BTree;
pub use deque::Deque;
pub use dlist::DList;
pub use list::List;
pub use lru_cache::LruCache;
pub use priority_queue::PriorityQueue;
pub use ringbuf::RingBuf;
pub use smallintmap::SmallIntMap;
pub use treemap::{TreeMap, TreeSet};
pub mod bitv;
pub mod btree;
pub mod deque;
pub mod dlist;
pub mod list;
pub mod lru_cache;
pub mod priority_queue;
pub mod ringbuf;
pub mod smallintmap;
pub mod treemap;

View File

@ -153,7 +153,7 @@ pub fn each<T>(l: @List<T>, f: |&T| -> bool) -> bool {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use list::*; use list::{List, Nil, from_vec, head, is_empty, tail};
use list; use list;
use std::option; use std::option;

View File

@ -17,7 +17,7 @@
//! # Example //! # Example
//! //!
//! ```rust //! ```rust
//! use extra::lru_cache::LruCache; //! use collections::LruCache;
//! //!
//! let mut cache: LruCache<int, int> = LruCache::new(2); //! let mut cache: LruCache<int, int> = LruCache::new(2);
//! cache.put(1, 10); //! cache.put(1, 10);

View File

@ -17,7 +17,7 @@ use std::num;
use std::vec; use std::vec;
use std::iter::{Rev, RandomAccessIterator}; use std::iter::{Rev, RandomAccessIterator};
use container::Deque; use deque::Deque;
use serialize::{Encodable, Decodable, Encoder, Decoder}; use serialize::{Encodable, Decodable, Encoder, Decoder};
@ -431,7 +431,7 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for RingBuf<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use container::Deque; use deque::Deque;
use extra::test; use extra::test;
use std::clone::Clone; use std::clone::Clone;
use std::cmp::Eq; use std::cmp::Eq;

View File

@ -471,9 +471,9 @@ mod test_map {
#[cfg(test)] #[cfg(test)]
mod bench { mod bench {
use super::*; use super::SmallIntMap;
use test::BenchHarness; use extra::test::BenchHarness;
use container::bench::*; use deque::bench::{insert_rand_n, insert_seq_n, find_rand_n, find_seq_n};
// Find seq // Find seq
#[bench] #[bench]

View File

@ -1495,9 +1495,9 @@ mod test_treemap {
#[cfg(test)] #[cfg(test)]
mod bench { mod bench {
use super::*; use super::TreeMap;
use test::BenchHarness; use extra::test::BenchHarness;
use container::bench::*; use deque::bench::{insert_rand_n, insert_seq_n, find_rand_n, find_seq_n};
// Find seq // Find seq
#[bench] #[bench]
@ -1555,7 +1555,7 @@ mod bench {
#[cfg(test)] #[cfg(test)]
mod test_set { mod test_set {
use super::*; use super::{TreeMap, TreeSet};
#[test] #[test]
fn test_clear() { fn test_clear() {

View File

@ -98,9 +98,11 @@ A basic `ToJson` example using a TreeMap of attribute name / attribute value:
```rust ```rust
extern mod collections;
use extra::json; use extra::json;
use extra::json::ToJson; use extra::json::ToJson;
use extra::treemap::TreeMap; use collections::TreeMap;
pub struct MyStruct { pub struct MyStruct {
attr1: u8, attr1: u8,
@ -185,10 +187,12 @@ Example of `ToJson` trait implementation for TestStruct1.
```rust ```rust
extern mod serialize; extern mod serialize;
extern mod collections;
use extra::json; use extra::json;
use extra::json::ToJson; use extra::json::ToJson;
use serialize::{Encodable, Decodable}; use serialize::{Encodable, Decodable};
use extra::treemap::TreeMap; use collections::TreeMap;
#[deriving(Decodable, Encodable)] // generate Decodable, Encodable impl. #[deriving(Decodable, Encodable)] // generate Decodable, Encodable impl.
pub struct TestStruct1 { pub struct TestStruct1 {
@ -236,7 +240,7 @@ use std::to_str;
use serialize::Encodable; use serialize::Encodable;
use serialize; use serialize;
use treemap::TreeMap; use collections::TreeMap;
macro_rules! if_ok( ($e:expr) => ( macro_rules! if_ok( ($e:expr) => (
match $e { Ok(e) => e, Err(e) => { self.error = Err(e); return } } match $e { Ok(e) => e, Err(e) => { self.error = Err(e); return } }
@ -1588,7 +1592,7 @@ mod tests {
use std::io; use std::io;
use serialize::{Encodable, Decodable}; use serialize::{Encodable, Decodable};
use treemap::TreeMap; use collections::TreeMap;
#[deriving(Eq, Encodable, Decodable)] #[deriving(Eq, Encodable, Decodable)]
enum Animal { enum Animal {

View File

@ -38,6 +38,8 @@ extern mod sync;
#[cfg(not(stage0))] #[cfg(not(stage0))]
extern mod serialize; extern mod serialize;
extern mod collections;
#[cfg(stage0)] #[cfg(stage0)]
pub mod serialize { pub mod serialize {
#[allow(missing_doc)]; #[allow(missing_doc)];
@ -47,29 +49,10 @@ pub mod serialize {
EncoderHelpers, DecoderHelpers}; EncoderHelpers, DecoderHelpers};
} }
#[cfg(stage0)]
macro_rules! if_ok (
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
)
// Utility modules // Utility modules
pub mod c_vec; pub mod c_vec;
// Collections
pub mod container;
pub mod bitv;
pub mod list;
pub mod ringbuf;
pub mod priority_queue;
pub mod smallintmap;
pub mod dlist;
pub mod treemap;
pub mod btree;
pub mod lru_cache;
// And ... other stuff // And ... other stuff
pub mod url; pub mod url;

View File

@ -24,7 +24,7 @@ use serialize::Decodable;
use stats::Stats; use stats::Stats;
use stats; use stats;
use time::precise_time_ns; use time::precise_time_ns;
use treemap::TreeMap; use collections::TreeMap;
use std::clone::Clone; use std::clone::Clone;
use std::io; use std::io;

View File

@ -14,7 +14,7 @@ use json;
use json::ToJson; use json::ToJson;
use serialize::{Encoder, Encodable, Decoder, Decodable}; use serialize::{Encoder, Encodable, Decoder, Decodable};
use sync::{Arc,RWArc}; use sync::{Arc,RWArc};
use treemap::TreeMap; use collections::TreeMap;
use std::str; use std::str;
use std::io; use std::io;
use std::io::{File, MemWriter}; use std::io::{File, MemWriter};

View File

@ -38,6 +38,7 @@ extern mod syntax;
extern mod serialize; extern mod serialize;
extern mod sync; extern mod sync;
extern mod getopts; extern mod getopts;
extern mod collections;
use back::link; use back::link;
use driver::session; use driver::session;

View File

@ -56,7 +56,7 @@ use std::u16;
use std::u32; use std::u32;
use std::u64; use std::u64;
use std::u8; use std::u8;
use extra::smallintmap::SmallIntMap; use collections::SmallIntMap;
use syntax::ast_map; use syntax::ast_map;
use syntax::ast_util::IdVisitingOperation; use syntax::ast_util::IdVisitingOperation;
use syntax::attr::{AttrMetaMethods, AttributeMethods}; use syntax::attr::{AttrMetaMethods, AttributeMethods};

View File

@ -20,7 +20,7 @@ pub use middle::typeck::infer::resolve::{resolve_ivar, resolve_all};
pub use middle::typeck::infer::resolve::{resolve_nested_tvar}; pub use middle::typeck::infer::resolve::{resolve_nested_tvar};
pub use middle::typeck::infer::resolve::{resolve_rvar}; pub use middle::typeck::infer::resolve::{resolve_rvar};
use extra::smallintmap::SmallIntMap; use collections::SmallIntMap;
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, Vid}; use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, Vid};
use middle::ty; use middle::ty;
use middle::ty_fold; use middle::ty_fold;

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use extra::smallintmap::SmallIntMap; use collections::SmallIntMap;
use middle::ty::{Vid, expected_found, IntVarValue}; use middle::ty::{Vid, expected_found, IntVarValue};
use middle::ty; use middle::ty;

View File

@ -71,8 +71,8 @@ use util::ppaux;
use std::cell::RefCell; use std::cell::RefCell;
use std::hashmap::HashMap; use std::hashmap::HashMap;
use std::rc::Rc; use std::rc::Rc;
use extra::list::List; use collections::List;
use extra::list; use collections::list;
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::print::pprust::*; use syntax::print::pprust::*;
use syntax::{ast, ast_map, abi}; use syntax::{ast, ast_map, abi};

View File

@ -21,6 +21,7 @@ extern mod extra;
extern mod serialize; extern mod serialize;
extern mod sync; extern mod sync;
extern mod getopts; extern mod getopts;
extern mod collections;
use std::local_data; use std::local_data;
use std::io; use std::io;
@ -326,7 +327,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson],
// "crate": { parsed crate ... }, // "crate": { parsed crate ... },
// "plugins": { output of plugins ... } // "plugins": { output of plugins ... }
// } // }
let mut json = ~extra::treemap::TreeMap::new(); let mut json = ~collections::TreeMap::new();
json.insert(~"schema", json::String(SCHEMA_VERSION.to_owned())); json.insert(~"schema", json::String(SCHEMA_VERSION.to_owned()));
let plugins_json = ~res.move_iter().filter_map(|opt| opt).collect(); let plugins_json = ~res.move_iter().filter_map(|opt| opt).collect();

View File

@ -22,7 +22,7 @@ use util::small_vector::SmallVector;
use std::logging; use std::logging;
use std::cell::RefCell; use std::cell::RefCell;
use extra::smallintmap::SmallIntMap; use collections::SmallIntMap;
#[deriving(Clone, Eq)] #[deriving(Clone, Eq)]
pub enum PathElem { pub enum PathElem {

View File

@ -35,6 +35,7 @@ This API is completely unstable and subject to change.
extern mod extra; extern mod extra;
extern mod serialize; extern mod serialize;
extern mod term; extern mod term;
extern mod collections;
pub mod util { pub mod util {
pub mod interner; pub mod interner;

View File

@ -9,9 +9,10 @@
// except according to those terms. // except according to those terms.
extern mod extra; extern mod extra;
extern mod collections;
use extra::time; use extra::time;
use extra::treemap::TreeMap; use collections::TreeMap;
use std::hashmap::{HashMap, HashSet}; use std::hashmap::{HashMap, HashSet};
use std::os; use std::os;
use std::rand::{Rng, IsaacRng, SeedableRng}; use std::rand::{Rng, IsaacRng, SeedableRng};

View File

@ -11,9 +11,10 @@
// except according to those terms. // except according to those terms.
extern mod extra; extern mod extra;
extern mod collections;
use extra::bitv::BitvSet; use collections::bitv::BitvSet;
use extra::treemap::TreeSet; use collections::TreeSet;
use std::hashmap::HashSet; use std::hashmap::HashSet;
use std::os; use std::os;
use std::rand; use std::rand;

View File

@ -11,8 +11,9 @@
// Microbenchmark for the smallintmap library // Microbenchmark for the smallintmap library
extern mod extra; extern mod extra;
extern mod collections;
use extra::smallintmap::SmallIntMap; use collections::SmallIntMap;
use std::os; use std::os;
use std::uint; use std::uint;

View File

@ -11,8 +11,9 @@
#[feature(managed_boxes)]; #[feature(managed_boxes)];
extern mod extra; extern mod extra;
extern mod collections;
use extra::list::{List, Cons, Nil}; use collections::list::{List, Cons, Nil};
use extra::time::precise_time_s; use extra::time::precise_time_s;
use std::os; use std::os;
use std::task; use std::task;

View File

@ -10,8 +10,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
extern mod extra; extern mod collections;
use extra::bitv::Bitv; use collections::Bitv;
fn bitv_test() { fn bitv_test() {
let mut v1 = ~Bitv::new(31, false); let mut v1 = ~Bitv::new(31, false);

View File

@ -10,9 +10,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
extern mod extra; extern mod collections;
use extra::ringbuf::RingBuf; use collections::RingBuf;
use extra::container::Deque; use collections::Deque;
pub fn main() { pub fn main() {
let mut q = RingBuf::new(); let mut q = RingBuf::new();

View File

@ -10,8 +10,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
extern mod extra; extern mod collections;
use extra::list; use collections::list;
#[deriving(Clone)] #[deriving(Clone)]
enum foo { enum foo {

View File

@ -12,9 +12,9 @@
#[feature(managed_boxes)]; #[feature(managed_boxes)];
extern mod extra; extern mod collections;
use extra::list::{List, Cons, Nil, head, is_empty}; use collections::list::{List, Cons, Nil, head, is_empty};
fn pure_length_go<T:Clone>(ls: @List<T>, acc: uint) -> uint { fn pure_length_go<T:Clone>(ls: @List<T>, acc: uint) -> uint {
match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } } match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } }

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
extern mod extra; extern mod collections;
use std::clone::{Clone, DeepClone}; use std::clone::{Clone, DeepClone};
use std::cmp::{TotalEq, Ord, TotalOrd, Equiv}; use std::cmp::{TotalEq, Ord, TotalOrd, Equiv};
@ -18,7 +18,7 @@ use std::default::Default;
use std::send_str::{SendStr, SendStrOwned, SendStrStatic}; use std::send_str::{SendStr, SendStrOwned, SendStrStatic};
use std::str::Str; use std::str::Str;
use std::to_str::ToStr; use std::to_str::ToStr;
use self::extra::treemap::TreeMap; use self::collections::TreeMap;
use std::option::Some; use std::option::Some;
pub fn main() { pub fn main() {