提交 112c8a96 编写于 作者: A Alexis Beingessner

refactor libcollections as part of collection reform

* Moves multi-collection files into their own directory, and splits them into seperate files
* Changes exports so that each collection has its own module
* Adds underscores to public modules and filenames to match standard naming conventions

(that is, treemap::{TreeMap, TreeSet} => tree_map::TreeMap, tree_set::TreeSet)

* Renames PriorityQueue to BinaryHeap
* Renames SmallIntMap to VecMap
* Miscellanious fallout fixes

[breaking-change]
上级 a294b350
......@@ -944,10 +944,10 @@ An example of `use` declarations:
```
use std::iter::range_step;
use std::option::{Some, None};
use std::collections::hashmap::{mod, HashMap};
use std::collections::hash_map::{mod, HashMap};
# fn foo<T>(_: T){}
# fn bar(map: HashMap<String, uint>, set: hashmap::HashSet<String>){}
fn foo<T>(_: T){}
fn bar(map1: HashMap<String, uint>, map2: hash_map::HashMap<String, uint>){}
fn main() {
// Equivalent to 'std::iter::range_step(0u, 10u, 2u);'
......@@ -957,10 +957,10 @@ fn main() {
// std::option::None]);'
foo(vec![Some(1.0f64), None]);
// Both `hash` and `HashMap` are in scope.
let map = HashMap::new();
let set = hashmap::HashSet::new();
bar(map, set);
// Both `hash_map` and `HashMap` are in scope.
let map1 = HashMap::new();
let map2 = hash_map::HashMap::new();
bar(map1, map2);
}
```
......@@ -4096,7 +4096,7 @@ cause transitions between the states. The lifecycle states of a task are:
* running
* blocked
* panicked
* panicked
* dead
A task begins its lifecycle &mdash; once it has been spawned &mdash; in the
......
......@@ -19,14 +19,14 @@
//!
//! This is a larger example which implements [Dijkstra's algorithm][dijkstra]
//! to solve the [shortest path problem][sssp] on a [directed graph][dir_graph].
//! It showcases how to use the `PriorityQueue` with custom types.
//! It showcases how to use the `BinaryHeap` with custom types.
//!
//! [dijkstra]: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
//! [sssp]: http://en.wikipedia.org/wiki/Shortest_path_problem
//! [dir_graph]: http://en.wikipedia.org/wiki/Directed_graph
//!
//! ```
//! use std::collections::PriorityQueue;
//! use std::collections::BinaryHeap;
//! use std::uint;
//!
//! #[deriving(Eq, PartialEq)]
......@@ -68,7 +68,7 @@
//! // dist[node] = current shortest distance from `start` to `node`
//! let mut dist = Vec::from_elem(adj_list.len(), uint::MAX);
//!
//! let mut pq = PriorityQueue::new();
//! let mut pq = BinaryHeap::new();
//!
//! // We're at `start`, with a zero cost
//! dist[start] = 0u;
......@@ -166,52 +166,52 @@
///
/// This will be a max-heap.
#[deriving(Clone)]
pub struct PriorityQueue<T> {
pub struct BinaryHeap<T> {
data: Vec<T>,
}
impl<T: Ord> Default for PriorityQueue<T> {
impl<T: Ord> Default for BinaryHeap<T> {
#[inline]
fn default() -> PriorityQueue<T> { PriorityQueue::new() }
fn default() -> BinaryHeap<T> { BinaryHeap::new() }
}
impl<T: Ord> PriorityQueue<T> {
/// Creates an empty `PriorityQueue` as a max-heap.
impl<T: Ord> BinaryHeap<T> {
/// Creates an empty `BinaryHeap` as a max-heap.
///
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// let pq: PriorityQueue<uint> = PriorityQueue::new();
/// use std::collections::BinaryHeap;
/// let pq: BinaryHeap<uint> = BinaryHeap::new();
/// ```
pub fn new() -> PriorityQueue<T> { PriorityQueue{data: vec!(),} }
pub fn new() -> BinaryHeap<T> { BinaryHeap{data: vec!(),} }
/// Creates an empty `PriorityQueue` with a specific capacity.
/// Creates an empty `BinaryHeap` with a specific capacity.
/// This preallocates enough memory for `capacity` elements,
/// so that the `PriorityQueue` does not have to be reallocated
/// so that the `BinaryHeap` does not have to be reallocated
/// until it contains at least that many values.
///
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// let pq: PriorityQueue<uint> = PriorityQueue::with_capacity(10u);
/// use std::collections::BinaryHeap;
/// let pq: BinaryHeap<uint> = BinaryHeap::with_capacity(10u);
/// ```
pub fn with_capacity(capacity: uint) -> PriorityQueue<T> {
PriorityQueue { data: Vec::with_capacity(capacity) }
pub fn with_capacity(capacity: uint) -> BinaryHeap<T> {
BinaryHeap { data: Vec::with_capacity(capacity) }
}
/// Creates a `PriorityQueue` from a vector. This is sometimes called
/// Creates a `BinaryHeap` from a vector. This is sometimes called
/// `heapifying` the vector.
///
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// let pq = PriorityQueue::from_vec(vec![9i, 1, 2, 7, 3, 2]);
/// use std::collections::BinaryHeap;
/// let pq = BinaryHeap::from_vec(vec![9i, 1, 2, 7, 3, 2]);
/// ```
pub fn from_vec(xs: Vec<T>) -> PriorityQueue<T> {
let mut q = PriorityQueue{data: xs,};
pub fn from_vec(xs: Vec<T>) -> BinaryHeap<T> {
let mut q = BinaryHeap{data: xs,};
let mut n = q.len() / 2;
while n > 0 {
n -= 1;
......@@ -226,8 +226,8 @@ pub fn from_vec(xs: Vec<T>) -> PriorityQueue<T> {
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// let pq = PriorityQueue::from_vec(vec![1i, 2, 3, 4]);
/// use std::collections::BinaryHeap;
/// let pq = BinaryHeap::from_vec(vec![1i, 2, 3, 4]);
///
/// // Print 1, 2, 3, 4 in arbitrary order
/// for x in pq.iter() {
......@@ -243,9 +243,9 @@ pub fn iter<'a>(&'a self) -> Items<'a, T> {
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let mut pq = PriorityQueue::new();
/// let mut pq = BinaryHeap::new();
/// assert_eq!(pq.top(), None);
///
/// pq.push(1i);
......@@ -263,36 +263,36 @@ pub fn top<'a>(&'a self) -> Option<&'a T> {
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let pq: PriorityQueue<uint> = PriorityQueue::with_capacity(100u);
/// let pq: BinaryHeap<uint> = BinaryHeap::with_capacity(100u);
/// assert!(pq.capacity() >= 100u);
/// ```
pub fn capacity(&self) -> uint { self.data.capacity() }
/// Reserves capacity for exactly `n` elements in the `PriorityQueue`.
/// Reserves capacity for exactly `n` elements in the `BinaryHeap`.
/// Do nothing if the capacity is already sufficient.
///
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let mut pq: PriorityQueue<uint> = PriorityQueue::new();
/// let mut pq: BinaryHeap<uint> = BinaryHeap::new();
/// pq.reserve_exact(100u);
/// assert!(pq.capacity() == 100u);
/// ```
pub fn reserve_exact(&mut self, n: uint) { self.data.reserve_exact(n) }
/// Reserves capacity for at least `n` elements in the `PriorityQueue`.
/// Reserves capacity for at least `n` elements in the `BinaryHeap`.
/// Do nothing if the capacity is already sufficient.
///
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let mut pq: PriorityQueue<uint> = PriorityQueue::new();
/// let mut pq: BinaryHeap<uint> = BinaryHeap::new();
/// pq.reserve(100u);
/// assert!(pq.capacity() >= 100u);
/// ```
......@@ -306,9 +306,9 @@ pub fn reserve(&mut self, n: uint) {
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let mut pq = PriorityQueue::from_vec(vec![1i, 3]);
/// let mut pq = BinaryHeap::from_vec(vec![1i, 3]);
///
/// assert_eq!(pq.pop(), Some(3i));
/// assert_eq!(pq.pop(), Some(1i));
......@@ -332,9 +332,9 @@ pub fn pop(&mut self) -> Option<T> {
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let mut pq = PriorityQueue::new();
/// let mut pq = BinaryHeap::new();
/// pq.push(3i);
/// pq.push(5i);
/// pq.push(1i);
......@@ -354,9 +354,9 @@ pub fn push(&mut self, item: T) {
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let mut pq = PriorityQueue::new();
/// let mut pq = BinaryHeap::new();
/// pq.push(1i);
/// pq.push(5i);
///
......@@ -380,9 +380,9 @@ pub fn push_pop(&mut self, mut item: T) -> T {
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let mut pq = PriorityQueue::new();
/// let mut pq = BinaryHeap::new();
///
/// assert_eq!(pq.replace(1i), None);
/// assert_eq!(pq.replace(3i), Some(1i));
......@@ -400,15 +400,15 @@ pub fn replace(&mut self, mut item: T) -> Option<T> {
}
}
/// Consumes the `PriorityQueue` and returns the underlying vector
/// Consumes the `BinaryHeap` and returns the underlying vector
/// in arbitrary order.
///
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let pq = PriorityQueue::from_vec(vec![1i, 2, 3, 4, 5, 6, 7]);
/// let pq = BinaryHeap::from_vec(vec![1i, 2, 3, 4, 5, 6, 7]);
/// let vec = pq.into_vec();
///
/// // Will print in some order
......@@ -416,17 +416,17 @@ pub fn replace(&mut self, mut item: T) -> Option<T> {
/// println!("{}", x);
/// }
/// ```
pub fn into_vec(self) -> Vec<T> { let PriorityQueue{data: v} = self; v }
pub fn into_vec(self) -> Vec<T> { let BinaryHeap{data: v} = self; v }
/// Consumes the `PriorityQueue` and returns a vector in sorted
/// Consumes the `BinaryHeap` and returns a vector in sorted
/// (ascending) order.
///
/// # Example
///
/// ```
/// use std::collections::PriorityQueue;
/// use std::collections::BinaryHeap;
///
/// let mut pq = PriorityQueue::from_vec(vec![1i, 2, 4, 5, 7]);
/// let mut pq = BinaryHeap::from_vec(vec![1i, 2, 4, 5, 7]);
/// pq.push(6);
/// pq.push(3);
///
......@@ -504,7 +504,7 @@ pub fn is_empty(&self) -> bool { self.len() == 0 }
pub fn clear(&mut self) { self.data.truncate(0) }
}
/// `PriorityQueue` iterator.
/// `BinaryHeap` iterator.
pub struct Items <'a, T:'a> {
iter: slice::Items<'a, T>,
}
......@@ -517,14 +517,14 @@ fn next(&mut self) -> Option<(&'a T)> { self.iter.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
impl<T: Ord> FromIterator<T> for PriorityQueue<T> {
fn from_iter<Iter: Iterator<T>>(mut iter: Iter) -> PriorityQueue<T> {
impl<T: Ord> FromIterator<T> for BinaryHeap<T> {
fn from_iter<Iter: Iterator<T>>(mut iter: Iter) -> BinaryHeap<T> {
let vec: Vec<T> = iter.collect();
PriorityQueue::from_vec(vec)
BinaryHeap::from_vec(vec)
}
}
impl<T: Ord> Extendable<T> for PriorityQueue<T> {
impl<T: Ord> Extendable<T> for BinaryHeap<T> {
fn extend<Iter: Iterator<T>>(&mut self, mut iter: Iter) {
let (lower, _) = iter.size_hint();
......@@ -541,14 +541,14 @@ fn extend<Iter: Iterator<T>>(&mut self, mut iter: Iter) {
mod tests {
use std::prelude::*;
use priority_queue::PriorityQueue;
use super::BinaryHeap;
use vec::Vec;
#[test]
fn test_iterator() {
let data = vec!(5i, 9, 3);
let iterout = [9i, 5, 3];
let pq = PriorityQueue::from_vec(data);
let pq = BinaryHeap::from_vec(data);
let mut i = 0;
for el in pq.iter() {
assert_eq!(*el, iterout[i]);
......@@ -561,7 +561,7 @@ fn test_top_and_pop() {
let data = vec!(2u, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1);
let mut sorted = data.clone();
sorted.sort();
let mut heap = PriorityQueue::from_vec(data);
let mut heap = BinaryHeap::from_vec(data);
while !heap.is_empty() {
assert_eq!(heap.top().unwrap(), sorted.last().unwrap());
assert_eq!(heap.pop().unwrap(), sorted.pop().unwrap());
......@@ -570,7 +570,7 @@ fn test_top_and_pop() {
#[test]
fn test_push() {
let mut heap = PriorityQueue::from_vec(vec!(2i, 4, 9));
let mut heap = BinaryHeap::from_vec(vec!(2i, 4, 9));
assert_eq!(heap.len(), 3);
assert!(*heap.top().unwrap() == 9);
heap.push(11);
......@@ -592,7 +592,7 @@ fn test_push() {
#[test]
fn test_push_unique() {
let mut heap = PriorityQueue::from_vec(vec!(box 2i, box 4, box 9));
let mut heap = BinaryHeap::from_vec(vec!(box 2i, box 4, box 9));
assert_eq!(heap.len(), 3);
assert!(*heap.top().unwrap() == box 9);
heap.push(box 11);
......@@ -614,7 +614,7 @@ fn test_push_unique() {
#[test]
fn test_push_pop() {
let mut heap = PriorityQueue::from_vec(vec!(5i, 5, 2, 1, 3));
let mut heap = BinaryHeap::from_vec(vec!(5i, 5, 2, 1, 3));
assert_eq!(heap.len(), 5);
assert_eq!(heap.push_pop(6), 6);
assert_eq!(heap.len(), 5);
......@@ -628,7 +628,7 @@ fn test_push_pop() {
#[test]
fn test_replace() {
let mut heap = PriorityQueue::from_vec(vec!(5i, 5, 2, 1, 3));
let mut heap = BinaryHeap::from_vec(vec!(5i, 5, 2, 1, 3));
assert_eq!(heap.len(), 5);
assert_eq!(heap.replace(6).unwrap(), 5);
assert_eq!(heap.len(), 5);
......@@ -641,7 +641,7 @@ fn test_replace() {
}
fn check_to_vec(mut data: Vec<int>) {
let heap = PriorityQueue::from_vec(data.clone());
let heap = BinaryHeap::from_vec(data.clone());
let mut v = heap.clone().into_vec();
v.sort();
data.sort();
......@@ -669,19 +669,19 @@ fn test_to_vec() {
#[test]
fn test_empty_pop() {
let mut heap: PriorityQueue<int> = PriorityQueue::new();
let mut heap: BinaryHeap<int> = BinaryHeap::new();
assert!(heap.pop().is_none());
}
#[test]
fn test_empty_top() {
let empty: PriorityQueue<int> = PriorityQueue::new();
let empty: BinaryHeap<int> = BinaryHeap::new();
assert!(empty.top().is_none());
}
#[test]
fn test_empty_replace() {
let mut heap: PriorityQueue<int> = PriorityQueue::new();
let mut heap: BinaryHeap<int> = BinaryHeap::new();
heap.replace(5).is_none();
}
......@@ -689,7 +689,7 @@ fn test_empty_replace() {
fn test_from_iter() {
let xs = vec!(9u, 8, 7, 6, 5, 4, 3, 2, 1);
let mut q: PriorityQueue<uint> = xs.as_slice().iter().rev().map(|&x| x).collect();
let mut q: BinaryHeap<uint> = xs.as_slice().iter().rev().map(|&x| x).collect();
for &x in xs.iter() {
assert_eq!(q.pop().unwrap(), x);
......
......@@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// FIXME(Gankro): Bitv and BitvSet are very tightly coupled. Ideally (for maintenance),
// they should be in separate files/modules, with BitvSet only using Bitv's public API.
//! Collections implemented with bit vectors.
//!
//! # Example
......@@ -1654,7 +1657,7 @@ mod tests {
use std::rand::Rng;
use test::Bencher;
use bitv::{Bitv, BitvSet, from_fn, from_bytes};
use super::{Bitv, BitvSet, from_fn, from_bytes};
use bitv;
use vec::Vec;
......
......@@ -23,7 +23,7 @@
use core::{iter, fmt, mem};
use core::fmt::Show;
use ringbuf::RingBuf;
use ring_buf::RingBuf;
/// A map based on a B-Tree.
///
......
......@@ -8,27 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub use self::map::BTreeMap;
pub use self::map::Entries;
pub use self::map::MutEntries;
pub use self::map::MoveEntries;
pub use self::map::Keys;
pub use self::map::Values;
pub use self::map::Entry;
pub use self::map::Occupied;
pub use self::map::Vacant;
pub use self::map::OccupiedEntry;
pub use self::map::VacantEntry;
pub use self::set::BTreeSet;
pub use self::set::Items;
pub use self::set::MoveItems;
pub use self::set::DifferenceItems;
pub use self::set::UnionItems;
pub use self::set::SymDifferenceItems;
pub use self::set::IntersectionItems;
mod node;
mod map;
mod set;
pub mod map;
pub mod set;
......@@ -13,7 +13,7 @@
use core::prelude::*;
use super::{BTreeMap, Keys, MoveEntries};
use btree_map::{BTreeMap, Keys, MoveEntries};
use std::hash::Hash;
use core::default::Default;
use core::{iter, fmt};
......
......@@ -155,7 +155,7 @@ mod test {
use std::prelude::*;
use std::mem;
use enum_set::{EnumSet, CLike};
use super::{EnumSet, CLike};
#[deriving(PartialEq, Show)]
#[repr(uint)]
......
......@@ -37,34 +37,72 @@
#[cfg(test)] #[phase(plugin, link)] extern crate std;
#[cfg(test)] #[phase(plugin, link)] extern crate log;
pub use bitv::{Bitv, BitvSet};
pub use btree::{BTreeMap, BTreeSet};
pub use binary_heap::BinaryHeap;
pub use bitv::Bitv;
pub use bitv_set::BitvSet;
pub use btree_map::BTreeMap;
pub use btree_set::BTreeSet;
pub use dlist::DList;
pub use enum_set::EnumSet;
pub use priority_queue::PriorityQueue;
pub use ringbuf::RingBuf;
pub use smallintmap::SmallIntMap;
pub use ring_buf::RingBuf;
pub use string::String;
pub use treemap::{TreeMap, TreeSet};
pub use trie::{TrieMap, TrieSet};
pub use tree_map::TreeMap;
pub use tree_set::TreeSet;
pub use trie_map::TrieMap;
pub use trie_set::TrieSet;
pub use vec::Vec;
pub use vec_map::VecMap;
mod macros;
pub mod bitv;
pub mod btree;
pub mod binary_heap;
mod bit;
mod btree;
pub mod dlist;
pub mod enum_set;
pub mod priority_queue;
pub mod ringbuf;
pub mod smallintmap;
pub mod treemap;
pub mod trie;
pub mod ring_buf;
mod tree;
mod trie;
pub mod slice;
pub mod str;
pub mod string;
pub mod vec;
pub mod hash;
pub mod vec_map;
pub mod bitv {
pub use bit::{Bitv, Bits, from_fn, from_bytes};
}
pub mod bitv_set {
pub use bit::{BitvSet, BitPositions, TwoBitPositions};
}
pub mod tree_map {
pub use tree::map::*;
}
pub mod tree_set {
pub use tree::set::*;
}
pub mod trie_map {
pub use trie::map::*;
}
pub mod trie_set {
pub use trie::set::*;
}
pub mod btree_map {
pub use btree::map::*;
}
pub mod btree_set {
pub use btree::set::*;
}
#[cfg(test)] mod bench;
......
......@@ -65,7 +65,7 @@
use core::prelude::{range};
use hash;
use ringbuf::RingBuf;
use ring_buf::RingBuf;
use string::String;
use unicode;
use vec::Vec;
......
// Copyright 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.
//! Maps are collections of unique keys with corresponding values, and sets are
//! just unique keys without a corresponding value. The `Map` and `Set` traits in
//! `std::container` define the basic interface.
//!
//! This crate defines the `TreeMap` and `TreeSet` types. Their keys must implement `Ord`.
//!
//! `TreeMap`s are ordered.
//!
//! ## Example
//!
//! ```{rust}
//! use std::collections::TreeSet;
//!
//! let mut tree_set = TreeSet::new();
//!
//! tree_set.insert(2i);
//! tree_set.insert(1i);
//! tree_set.insert(3i);
//!
//! for i in tree_set.iter() {
//! println!("{}", i) // prints 1, then 2, then 3
//! }
//! ```
pub mod map;
pub mod set;
\ No newline at end of file
此差异已折叠。
......@@ -654,335 +654,6 @@ fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut T {
}
}
/// A set implemented as a radix trie.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut set = TrieSet::new();
/// set.insert(6);
/// set.insert(28);
/// set.insert(6);
///
/// assert_eq!(set.len(), 2);
///
/// if !set.contains(&3) {
/// println!("3 is not in the set");
/// }
///
/// // Print contents in order
/// for x in set.iter() {
/// println!("{}", x);
/// }
///
/// set.remove(&6);
/// assert_eq!(set.len(), 1);
///
/// set.clear();
/// assert!(set.is_empty());
/// ```
#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct TrieSet {
map: TrieMap<()>
}
impl Show for TrieSet {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "{{"));
for (i, x) in self.iter().enumerate() {
if i != 0 { try!(write!(f, ", ")); }
try!(write!(f, "{}", x));
}
write!(f, "}}")
}
}
impl Default for TrieSet {
#[inline]
fn default() -> TrieSet { TrieSet::new() }
}
impl TrieSet {
/// Creates an empty TrieSet.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
/// let mut set = TrieSet::new();
/// ```
#[inline]
pub fn new() -> TrieSet {
TrieSet{map: TrieMap::new()}
}
/// Visits all values in reverse order. Aborts traversal when `f` returns `false`.
/// Returns `true` if `f` returns `true` for all elements.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let set: TrieSet = [1, 2, 3, 4, 5].iter().map(|&x| x).collect();
///
/// let mut vec = Vec::new();
/// assert_eq!(true, set.each_reverse(|&x| { vec.push(x); true }));
/// assert_eq!(vec, vec![5, 4, 3, 2, 1]);
///
/// // Stop when we reach 3
/// let mut vec = Vec::new();
/// assert_eq!(false, set.each_reverse(|&x| { vec.push(x); x != 3 }));
/// assert_eq!(vec, vec![5, 4, 3]);
/// ```
#[inline]
pub fn each_reverse(&self, f: |&uint| -> bool) -> bool {
self.map.each_reverse(|k, _| f(k))
}
/// Gets an iterator over the values in the set, in sorted order.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut set = TrieSet::new();
/// set.insert(3);
/// set.insert(2);
/// set.insert(1);
/// set.insert(2);
///
/// // Print 1, 2, 3
/// for x in set.iter() {
/// println!("{}", x);
/// }
/// ```
#[inline]
pub fn iter<'a>(&'a self) -> SetItems<'a> {
SetItems{iter: self.map.iter()}
}
/// Gets an iterator pointing to the first value that is not less than `val`.
/// If all values in the set are less than `val` an empty iterator is returned.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let set: TrieSet = [2, 4, 6, 8].iter().map(|&x| x).collect();
/// assert_eq!(set.lower_bound(4).next(), Some(4));
/// assert_eq!(set.lower_bound(5).next(), Some(6));
/// assert_eq!(set.lower_bound(10).next(), None);
/// ```
pub fn lower_bound<'a>(&'a self, val: uint) -> SetItems<'a> {
SetItems{iter: self.map.lower_bound(val)}
}
/// Gets an iterator pointing to the first value that key is greater than `val`.
/// If all values in the set are less than or equal to `val` an empty iterator is returned.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let set: TrieSet = [2, 4, 6, 8].iter().map(|&x| x).collect();
/// assert_eq!(set.upper_bound(4).next(), Some(6));
/// assert_eq!(set.upper_bound(5).next(), Some(6));
/// assert_eq!(set.upper_bound(10).next(), None);
/// ```
pub fn upper_bound<'a>(&'a self, val: uint) -> SetItems<'a> {
SetItems{iter: self.map.upper_bound(val)}
}
/// Return the number of elements in the set
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut v = TrieSet::new();
/// assert_eq!(v.len(), 0);
/// v.insert(1);
/// assert_eq!(v.len(), 1);
/// ```
#[inline]
pub fn len(&self) -> uint { self.map.len() }
/// Returns true if the set contains no elements
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut v = TrieSet::new();
/// assert!(v.is_empty());
/// v.insert(1);
/// assert!(!v.is_empty());
/// ```
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Clears the set, removing all values.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut v = TrieSet::new();
/// v.insert(1);
/// v.clear();
/// assert!(v.is_empty());
/// ```
#[inline]
pub fn clear(&mut self) { self.map.clear() }
/// Returns `true` if the set contains a value.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let set: TrieSet = [1, 2, 3].iter().map(|&x| x).collect();
/// assert_eq!(set.contains(&1), true);
/// assert_eq!(set.contains(&4), false);
/// ```
#[inline]
pub fn contains(&self, value: &uint) -> bool {
self.map.contains_key(value)
}
/// Returns `true` if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let a: TrieSet = [1, 2, 3].iter().map(|&x| x).collect();
/// let mut b: TrieSet = TrieSet::new();
///
/// assert_eq!(a.is_disjoint(&b), true);
/// b.insert(4);
/// assert_eq!(a.is_disjoint(&b), true);
/// b.insert(1);
/// assert_eq!(a.is_disjoint(&b), false);
/// ```
#[inline]
pub fn is_disjoint(&self, other: &TrieSet) -> bool {
self.iter().all(|v| !other.contains(&v))
}
/// Returns `true` if the set is a subset of another.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let sup: TrieSet = [1, 2, 3].iter().map(|&x| x).collect();
/// let mut set: TrieSet = TrieSet::new();
///
/// assert_eq!(set.is_subset(&sup), true);
/// set.insert(2);
/// assert_eq!(set.is_subset(&sup), true);
/// set.insert(4);
/// assert_eq!(set.is_subset(&sup), false);
/// ```
#[inline]
pub fn is_subset(&self, other: &TrieSet) -> bool {
self.iter().all(|v| other.contains(&v))
}
/// Returns `true` if the set is a superset of another.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let sub: TrieSet = [1, 2].iter().map(|&x| x).collect();
/// let mut set: TrieSet = TrieSet::new();
///
/// assert_eq!(set.is_superset(&sub), false);
///
/// set.insert(0);
/// set.insert(1);
/// assert_eq!(set.is_superset(&sub), false);
///
/// set.insert(2);
/// assert_eq!(set.is_superset(&sub), true);
/// ```
#[inline]
pub fn is_superset(&self, other: &TrieSet) -> bool {
other.is_subset(self)
}
/// Adds a value to the set. Returns `true` if the value was not already
/// present in the set.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut set = TrieSet::new();
///
/// assert_eq!(set.insert(2), true);
/// assert_eq!(set.insert(2), false);
/// assert_eq!(set.len(), 1);
/// ```
#[inline]
pub fn insert(&mut self, value: uint) -> bool {
self.map.insert(value, ())
}
/// Removes a value from the set. Returns `true` if the value was
/// present in the set.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut set = TrieSet::new();
///
/// set.insert(2);
/// assert_eq!(set.remove(&2), true);
/// assert_eq!(set.remove(&2), false);
/// ```
#[inline]
pub fn remove(&mut self, value: &uint) -> bool {
self.map.remove(value)
}
}
impl FromIterator<uint> for TrieSet {
fn from_iter<Iter: Iterator<uint>>(iter: Iter) -> TrieSet {
let mut set = TrieSet::new();
set.extend(iter);
set
}
}
impl Extendable<uint> for TrieSet {
fn extend<Iter: Iterator<uint>>(&mut self, mut iter: Iter) {
for elem in iter {
self.insert(elem);
}
}
}
struct TrieNode<T> {
count: uint,
children: [Child<T>, ..SIZE]
......@@ -1255,23 +926,8 @@ fn size_hint(&self) -> (uint, Option<uint>) {
iterator_impl! { Entries, iter = iter, mutability = }
iterator_impl! { MutEntries, iter = iter_mut, mutability = mut }
/// A forward iterator over a set.
pub struct SetItems<'a> {
iter: Entries<'a, ()>
}
impl<'a> Iterator<uint> for SetItems<'a> {
fn next(&mut self) -> Option<uint> {
self.iter.next().map(|(key, _)| key)
}
fn size_hint(&self) -> (uint, Option<uint>) {
self.iter.size_hint()
}
}
#[cfg(test)]
mod test_map {
mod test {
use std::prelude::*;
use std::iter::range_step;
use std::uint;
......@@ -1687,7 +1343,7 @@ fn test_index_nonexistent() {
}
#[cfg(test)]
mod bench_map {
mod bench {
use std::prelude::*;
use std::rand::{weak_rng, Rng};
use test::{Bencher, black_box};
......@@ -1802,98 +1458,3 @@ fn bench_insert_small_low_bits(b: &mut Bencher) {
})
}
}
#[cfg(test)]
mod test_set {
use std::prelude::*;
use std::uint;
use super::TrieSet;
#[test]
fn test_sane_chunk() {
let x = 1;
let y = 1 << (uint::BITS - 1);
let mut trie = TrieSet::new();
assert!(trie.insert(x));
assert!(trie.insert(y));
assert_eq!(trie.len(), 2);
let expected = [x, y];
for (i, x) in trie.iter().enumerate() {
assert_eq!(expected[i], x);
}
}
#[test]
fn test_from_iter() {
let xs = vec![9u, 8, 7, 6, 5, 4, 3, 2, 1];
let set: TrieSet = xs.iter().map(|&x| x).collect();
for x in xs.iter() {
assert!(set.contains(x));
}
}
#[test]
fn test_show() {
let mut set = TrieSet::new();
let empty = TrieSet::new();
set.insert(1);
set.insert(2);
let set_str = format!("{}", set);
assert!(set_str == "{1, 2}".to_string());
assert_eq!(format!("{}", empty), "{}".to_string());
}
#[test]
fn test_clone() {
let mut a = TrieSet::new();
a.insert(1);
a.insert(2);
a.insert(3);
assert!(a.clone() == a);
}
#[test]
fn test_lt() {
let mut a = TrieSet::new();
let mut b = TrieSet::new();
assert!(!(a < b) && !(b < a));
assert!(b.insert(2u));
assert!(a < b);
assert!(a.insert(3u));
assert!(!(a < b) && b < a);
assert!(b.insert(1));
assert!(b < a);
assert!(a.insert(0));
assert!(a < b);
assert!(a.insert(6));
assert!(a < b && !(b < a));
}
#[test]
fn test_ord() {
let mut a = TrieSet::new();
let mut b = TrieSet::new();
assert!(a <= b && a >= b);
assert!(a.insert(1u));
assert!(a > b && a >= b);
assert!(b < a && b <= a);
assert!(b.insert(2u));
assert!(b > a && b >= a);
assert!(a < b && a <= b);
}
}
// Copyright 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.
//! Maps are collections of unique keys with corresponding values, and sets are
//! just unique keys without a corresponding value. The `Map` and `Set` traits in
//! `std::container` define the basic interface.
//!
//! This crate defines `TrieMap` and `TrieSet`, which require `uint` keys.
//!
//! `TrieMap` is ordered.
pub mod map;
pub mod set;
\ No newline at end of file
// Copyright 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.
use core::prelude::*;
use core::default::Default;
use core::fmt;
use core::fmt::Show;
use std::hash::Hash;
use trie_map::{TrieMap, Entries};
/// A set implemented as a radix trie.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut set = TrieSet::new();
/// set.insert(6);
/// set.insert(28);
/// set.insert(6);
///
/// assert_eq!(set.len(), 2);
///
/// if !set.contains(&3) {
/// println!("3 is not in the set");
/// }
///
/// // Print contents in order
/// for x in set.iter() {
/// println!("{}", x);
/// }
///
/// set.remove(&6);
/// assert_eq!(set.len(), 1);
///
/// set.clear();
/// assert!(set.is_empty());
/// ```
#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct TrieSet {
map: TrieMap<()>
}
impl Show for TrieSet {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "{{"));
for (i, x) in self.iter().enumerate() {
if i != 0 { try!(write!(f, ", ")); }
try!(write!(f, "{}", x));
}
write!(f, "}}")
}
}
impl Default for TrieSet {
#[inline]
fn default() -> TrieSet { TrieSet::new() }
}
impl TrieSet {
/// Creates an empty TrieSet.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
/// let mut set = TrieSet::new();
/// ```
#[inline]
pub fn new() -> TrieSet {
TrieSet{map: TrieMap::new()}
}
/// Visits all values in reverse order. Aborts traversal when `f` returns `false`.
/// Returns `true` if `f` returns `true` for all elements.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let set: TrieSet = [1, 2, 3, 4, 5].iter().map(|&x| x).collect();
///
/// let mut vec = Vec::new();
/// assert_eq!(true, set.each_reverse(|&x| { vec.push(x); true }));
/// assert_eq!(vec, vec![5, 4, 3, 2, 1]);
///
/// // Stop when we reach 3
/// let mut vec = Vec::new();
/// assert_eq!(false, set.each_reverse(|&x| { vec.push(x); x != 3 }));
/// assert_eq!(vec, vec![5, 4, 3]);
/// ```
#[inline]
pub fn each_reverse(&self, f: |&uint| -> bool) -> bool {
self.map.each_reverse(|k, _| f(k))
}
/// Gets an iterator over the values in the set, in sorted order.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut set = TrieSet::new();
/// set.insert(3);
/// set.insert(2);
/// set.insert(1);
/// set.insert(2);
///
/// // Print 1, 2, 3
/// for x in set.iter() {
/// println!("{}", x);
/// }
/// ```
#[inline]
pub fn iter<'a>(&'a self) -> SetItems<'a> {
SetItems{iter: self.map.iter()}
}
/// Gets an iterator pointing to the first value that is not less than `val`.
/// If all values in the set are less than `val` an empty iterator is returned.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let set: TrieSet = [2, 4, 6, 8].iter().map(|&x| x).collect();
/// assert_eq!(set.lower_bound(4).next(), Some(4));
/// assert_eq!(set.lower_bound(5).next(), Some(6));
/// assert_eq!(set.lower_bound(10).next(), None);
/// ```
pub fn lower_bound<'a>(&'a self, val: uint) -> SetItems<'a> {
SetItems{iter: self.map.lower_bound(val)}
}
/// Gets an iterator pointing to the first value that key is greater than `val`.
/// If all values in the set are less than or equal to `val` an empty iterator is returned.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let set: TrieSet = [2, 4, 6, 8].iter().map(|&x| x).collect();
/// assert_eq!(set.upper_bound(4).next(), Some(6));
/// assert_eq!(set.upper_bound(5).next(), Some(6));
/// assert_eq!(set.upper_bound(10).next(), None);
/// ```
pub fn upper_bound<'a>(&'a self, val: uint) -> SetItems<'a> {
SetItems{iter: self.map.upper_bound(val)}
}
/// Return the number of elements in the set
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut v = TrieSet::new();
/// assert_eq!(v.len(), 0);
/// v.insert(1);
/// assert_eq!(v.len(), 1);
/// ```
#[inline]
pub fn len(&self) -> uint { self.map.len() }
/// Returns true if the set contains no elements
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut v = TrieSet::new();
/// assert!(v.is_empty());
/// v.insert(1);
/// assert!(!v.is_empty());
/// ```
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Clears the set, removing all values.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut v = TrieSet::new();
/// v.insert(1);
/// v.clear();
/// assert!(v.is_empty());
/// ```
#[inline]
pub fn clear(&mut self) { self.map.clear() }
/// Returns `true` if the set contains a value.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let set: TrieSet = [1, 2, 3].iter().map(|&x| x).collect();
/// assert_eq!(set.contains(&1), true);
/// assert_eq!(set.contains(&4), false);
/// ```
#[inline]
pub fn contains(&self, value: &uint) -> bool {
self.map.contains_key(value)
}
/// Returns `true` if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let a: TrieSet = [1, 2, 3].iter().map(|&x| x).collect();
/// let mut b: TrieSet = TrieSet::new();
///
/// assert_eq!(a.is_disjoint(&b), true);
/// b.insert(4);
/// assert_eq!(a.is_disjoint(&b), true);
/// b.insert(1);
/// assert_eq!(a.is_disjoint(&b), false);
/// ```
#[inline]
pub fn is_disjoint(&self, other: &TrieSet) -> bool {
self.iter().all(|v| !other.contains(&v))
}
/// Returns `true` if the set is a subset of another.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let sup: TrieSet = [1, 2, 3].iter().map(|&x| x).collect();
/// let mut set: TrieSet = TrieSet::new();
///
/// assert_eq!(set.is_subset(&sup), true);
/// set.insert(2);
/// assert_eq!(set.is_subset(&sup), true);
/// set.insert(4);
/// assert_eq!(set.is_subset(&sup), false);
/// ```
#[inline]
pub fn is_subset(&self, other: &TrieSet) -> bool {
self.iter().all(|v| other.contains(&v))
}
/// Returns `true` if the set is a superset of another.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let sub: TrieSet = [1, 2].iter().map(|&x| x).collect();
/// let mut set: TrieSet = TrieSet::new();
///
/// assert_eq!(set.is_superset(&sub), false);
///
/// set.insert(0);
/// set.insert(1);
/// assert_eq!(set.is_superset(&sub), false);
///
/// set.insert(2);
/// assert_eq!(set.is_superset(&sub), true);
/// ```
#[inline]
pub fn is_superset(&self, other: &TrieSet) -> bool {
other.is_subset(self)
}
/// Adds a value to the set. Returns `true` if the value was not already
/// present in the set.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut set = TrieSet::new();
///
/// assert_eq!(set.insert(2), true);
/// assert_eq!(set.insert(2), false);
/// assert_eq!(set.len(), 1);
/// ```
#[inline]
pub fn insert(&mut self, value: uint) -> bool {
self.map.insert(value, ())
}
/// Removes a value from the set. Returns `true` if the value was
/// present in the set.
///
/// # Example
///
/// ```
/// use std::collections::TrieSet;
///
/// let mut set = TrieSet::new();
///
/// set.insert(2);
/// assert_eq!(set.remove(&2), true);
/// assert_eq!(set.remove(&2), false);
/// ```
#[inline]
pub fn remove(&mut self, value: &uint) -> bool {
self.map.remove(value)
}
}
impl FromIterator<uint> for TrieSet {
fn from_iter<Iter: Iterator<uint>>(iter: Iter) -> TrieSet {
let mut set = TrieSet::new();
set.extend(iter);
set
}
}
impl Extendable<uint> for TrieSet {
fn extend<Iter: Iterator<uint>>(&mut self, mut iter: Iter) {
for elem in iter {
self.insert(elem);
}
}
}
/// A forward iterator over a set.
pub struct SetItems<'a> {
iter: Entries<'a, ()>
}
impl<'a> Iterator<uint> for SetItems<'a> {
fn next(&mut self) -> Option<uint> {
self.iter.next().map(|(key, _)| key)
}
fn size_hint(&self) -> (uint, Option<uint>) {
self.iter.size_hint()
}
}
#[cfg(test)]
mod test {
use std::prelude::*;
use std::uint;
use super::TrieSet;
#[test]
fn test_sane_chunk() {
let x = 1;
let y = 1 << (uint::BITS - 1);
let mut trie = TrieSet::new();
assert!(trie.insert(x));
assert!(trie.insert(y));
assert_eq!(trie.len(), 2);
let expected = [x, y];
for (i, x) in trie.iter().enumerate() {
assert_eq!(expected[i], x);
}
}
#[test]
fn test_from_iter() {
let xs = vec![9u, 8, 7, 6, 5, 4, 3, 2, 1];
let set: TrieSet = xs.iter().map(|&x| x).collect();
for x in xs.iter() {
assert!(set.contains(x));
}
}
#[test]
fn test_show() {
let mut set = TrieSet::new();
let empty = TrieSet::new();
set.insert(1);
set.insert(2);
let set_str = format!("{}", set);
assert!(set_str == "{1, 2}".to_string());
assert_eq!(format!("{}", empty), "{}".to_string());
}
#[test]
fn test_clone() {
let mut a = TrieSet::new();
a.insert(1);
a.insert(2);
a.insert(3);
assert!(a.clone() == a);
}
#[test]
fn test_lt() {
let mut a = TrieSet::new();
let mut b = TrieSet::new();
assert!(!(a < b) && !(b < a));
assert!(b.insert(2u));
assert!(a < b);
assert!(a.insert(3u));
assert!(!(a < b) && b < a);
assert!(b.insert(1));
assert!(b < a);
assert!(a.insert(0));
assert!(a < b);
assert!(a.insert(6));
assert!(a < b && !(b < a));
}
#[test]
fn test_ord() {
let mut a = TrieSet::new();
let mut b = TrieSet::new();
assert!(a <= b && a >= b);
assert!(a.insert(1u));
assert!(a > b && a >= b);
assert!(b < a && b <= a);
assert!(b.insert(2u));
assert!(b > a && b >= a);
assert!(a < b && a <= b);
}
}
......@@ -31,7 +31,7 @@
use syntax::parse::token::InternedString;
use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use getopts::{optopt, optmulti, optflag, optflagopt};
use getopts;
use std::cell::{RefCell};
......
......@@ -36,7 +36,7 @@
use std::cmp;
use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use std::slice;
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
use syntax::abi;
......
......@@ -24,7 +24,7 @@
use std::rc::Rc;
use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use syntax::ast;
use syntax::abi;
use syntax::attr;
......
......@@ -31,7 +31,7 @@
use syntax::diagnostic::expect;
use syntax::parse::token;
use std::collections::hashmap::HashMap;
use std::collections::hash_map::HashMap;
pub struct MethodInfo {
pub name: ast::Name,
......
......@@ -34,7 +34,7 @@
use std::hash;
use std::io::extensions::u64_from_be_bytes;
use std::io;
use std::collections::hashmap::HashMap;
use std::collections::hash_map::HashMap;
use std::rc::Rc;
use std::u64;
use rbml::reader;
......
......@@ -237,7 +237,7 @@
use std::string;
use std::collections::{HashMap, HashSet};
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use flate;
use time;
......
......@@ -28,7 +28,7 @@
use syntax::{ast, ast_map, ast_util, codemap};
use std::rc::Rc;
use std::collections::hashmap::Vacant;
use std::collections::hash_map::Vacant;
//
// This pass classifies expressions by their constant-ness.
......
......@@ -58,7 +58,7 @@
use syntax::visit::Visitor;
use std::collections::{HashMap, HashSet};
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use std::cell::{Cell, RefCell};
use std::mem::replace;
use std::rc::{Rc, Weak};
......
......@@ -29,7 +29,7 @@
use middle::typeck::infer::{InferCtxt, TypeSkolemizer};
use middle::ty_fold::TypeFoldable;
use std::cell::RefCell;
use std::collections::hashmap::HashMap;
use std::collections::hash_map::HashMap;
use std::rc::Rc;
use syntax::ast;
use util::ppaux::Repr;
......
......@@ -43,7 +43,7 @@
use std::ops;
use std::rc::Rc;
use std::collections::{HashMap, HashSet};
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use arena::TypedArena;
use syntax::abi;
use syntax::ast::{CrateNum, DefId, FnStyle, Ident, ItemTrait, LOCAL_CRATE};
......
......@@ -19,7 +19,7 @@
use std::cmp;
use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use syntax::ast;
use syntax::ast_util;
use syntax::codemap::{Span, Spanned};
......
......@@ -118,7 +118,7 @@
use std::cell::{Cell, Ref, RefCell};
use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use std::mem::replace;
use std::rc::Rc;
use syntax::abi;
......
......@@ -142,7 +142,7 @@ fn get_i(x: &'a Bar) -> &'a int {
use std::cell::{RefCell};
use std::collections::HashMap;
use std::collections::hashmap::{Vacant, Occupied};
use std::collections::hash_map::{Vacant, Occupied};
///////////////////////////////////////////////////////////////////////////
// PUBLIC ENTRY POINTS
......
......@@ -18,7 +18,7 @@
use syntax::ast;
use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use util::ppaux::Repr;
// Helper functions related to manipulating region types.
......
......@@ -44,7 +44,7 @@
use middle::ty_fold;
use middle::ty_fold::TypeFoldable;
use middle::ty_fold::TypeFolder;
use std::collections::hashmap;
use std::collections::hash_map;
use super::InferCtxt;
use super::unify::InferCtxtMethodsForSimplyUnifiableTypes;
......@@ -52,7 +52,7 @@
pub struct TypeSkolemizer<'a, 'tcx:'a> {
infcx: &'a InferCtxt<'a, 'tcx>,
skolemization_count: uint,
skolemization_map: hashmap::HashMap<ty::InferTy, ty::t>,
skolemization_map: hash_map::HashMap<ty::InferTy, ty::t>,
}
impl<'a, 'tcx> TypeSkolemizer<'a, 'tcx> {
......@@ -60,7 +60,7 @@ pub fn new<'tcx>(infcx: &'a InferCtxt<'a, 'tcx>) -> TypeSkolemizer<'a, 'tcx> {
TypeSkolemizer {
infcx: infcx,
skolemization_count: 0,
skolemization_map: hashmap::HashMap::new(),
skolemization_map: hash_map::HashMap::new(),
}
}
......@@ -76,8 +76,8 @@ fn skolemize(&mut self,
}
match self.skolemization_map.entry(key) {
hashmap::Occupied(entry) => *entry.get(),
hashmap::Vacant(entry) => {
hash_map::Occupied(entry) => *entry.get(),
hash_map::Vacant(entry) => {
let index = self.skolemization_count;
self.skolemization_count += 1;
let t = ty::mk_infer(self.infcx.tcx, skolemizer(index));
......
......@@ -34,7 +34,7 @@
//! both occur before the crate is rendered.
use std::collections::{HashMap, HashSet};
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use std::fmt;
use std::io::fs::PathExtensions;
use std::io::{fs, File, BufferedWriter, MemWriter, BufferedReader};
......
......@@ -31,7 +31,7 @@
use std::io;
use std::io::{File, MemWriter};
use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
use serialize::{json, Decodable, Encodable};
use externalfiles::ExternalHtml;
......
......@@ -41,7 +41,7 @@
use core::prelude::*;
use alloc::heap;
use collections::treemap::TreeMap;
use collections::TreeMap;
use core::cmp;
use core::kinds::marker;
use core::mem;
......
......@@ -18,7 +18,7 @@
#[bench]
fn new_drop(b : &mut Bencher) {
use super::HashMap;
use super::map::HashMap;
b.iter(|| {
let m : HashMap<int, int> = HashMap::new();
......@@ -28,7 +28,7 @@ fn new_drop(b : &mut Bencher) {
#[bench]
fn new_insert_drop(b : &mut Bencher) {
use super::HashMap;
use super::map::HashMap;
b.iter(|| {
let mut m = HashMap::new();
......@@ -39,7 +39,7 @@ fn new_insert_drop(b : &mut Bencher) {
#[bench]
fn grow_by_insertion(b: &mut Bencher) {
use super::HashMap;
use super::map::HashMap;
let mut m = HashMap::new();
......@@ -57,7 +57,7 @@ fn grow_by_insertion(b: &mut Bencher) {
#[bench]
fn find_existing(b: &mut Bencher) {
use super::HashMap;
use super::map::HashMap;
let mut m = HashMap::new();
......@@ -74,7 +74,7 @@ fn find_existing(b: &mut Bencher) {
#[bench]
fn find_nonexisting(b: &mut Bencher) {
use super::HashMap;
use super::map::HashMap;
let mut m = HashMap::new();
......@@ -91,7 +91,7 @@ fn find_nonexisting(b: &mut Bencher) {
#[bench]
fn hashmap_as_queue(b: &mut Bencher) {
use super::HashMap;
use super::map::HashMap;
let mut m = HashMap::new();
......@@ -110,7 +110,7 @@ fn hashmap_as_queue(b: &mut Bencher) {
#[bench]
fn find_pop_insert(b: &mut Bencher) {
use super::HashMap;
use super::map::HashMap;
let mut m = HashMap::new();
......
......@@ -10,24 +10,7 @@
//! Unordered containers, implemented as hash-tables
pub use self::map::HashMap;
pub use self::map::Entries;
pub use self::map::MutEntries;
pub use self::map::MoveEntries;
pub use self::map::Entry;
pub use self::map::Occupied;
pub use self::map::Vacant;
pub use self::map::OccupiedEntry;
pub use self::map::VacantEntry;
pub use self::map::Keys;
pub use self::map::Values;
pub use self::map::INITIAL_CAPACITY;
pub use self::set::HashSet;
pub use self::set::SetItems;
pub use self::set::SetMoveItems;
pub use self::set::SetAlgebraItems;
mod bench;
mod map;
mod set;
pub mod map;
pub mod set;
mod table;
......@@ -22,7 +22,7 @@
use option::{Some, None};
use result::{Ok, Err};
use super::{HashMap, Entries, MoveEntries, INITIAL_CAPACITY};
use super::map::{HashMap, Entries, MoveEntries, INITIAL_CAPACITY};
// Future Optimization (FIXME!)
......
......@@ -24,9 +24,9 @@
//! Rust's collections can be grouped into four major categories:
//!
//! * Sequences: `Vec`, `RingBuf`, `DList`, `BitV`
//! * Maps: `HashMap`, `BTreeMap`, `TreeMap`, `TrieMap`, `SmallIntMap`, `LruCache`
//! * Maps: `HashMap`, `BTreeMap`, `TreeMap`, `TrieMap`, `VecMap`, `LruCache`
//! * Sets: `HashSet`, `BTreeSet`, `TreeSet`, `TrieSet`, `BitVSet`, `EnumSet`
//! * Misc: `PriorityQueue`
//! * Misc: `BinaryHeap`
//!
//! # When Should You Use Which Collection?
//!
......@@ -74,7 +74,7 @@
//! * You want a `HashMap`, but with many potentially large `uint` keys.
//! * You want a `BTreeMap`, but with potentially large `uint` keys.
//!
//! ### Use a `SmallIntMap` when:
//! ### Use a `VecMap` when:
//! * You want a `HashMap` but with known to be small `uint` keys.
//! * You want a `BTreeMap`, but with known to be small `uint` keys.
//!
......@@ -88,12 +88,12 @@
//! * You want a bitvector.
//!
//! ### Use a `BitVSet` when:
//! * You want a `SmallIntSet`.
//! * You want a `VecSet`.
//!
//! ### Use an `EnumSet` when:
//! * You want a C-like enum, stored in a single `uint`.
//!
//! ### Use a `PriorityQueue` when:
//! ### Use a `BinaryHeap` when:
//! * You want to store a bunch of elements, but only ever want to process the "biggest"
//! or "most important" one at any given time.
//! * You want a priority queue.
......@@ -266,7 +266,7 @@
//! #### Counting the number of times each character in a string occurs
//!
//! ```
//! use std::collections::btree::{BTreeMap, Occupied, Vacant};
//! use std::collections::btree_map::{BTreeMap, Occupied, Vacant};
//!
//! let mut count = BTreeMap::new();
//! let message = "she sells sea shells by the sea shore";
......@@ -293,7 +293,7 @@
//! #### Tracking the inebriation of customers at a bar
//!
//! ```
//! use std::collections::btree::{BTreeMap, Occupied, Vacant};
//! use std::collections::btree_map::{BTreeMap, Occupied, Vacant};
//!
//! // A client of the bar. They have an id and a blood alcohol level.
//! struct Person { id: u32, blood_alcohol: f32 };
......@@ -328,14 +328,27 @@
#![experimental]
pub use core_collections::{Bitv, BitvSet, BTreeMap, BTreeSet, DList, EnumSet};
pub use core_collections::{PriorityQueue, RingBuf, SmallIntMap};
pub use core_collections::{TreeMap, TreeSet, TrieMap, TrieSet};
pub use core_collections::{bitv, btree, dlist, enum_set};
pub use core_collections::{priority_queue, ringbuf, smallintmap, treemap, trie};
pub use core_collections::{BinaryHeap, Bitv, BitvSet, BTreeMap, BTreeSet};
pub use core_collections::{DList, EnumSet, RingBuf};
pub use core_collections::{TreeMap, TreeSet, TrieMap, TrieSet, VecMap};
pub use self::hashmap::{HashMap, HashSet};
pub use core_collections::{binary_heap, bitv, bitv_set, btree_map, btree_set, dlist, enum_set};
pub use core_collections::{ring_buf, tree_map, tree_set, trie_map, trie_set, vec_map};
pub use self::hash_map::HashMap;
pub use self::hash_set::HashSet;
pub use self::lru_cache::LruCache;
pub mod hashmap;
mod hash;
pub mod hash_map {
//! A hashmap
pub use super::hash::map::*;
}
pub mod hash_set {
//! A hashset
pub use super::hash::set::*;
}
pub mod lru_cache;
......@@ -20,7 +20,7 @@
use std::cell::RefCell;
use std::rc::Rc;
use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map::{Occupied, Vacant};
/// The SCTable contains a table of SyntaxContext_'s. It
/// represents a flattened tree structure, to avoid having
......
......@@ -10,8 +10,8 @@
#![allow(missing_docs)]
use std::collections::hashmap;
use std::collections::hashmap::{Occupied, Vacant};
use std::collections::hash_map;
use std::collections::hash_map::{Occupied, Vacant};
use std::fmt::Show;
use std::hash::Hash;
use std::io;
......@@ -440,8 +440,8 @@ pub fn write_boxplot<T: Float + Show + FromPrimitive>(
/// Returns a HashMap with the number of occurrences of every element in the
/// sequence that the iterator exposes.
pub fn freq_count<T: Iterator<U>, U: Eq+Hash>(mut iter: T) -> hashmap::HashMap<U, uint> {
let mut map: hashmap::HashMap<U,uint> = hashmap::HashMap::new();
pub fn freq_count<T: Iterator<U>, U: Eq+Hash>(mut iter: T) -> hash_map::HashMap<U, uint> {
let mut map: hash_map::HashMap<U,uint> = hash_map::HashMap::new();
for elem in iter {
match map.entry(elem) {
Occupied(mut entry) => { *entry.get_mut() += 1; },
......
......@@ -14,7 +14,7 @@
extern crate rand;
extern crate time;
use std::collections::bitv::BitvSet;
use std::collections::BitvSet;
use std::collections::TreeSet;
use std::hash::Hash;
use std::collections::HashSet;
......
......@@ -13,17 +13,17 @@
extern crate collections;
extern crate time;
use std::collections::SmallIntMap;
use std::collections::VecMap;
use std::os;
use std::uint;
fn append_sequential(min: uint, max: uint, map: &mut SmallIntMap<uint>) {
fn append_sequential(min: uint, max: uint, map: &mut VecMap<uint>) {
for i in range(min, max) {
map.insert(i, i + 22u);
}
}
fn check_sequential(min: uint, max: uint, map: &SmallIntMap<uint>) {
fn check_sequential(min: uint, max: uint, map: &VecMap<uint>) {
for i in range(min, max) {
assert_eq!(map[i], i + 22u);
}
......@@ -45,7 +45,7 @@ fn main() {
let mut appendf = 0.0;
for _ in range(0u, rep) {
let mut map = SmallIntMap::new();
let mut map = VecMap::new();
let start = time::precise_time_s();
append_sequential(0u, max, &mut map);
let mid = time::precise_time_s();
......
......@@ -10,7 +10,7 @@
// error-pattern:capacity overflow
use std::collections::hashmap::HashMap;
use std::collections::hash_map::HashMap;
use std::uint;
use std::mem::size_of;
......
......@@ -17,7 +17,7 @@
// These tests used to be separate files, but I wanted to refactor all
// the common code.
use std::hashmap::{HashMap, HashSet};
use std::collections::{HashMap, HashSet};
use rbml::reader as EBReader;
use rbml::writer as EBWriter;
......
......@@ -10,10 +10,10 @@
#![feature(while_let)]
use std::collections::PriorityQueue;
use std::collections::BinaryHeap;
fn make_pq() -> PriorityQueue<int> {
PriorityQueue::from_vec(vec![1i,2,3])
fn make_pq() -> BinaryHeap<int> {
BinaryHeap::from_vec(vec![1i,2,3])
}
pub fn main() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册