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 \
uuid serialize sync getopts
uuid serialize sync getopts collections
HOST_CRATES := syntax rustc rustdoc
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc
DEPS_std := native:rustrt
DEPS_extra := std term sync serialize getopts
DEPS_extra := std term sync serialize getopts collections
DEPS_green := std
DEPS_rustuv := std native:uv native:uv_support
DEPS_native := std
DEPS_syntax := std extra term serialize
DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts
DEPS_rustdoc := rustc native:sundown serialize sync getopts
DEPS_syntax := std extra term serialize collections
DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts \
collections
DEPS_rustdoc := rustc native:sundown serialize sync getopts collections
DEPS_flate := std native:miniz
DEPS_arena := std extra
DEPS_arena := std collections
DEPS_glob := std
DEPS_serialize := std
DEPS_term := std
@ -72,6 +73,7 @@ DEPS_semver := std
DEPS_uuid := std serialize
DEPS_sync := std
DEPS_getopts := std
DEPS_collections := std serialize
TOOL_DEPS_compiletest := extra green rustuv getopts
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 `arena` allocation library](arena/index.html)
* [The `collections` library](collections/index.html)
* [The `flate` compression library](flate/index.html)
* [The `getopts` argument parsing library](getopts/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 {
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 self::baz::foobaz; // good: self refers to module 'foo'
use foo::bar::foobar; // good: foo is at crate root

View File

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

View File

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

View File

@ -28,7 +28,7 @@ use std::util;
use std::iter::Rev;
use std::iter;
use container::Deque;
use deque::Deque;
use serialize::{Encodable, Decodable, Encoder, Decoder};
@ -657,7 +657,7 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for DList<T> {
#[cfg(test)]
mod tests {
use container::Deque;
use deque::Deque;
use extra::test;
use std::rand;
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)]
mod tests {
use list::*;
use list::{List, Nil, from_vec, head, is_empty, tail};
use list;
use std::option;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -38,6 +38,8 @@ extern mod sync;
#[cfg(not(stage0))]
extern mod serialize;
extern mod collections;
#[cfg(stage0)]
pub mod serialize {
#[allow(missing_doc)];
@ -47,29 +49,10 @@ pub mod serialize {
EncoderHelpers, DecoderHelpers};
}
#[cfg(stage0)]
macro_rules! if_ok (
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
)
// Utility modules
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
pub mod url;

View File

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

View File

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

View File

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

View File

@ -56,7 +56,7 @@ use std::u16;
use std::u32;
use std::u64;
use std::u8;
use extra::smallintmap::SmallIntMap;
use collections::SmallIntMap;
use syntax::ast_map;
use syntax::ast_util::IdVisitingOperation;
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_rvar};
use extra::smallintmap::SmallIntMap;
use collections::SmallIntMap;
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, Vid};
use middle::ty;
use middle::ty_fold;

View File

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

View File

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

View File

@ -21,6 +21,7 @@ extern mod extra;
extern mod serialize;
extern mod sync;
extern mod getopts;
extern mod collections;
use std::local_data;
use std::io;
@ -326,7 +327,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson],
// "crate": { parsed crate ... },
// "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()));
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::cell::RefCell;
use extra::smallintmap::SmallIntMap;
use collections::SmallIntMap;
#[deriving(Clone, Eq)]
pub enum PathElem {

View File

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

View File

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

View File

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

View File

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

View File

@ -11,8 +11,9 @@
#[feature(managed_boxes)];
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 std::os;
use std::task;

View File

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

View File

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

View File

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

View File

@ -12,9 +12,9 @@
#[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 {
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
// except according to those terms.
extern mod extra;
extern mod collections;
use std::clone::{Clone, DeepClone};
use std::cmp::{TotalEq, Ord, TotalOrd, Equiv};
@ -18,7 +18,7 @@ use std::default::Default;
use std::send_str::{SendStr, SendStrOwned, SendStrStatic};
use std::str::Str;
use std::to_str::ToStr;
use self::extra::treemap::TreeMap;
use self::collections::TreeMap;
use std::option::Some;
pub fn main() {