This is mostly just a cosmetic change, continuing the work from #14333.
use core::uint;
use std::hash;
+use {Collection, Mutable, Set, MutableSet};
use vec::Vec;
#[deriving(Clone)]
}
}
-impl Container for BitvSet {
+impl Collection for BitvSet {
#[inline]
fn len(&self) -> uint { self.size }
}
use std::rand::Rng;
use test::Bencher;
+ use {Set, Mutable, MutableSet};
use bitv::{Bitv, SmallBitv, BigBitv, BitvSet, from_bools, from_fn,
from_bytes};
use bitv;
use core::fmt;
use core::fmt::Show;
+use Collection;
use vec::Vec;
#[allow(missing_doc)]
//! Container traits for collections
-use core::prelude::*;
-
-/// A double-ended sequence that allows querying, insertion and deletion at both ends.
-pub trait Deque<T> : Mutable {
- /// Provide a reference to the front element, or None if the sequence is empty
- fn front<'a>(&'a self) -> Option<&'a T>;
-
- /// Provide a mutable reference to the front element, or None if the sequence is empty
- fn front_mut<'a>(&'a mut self) -> Option<&'a mut T>;
-
- /// Provide a reference to the back element, or None if the sequence is empty
- fn back<'a>(&'a self) -> Option<&'a T>;
-
- /// Provide a mutable reference to the back element, or None if the sequence is empty
- fn back_mut<'a>(&'a mut self) -> Option<&'a mut T>;
-
- /// Insert an element first in the sequence
- fn push_front(&mut self, elt: T);
-
- /// Insert an element last in the sequence
- fn push_back(&mut self, elt: T);
-
- /// Remove the last element and return it, or None if the sequence is empty
- fn pop_back(&mut self) -> Option<T>;
-
- /// 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::prelude::*;
use std::rand;
use std::rand::Rng;
use test::Bencher;
+ use MutableMap;
pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
})
}
}
+
//! The DList allows pushing and popping elements at either end.
//!
//! DList implements the trait Deque. It should be imported with `use
-//! collections::deque::Deque`.
+//! collections::Deque`.
// DList is constructed like a singly-linked list over the field `next`.
// including the last link being None; each Node owns its `next` field.
use core::mem;
use core::ptr;
-use deque::Deque;
+use {Collection, Mutable, Deque};
/// A doubly-linked list.
pub struct DList<T> {
Some(next)
}
-impl<T> Container for DList<T> {
+impl<T> Collection for DList<T> {
/// O(1)
#[inline]
fn is_empty(&self) -> bool {
use test::Bencher;
use test;
- use deque::Deque;
+ use Deque;
use super::{DList, Node, ListInsertion};
use vec::Vec;
#[cfg(test)] #[phase(syntax, link)] extern crate std;
#[cfg(test)] #[phase(syntax, link)] extern crate log;
+use core::prelude::*;
+
+pub use core::collections::Collection;
pub use bitv::{Bitv, BitvSet};
pub use btree::BTree;
-pub use deque::Deque;
pub use dlist::DList;
pub use enum_set::EnumSet;
pub use priority_queue::PriorityQueue;
pub mod bitv;
pub mod btree;
-pub mod deque;
pub mod dlist;
pub mod enum_set;
pub mod priority_queue;
// Internal unicode fiddly bits for the str module
mod unicode;
-// FIXME(#14008) should this actually exist, or should a method be added?
-fn expect<T>(a: core::option::Option<T>, b: &str) -> T {
- match a {
- core::option::Some(a) => a,
- core::option::None => fail!("{}", b),
+mod deque;
+
+/// A trait to represent mutable containers
+pub trait Mutable: Collection {
+ /// Clear the container, removing all values.
+ fn clear(&mut self);
+}
+
+/// A map is a key-value store where values may be looked up by their keys. This
+/// trait provides basic operations to operate on these stores.
+pub trait Map<K, V>: Collection {
+ /// Return a reference to the value corresponding to the key
+ fn find<'a>(&'a self, key: &K) -> Option<&'a V>;
+
+ /// Return true if the map contains a value for the specified key
+ #[inline]
+ fn contains_key(&self, key: &K) -> bool {
+ self.find(key).is_some()
+ }
+}
+
+/// This trait provides basic operations to modify the contents of a map.
+pub trait MutableMap<K, V>: Map<K, V> + Mutable {
+ /// 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.
+ #[inline]
+ fn insert(&mut self, key: K, value: V) -> bool {
+ self.swap(key, value).is_none()
+ }
+
+ /// Remove a key-value pair from the map. Return true if the key
+ /// was present in the map, otherwise false.
+ #[inline]
+ fn remove(&mut self, key: &K) -> bool {
+ self.pop(key).is_some()
+ }
+
+ /// Insert a key-value pair from the map. If the key already had a value
+ /// present in the map, that value is returned. Otherwise None is returned.
+ fn swap(&mut self, k: K, v: V) -> Option<V>;
+
+ /// Removes a key from the map, returning the value at the key if the key
+ /// was previously in the map.
+ fn pop(&mut self, k: &K) -> Option<V>;
+
+ /// Return a mutable reference to the value corresponding to the key
+ fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>;
+}
+
+/// A set is a group of objects which are each distinct from one another. This
+/// trait represents actions which can be performed on sets to iterate over
+/// them.
+pub trait Set<T>: Collection {
+ /// Return true if the set contains a value
+ fn contains(&self, value: &T) -> bool;
+
+ /// Return true if the set has no elements in common with `other`.
+ /// This is equivalent to checking for an empty intersection.
+ fn is_disjoint(&self, other: &Self) -> bool;
+
+ /// Return true if the set is a subset of another
+ fn is_subset(&self, other: &Self) -> bool;
+
+ /// Return true if the set is a superset of another
+ fn is_superset(&self, other: &Self) -> bool {
+ other.is_subset(self)
}
+
+ // FIXME #8154: Add difference, sym. difference, intersection and union iterators
+}
+
+/// This trait represents actions which can be performed on sets to mutate
+/// them.
+pub trait MutableSet<T>: Set<T> + Mutable {
+ /// Add a value to the set. Return true if the value was not already
+ /// present in the set.
+ fn insert(&mut self, value: T) -> bool;
+
+ /// Remove a value from the set. Return true if the value was
+ /// present in the set.
+ fn remove(&mut self, value: &T) -> bool;
+}
+
+/// A double-ended sequence that allows querying, insertion and deletion at both
+/// ends.
+pub trait Deque<T> : Mutable {
+ /// Provide a reference to the front element, or None if the sequence is
+ /// empty
+ fn front<'a>(&'a self) -> Option<&'a T>;
+
+ /// Provide a mutable reference to the front element, or None if the
+ /// sequence is empty
+ fn front_mut<'a>(&'a mut self) -> Option<&'a mut T>;
+
+ /// Provide a reference to the back element, or None if the sequence is
+ /// empty
+ fn back<'a>(&'a self) -> Option<&'a T>;
+
+ /// Provide a mutable reference to the back element, or None if the sequence
+ /// is empty
+ fn back_mut<'a>(&'a mut self) -> Option<&'a mut T>;
+
+ /// Insert an element first in the sequence
+ fn push_front(&mut self, elt: T);
+
+ /// Insert an element last in the sequence
+ fn push_back(&mut self, elt: T);
+
+ /// Remove the last element and return it, or None if the sequence is empty
+ fn pop_back(&mut self) -> Option<T>;
+
+ /// Remove the first element and return it, or None if the sequence is empty
+ fn pop_front(&mut self) -> Option<T>;
}
// FIXME(#14344) this shouldn't be necessary
use core::mem::{zeroed, replace, swap};
use core::ptr;
+use {Collection, Mutable};
use slice;
use vec::Vec;
data: Vec<T>,
}
-impl<T: Ord> Container for PriorityQueue<T> {
+impl<T: Ord> Collection for PriorityQueue<T> {
/// Returns the length of the queue
fn len(&self) -> uint { self.data.len() }
}
//! A double-ended queue implemented as a circular buffer
//!
//! RingBuf implements the trait Deque. It should be imported with `use
-//! collections::deque::Deque`.
+//! collections::Deque`.
use core::prelude::*;
use core::fmt;
use core::iter::RandomAccessIterator;
-use deque::Deque;
+use {Deque, Collection, Mutable};
use vec::Vec;
static INITIAL_CAPACITY: uint = 8u; // 2^3
elts: Vec<Option<T>>
}
-impl<T> Container for RingBuf<T> {
+impl<T> Collection for RingBuf<T> {
/// Return the number of elements in the RingBuf
fn len(&self) -> uint { self.nelts }
}
use test::Bencher;
use test;
- use deque::Deque;
+ use {Deque, Mutable};
use super::RingBuf;
use vec::Vec;
use core::mem;
use core::ptr;
use core::iter::{range_step, MultiplicativeIterator};
+
+use Collection;
use vec::Vec;
pub use core::slice::{ref_slice, mut_ref_slice, Splits, Windows};
let len = self.len();
let data_size = len.checked_mul(&mem::size_of::<T>());
- let data_size = ::expect(data_size, "overflow in to_owned()");
+ let data_size = data_size.expect("overflow in to_owned()");
let size = mem::size_of::<RawVec<()>>().checked_add(&data_size);
- let size = ::expect(size, "overflow in to_owned()");
+ let size = size.expect("overflow in to_owned()");
unsafe {
// this should pass the real required alignment
use std::rt;
use slice::*;
+ use Mutable;
use vec::Vec;
fn square(n: uint) -> uint { n * n }
use core::iter::{Enumerate, FilterMap};
use core::mem::replace;
+use {Collection, Mutable, Map, MutableMap};
use {vec, slice};
use vec::Vec;
v: Vec<Option<T>>,
}
-impl<V> Container for SmallIntMap<V> {
+impl<V> Collection for SmallIntMap<V> {
/// Return the number of elements in the map
fn len(&self) -> uint {
self.v.iter().filter(|elt| elt.is_some()).count()
}
pub fn get<'a>(&'a self, key: &uint) -> &'a V {
- ::expect(self.find(key), "key not present")
+ self.find(key).expect("key not present")
}
/// An iterator visiting all key-value pairs in ascending order by the keys.
mod test_map {
use std::prelude::*;
+ use {Map, MutableMap, Mutable};
use super::SmallIntMap;
#[test]
use core::iter::AdditiveIterator;
use core::mem;
+use Collection;
use hash;
use string::String;
use vec::Vec;
}
}
-impl<'a> Container for MaybeOwned<'a> {
+impl<'a> Collection for MaybeOwned<'a> {
#[inline]
fn len(&self) -> uint { self.as_slice().len() }
}
#[test]
fn test_str_container() {
- fn sum_len<S: Container>(v: &[S]) -> uint {
+ fn sum_len<S: Collection>(v: &[S]) -> uint {
v.iter().map(|x| x.len()).sum()
}
use core::ptr;
use core::raw::Slice;
+use {Collection, Mutable};
use hash;
use str;
use str::{CharRange, StrAllocating};
}
}
-impl Container for String {
+impl Collection for String {
#[inline]
fn len(&self) -> uint {
self.vec.len()
use std::prelude::*;
use test::Bencher;
+ use Mutable;
use str::{Str, StrSlice};
use super::String;
use core::mem::{replace, swap};
use core::ptr;
+use {Collection, Mutable, Set, MutableSet, MutableMap, Map};
use vec::Vec;
// This is implemented as an AA tree, which is a simplified variation of
}
}
-impl<K: Ord, V> Container for TreeMap<K, V> {
+impl<K: Ord, V> Collection for TreeMap<K, V> {
fn len(&self) -> uint { self.length }
}
}
}
-impl<T: Ord> Container for TreeSet<T> {
+impl<T: Ord> Collection for TreeSet<T> {
#[inline]
fn len(&self) -> uint { self.map.len() }
}
use std::rand::Rng;
use std::rand;
+ use {Map, MutableMap, Mutable};
use super::{TreeMap, TreeNode};
#[test]
#[cfg(test)]
mod bench {
- use std::prelude::*;
use test::Bencher;
use super::TreeMap;
mod test_set {
use std::prelude::*;
+ use {Set, MutableSet, Mutable, MutableMap};
use super::{TreeMap, TreeSet};
#[test]
use core::mem;
use core::uint;
+use {Collection, Mutable, Map, MutableMap, Set, MutableSet};
use slice::{Items, MutItems};
use slice;
length: uint
}
-impl<T> Container for TrieMap<T> {
+impl<T> Collection for TrieMap<T> {
/// Return the number of elements in the map
#[inline]
fn len(&self) -> uint { self.length }
map: TrieMap<()>
}
-impl Container for TrieSet {
+impl Collection for TrieSet {
/// Return the number of elements in the set
#[inline]
fn len(&self) -> uint { self.map.len() }
use std::iter::range_step;
use std::uint;
+ use {MutableMap, Map};
use super::{TrieMap, TrieNode, Internal, External, Nothing};
fn check_integrity<T>(trie: &TrieNode<T>) {
use std::rand::{weak_rng, Rng};
use test::Bencher;
+ use MutableMap;
use super::TrieMap;
#[bench]
use std::prelude::*;
use std::uint;
+ use {MutableSet, Set};
use super::TrieSet;
#[test]
use core::ptr;
use core::uint;
+use {Collection, Mutable};
use slice::{MutableOrdVector, OwnedVector, MutableVectorAllocating};
use slice::{Items, MutItems};
} else if capacity == 0 {
Vec::new()
} else {
- let size = ::expect(capacity.checked_mul(&mem::size_of::<T>()),
- "capacity overflow");
+ let size = capacity.checked_mul(&mem::size_of::<T>())
+ .expect("capacity overflow");
let ptr = unsafe { allocate(size, mem::min_align_of::<T>()) };
Vec { len: 0, cap: capacity, ptr: ptr as *mut T }
}
}
}
-impl<T> Container for Vec<T> {
+impl<T> Collection for Vec<T> {
#[inline]
fn len(&self) -> uint {
self.len
if mem::size_of::<T>() == 0 { return }
if capacity > self.cap {
- let size = ::expect(capacity.checked_mul(&mem::size_of::<T>()),
- "capacity overflow");
+ let size = capacity.checked_mul(&mem::size_of::<T>())
+ .expect("capacity overflow");
unsafe {
self.ptr = alloc_or_realloc(self.ptr, size,
self.cap * mem::size_of::<T>());
pub fn push(&mut self, value: T) {
if mem::size_of::<T>() == 0 {
// zero-size types consume no memory, so we can't rely on the address space running out
- self.len = ::expect(self.len.checked_add(&1), "length overflow");
+ self.len = self.len.checked_add(&1).expect("length overflow");
unsafe { mem::forget(value); }
return
}
fn from_vec(mut v: Vec<T>) -> ~[T] {
let len = v.len();
let data_size = len.checked_mul(&mem::size_of::<T>());
- let data_size = ::expect(data_size, "overflow in from_vec()");
+ let data_size = data_size.expect("overflow in from_vec()");
let size = mem::size_of::<RawVec<()>>().checked_add(&data_size);
- let size = ::expect(size, "overflow in from_vec()");
+ let size = size.expect("overflow in from_vec()");
// In a post-DST world, we can attempt to reuse the Vec allocation by calling
// shrink_to_fit() on it. That may involve a reallocation+memcpy, but that's no
--- /dev/null
+// Copyright 2013 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.
+
+//! Traits for generic collections
+
+/// A trait to represent the abstract idea of a container. The only concrete
+/// knowledge known is the number of elements contained within.
+pub trait Collection {
+ /// Return the number of elements in the container
+ fn len(&self) -> uint;
+
+ /// Return true if the container contains no elements
+ #[inline]
+ fn is_empty(&self) -> bool {
+ self.len() == 0
+ }
+}
+++ /dev/null
-// Copyright 2013 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.
-
-//! Traits for generic containers (including `Map` and `Set`)
-
-use option::Option;
-
-/// A trait to represent the abstract idea of a container. The only concrete
-/// knowledge known is the number of elements contained within.
-pub trait Container {
- /// Return the number of elements in the container
- fn len(&self) -> uint;
-
- /// Return true if the container contains no elements
- #[inline]
- fn is_empty(&self) -> bool {
- self.len() == 0
- }
-}
-
-/// A trait to represent mutable containers
-pub trait Mutable: Container {
- /// Clear the container, removing all values.
- fn clear(&mut self);
-}
-
-/// A map is a key-value store where values may be looked up by their keys. This
-/// trait provides basic operations to operate on these stores.
-pub trait Map<K, V>: Container {
- /// Return a reference to the value corresponding to the key
- fn find<'a>(&'a self, key: &K) -> Option<&'a V>;
-
- /// Return true if the map contains a value for the specified key
- #[inline]
- fn contains_key(&self, key: &K) -> bool {
- self.find(key).is_some()
- }
-}
-
-/// This trait provides basic operations to modify the contents of a map.
-pub trait MutableMap<K, V>: Map<K, V> + Mutable {
- /// 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.
- #[inline]
- fn insert(&mut self, key: K, value: V) -> bool {
- self.swap(key, value).is_none()
- }
-
- /// Remove a key-value pair from the map. Return true if the key
- /// was present in the map, otherwise false.
- #[inline]
- fn remove(&mut self, key: &K) -> bool {
- self.pop(key).is_some()
- }
-
- /// Insert a key-value pair from the map. If the key already had a value
- /// present in the map, that value is returned. Otherwise None is returned.
- fn swap(&mut self, k: K, v: V) -> Option<V>;
-
- /// Removes a key from the map, returning the value at the key if the key
- /// was previously in the map.
- fn pop(&mut self, k: &K) -> Option<V>;
-
- /// Return a mutable reference to the value corresponding to the key
- fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>;
-}
-
-/// A set is a group of objects which are each distinct from one another. This
-/// trait represents actions which can be performed on sets to iterate over
-/// them.
-pub trait Set<T>: Container {
- /// Return true if the set contains a value
- fn contains(&self, value: &T) -> bool;
-
- /// Return true if the set has no elements in common with `other`.
- /// This is equivalent to checking for an empty intersection.
- fn is_disjoint(&self, other: &Self) -> bool;
-
- /// Return true if the set is a subset of another
- fn is_subset(&self, other: &Self) -> bool;
-
- /// Return true if the set is a superset of another
- fn is_superset(&self, other: &Self) -> bool {
- other.is_subset(self)
- }
-
- // FIXME #8154: Add difference, sym. difference, intersection and union iterators
-}
-
-/// This trait represents actions which can be performed on sets to mutate
-/// them.
-pub trait MutableSet<T>: Set<T> + Mutable {
- /// Add a value to the set. Return true if the value was not already
- /// present in the set.
- fn insert(&mut self, value: T) -> bool;
-
- /// Remove a value from the set. Return true if the value was
- /// present in the set.
- fn remove(&mut self, value: &T) -> bool;
-}
#![allow(missing_doc)]
use char;
-use container::Container;
+use collections::Collection;
use fmt;
use iter::{Iterator, range, DoubleEndedIterator};
use num::{Float, FPNaN, FPInfinite, ToPrimitive, Primitive};
use any;
use cell::Cell;
use char::Char;
-use container::Container;
+use collections::Collection;
use iter::{Iterator, range};
use kinds::Copy;
use mem;
#![allow(unsigned_negate)]
-use container::Container;
+use collections::Collection;
use fmt;
use iter::{Iterator, DoubleEndedIterator};
use num::{Int, cast, zero};
#[cfg(not(test))] pub mod cmp;
pub mod clone;
pub mod default;
-pub mod container;
+pub mod collections;
/* Core types and methods on primitives */
pub use clone::Clone;
pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
pub use cmp::{Ordering, Less, Equal, Greater, Equiv};
-pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
+pub use collections::Collection;
pub use iter::{FromIterator, Extendable};
pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
// Currently, no progress has been made on this list.
use clone::Clone;
-use container::Container;
+use collections::Collection;
use finally::try_finally;
use intrinsics;
use iter::{range, Iterator};
use mem::transmute;
use clone::Clone;
-use container::Container;
+use collections::Collection;
use cmp::{PartialEq, Ord, Ordering, Less, Equal, Greater};
use cmp;
use default::Default;
use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Equiv};
use iter::order;
- use container::Container;
+ use collections::Collection;
impl<'a,T:PartialEq> PartialEq for &'a [T] {
fn eq(&self, other: & &'a [T]) -> bool {
fn as_slice<'a>(&'a self) -> &'a [T] { let v: &'a [T] = *self; v }
}
-impl<'a, T> Container for &'a [T] {
+impl<'a, T> Collection for &'a [T] {
/// Returns the length of a vector
#[inline]
fn len(&self) -> uint {
}
}
-impl<T> Container for ~[T] {
+impl<T> Collection for ~[T] {
/// Returns the length of a vector
#[inline]
fn len(&self) -> uint {
/// Operations on `[u8]`.
pub mod bytes {
- use container::Container;
+ use collections::Collection;
use ptr;
use slice::MutableVector;
use clone::Clone;
use cmp;
use cmp::{PartialEq, Eq};
-use container::Container;
+use collections::Collection;
use default::Default;
use iter::{Filter, Map, Iterator};
use iter::{DoubleEndedIterator, ExactSize};
/// Unsafe operations
pub mod raw {
use mem;
- use container::Container;
+ use collections::Collection;
use ptr::RawPtr;
use raw::Slice;
use slice::{ImmutableVector};
#[cfg(not(test))]
#[allow(missing_doc)]
pub mod traits {
- use container::Container;
use cmp::{Ord, Ordering, Less, Equal, Greater, PartialEq, PartialOrd, Equiv, Eq};
+ use collections::Collection;
use iter::Iterator;
use option::{Some, None};
use str::{Str, StrSlice, eq_slice};
fn as_slice<'a>(&'a self) -> &'a str { *self }
}
-impl<'a> Container for &'a str {
+impl<'a> Collection for &'a str {
#[inline]
fn len(&self) -> uint {
self.repr().len
}
}
-impl<'t> Container for Captures<'t> {
+impl<'t> Collection for Captures<'t> {
/// Returns the number of captured groups.
#[inline]
fn len(&self) -> uint {
#![allow(unsigned_negate)]
-use std::container::Map;
use libc::c_ulonglong;
use std::num::{Bitwise};
use std::rc::Rc;
}
}
-impl Container for CString {
+impl Collection for CString {
/// Return the number of bytes in the CString (not including the NUL terminator).
///
/// # Failure
//! Operations on ASCII strings and characters
-use container::Container;
+use collections::Collection;
use fmt;
use iter::Iterator;
use mem;
//! handled correctly, i.e. that allocated memory is eventually freed
//! if necessary.
-use container::Container;
+use collections::Collection;
use kinds::Send;
use mem;
use ops::Drop;
}
}
-impl<T> Container for CVec<T> {
+impl<T> Collection for CVec<T> {
fn len(&self) -> uint { self.len }
}
use clone::Clone;
use cmp::{max, Eq, Equiv, PartialEq};
-use container::{Container, Mutable, Set, MutableSet, Map, MutableMap};
+use collections::{Collection, Mutable, Set, MutableSet, Map, MutableMap};
use default::Default;
use fmt::Show;
use fmt;
}
}
-impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> Container for HashMap<K, V, H> {
+impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> Collection for HashMap<K, V, H> {
/// Return the number of elements in the map
fn len(&self) -> uint { self.table.size() }
}
impl<T: Eq + Hash<S>, S, H: Hasher<S>> Eq for HashSet<T, H> {}
-impl<T: Eq + Hash<S>, S, H: Hasher<S>> Container for HashSet<T, H> {
+impl<T: Eq + Hash<S>, S, H: Hasher<S>> Collection for HashSet<T, H> {
fn len(&self) -> uint { self.map.len() }
}
use prelude::*;
use super::HashSet;
- use container::Container;
use slice::ImmutableEqVector;
+ use collections::Collection;
#[test]
fn test_disjoint() {
//! ```
use cmp::{PartialEq, Eq};
-use collections::HashMap;
-use container::{Container, Mutable, MutableMap};
+use collections::{HashMap, Collection, Mutable, MutableMap};
use fmt;
use hash::Hash;
use iter::{range, Iterator};
}
}
-impl<K: Hash + Eq, V> Container for LruCache<K, V> {
+impl<K: Hash + Eq, V> Collection for LruCache<K, V> {
/// Return the number of key-value pairs in the cache.
fn len(&self) -> uint {
self.map.len()
* Collection types.
*/
-pub use core_collections::{Bitv, BitvSet, BTree, Deque, DList, EnumSet};
+pub use core_collections::{Collection, Mutable, Map, MutableMap};
+pub use core_collections::{Set, MutableSet, Deque};
+pub use core_collections::{Bitv, BitvSet, BTree, DList, EnumSet};
pub use core_collections::{PriorityQueue, RingBuf, SmallIntMap};
pub use core_collections::{TreeMap, TreeSet, TrieMap, TrieSet};
-pub use core_collections::{bitv, btree, deque, dlist, enum_set};
+pub use core_collections::{bitv, btree, dlist, enum_set};
pub use core_collections::{priority_queue, ringbuf, smallintmap, treemap, trie};
pub use self::hashmap::{HashMap, HashSet};
/// of a synchronous channel. There are a few branches for the unbuffered case,
/// but they're mostly just relevant to blocking senders.
-use container::Container;
+use collections::Collection;
use iter::Iterator;
use kinds::Send;
use mem;
//! Buffering wrappers for I/O traits
use cmp;
-use container::Container;
+use collections::Collection;
use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult};
use iter::ExactSize;
use ops::Drop;
use clone::Clone;
use cmp;
-use container::Container;
+use collections::Collection;
use comm::{Sender, Receiver};
use io;
use option::{None, Option, Some};
// FIXME: Not sure how this should be structured
// FIXME: Iteration should probably be considered separately
-use container::Container;
+use collections::Collection;
use iter::Iterator;
use option::{Option, Some, None};
use result::{Ok, Err};
mod bench {
extern crate test;
- use container::Container;
+ use collections::Collection;
use prelude::*;
use self::test::Bencher;
use c_str::ToCStr;
use clone::Clone;
-use container::Container;
+use collections::Collection;
use io;
use iter::Iterator;
use kinds::Send;
//! Readers and Writers for in-memory buffers
use cmp::min;
-use container::Container;
+use collections::Collection;
use option::None;
use result::{Err, Ok};
use io;
#![deny(unused_must_use)]
use char::Char;
-use container::Container;
+use collections::Collection;
use fmt;
use int;
use iter::Iterator;
#![allow(missing_doc)]
-use container::Container;
+use collections::Collection;
use fmt;
use from_str::FromStr;
use iter::Iterator;
pub use core::char;
pub use core::clone;
#[cfg(not(test))] pub use core::cmp;
-pub use core::container;
pub use core::default;
pub use core::finally;
pub use core::intrinsics;
use char;
use clone::Clone;
-use container::Container;
+use collections::Collection;
use num::{NumCast, Zero, One, cast, Int};
use num::{Float, FPNaN, FPInfinite, ToPrimitive};
use num;
#![allow(non_snake_case_functions)]
use clone::Clone;
-use container::Container;
+use collections::Collection;
use fmt;
use iter::Iterator;
use libc::{c_void, c_int};
#![deny(deprecated_owned_vector)]
-use container::Container;
+use collections::Collection;
use c_str::CString;
use clone::Clone;
use fmt;
use c_str::{CString, ToCStr};
use clone::Clone;
use cmp::{PartialEq, Eq};
-use container::Container;
+use collections::Collection;
use from_str::FromStr;
use hash;
use io::Writer;
use c_str::{CString, ToCStr};
use clone::Clone;
use cmp::{PartialEq, Eq};
-use container::Container;
+use collections::Collection;
use from_str::FromStr;
use hash;
use io::Writer;
#[doc(no_inline)] pub use clone::Clone;
#[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
#[doc(no_inline)] pub use cmp::{Ordering, Less, Equal, Greater, Equiv};
-#[doc(no_inline)] pub use container::{Container, Mutable, Map, MutableMap};
-#[doc(no_inline)] pub use container::{Set, MutableSet};
+#[doc(no_inline)] pub use collections::{Collection, Mutable, Map, MutableMap};
+#[doc(no_inline)] pub use collections::{Set, MutableSet};
#[doc(no_inline)] pub use iter::{FromIterator, Extendable, ExactSize};
#[doc(no_inline)] pub use iter::{Iterator, DoubleEndedIterator};
#[doc(no_inline)] pub use iter::{RandomAccessIterator, CloneableIterator};
mod imp {
extern crate libc;
- use container::Container;
+ use core_collections::Collection;
use io::{IoResult, IoError};
use mem;
use ops::Drop;
//! A wrapper around any Reader to treat it as an RNG.
-use container::Container;
+use collections::Collection;
use io::Reader;
use rand::Rng;
use result::{Ok, Err};
#![allow(non_camel_case_types)]
use char::Char;
-use container::Container;
+use collections::Collection;
use from_str::from_str;
use io::{IoResult, Writer};
use iter::Iterator;
#[cfg(not(target_os = "macos"))]
fn print(w: &mut Writer, idx: int, addr: *libc::c_void) -> IoResult<()> {
- use container::Container;
+ use collections::Collection;
use iter::Iterator;
use os;
use path::GenericPath;
#[allow(dead_code, uppercase_variables)]
mod imp {
use c_str::CString;
- use container::Container;
+ use core_collections::Collection;
use intrinsics;
use io::{IoResult, Writer};
use libc;
impl<T: Eq> Eq for OwnedSlice<T> {}
-impl<T> Container for OwnedSlice<T> {
+impl<T> Collection for OwnedSlice<T> {
fn len(&self) -> uint { self.len }
}
Many(Vec<T> ),
}
-impl<T> Container for SmallVector<T> {
+impl<T> Collection for SmallVector<T> {
fn len(&self) -> uint {
match self.repr {
Zero => 0,
let x: Box<HashMap<int, int>> = box HashMap::new();
let x: Box<Map<int, int>> = x;
let y: Box<Map<uint, int>> = box x;
- //~^ ERROR failed to find an implementation of trait core::container::Map<uint,int>
- // for ~core::container::Map<int,int>:Send
+ //~^ ERROR failed to find an implementation of trait collections::Map<uint,int>
+ // for ~collections::Map<int,int>:Send
}
}
}
-impl<T> Container for cat<T> {
+impl<T> Collection for cat<T> {
fn len(&self) -> uint { self.meows as uint }
fn is_empty(&self) -> bool { self.meows == 0 }
}
extern crate collections;
-use std::container::{Map, MutableMap};
+use std::collections::{Map, MutableMap};
use std::str::{SendStr, Owned, Slice};
use std::collections::HashMap;
use std::option::Some;
extern crate collections;
-use std::container::{ Map, MutableMap};
+use std::collections::{ Map, MutableMap};
use std::str::{SendStr, Owned, Slice};
use std::to_str::ToStr;
use self::collections::TreeMap;