Implement RFC 580

This commit implements RFC 580 by renaming:

* DList -> LinkedList
* Bitv -> BitVec
* BitvSet -> BitSet
* RingBuf -> VecDeque

More details are in [the
RFC](https://github.com/rust-lang/rfcs/pull/580)

[breaking-change]
This commit is contained in:
Aaron Turon 2015-02-17 23:44:55 -08:00 committed by Alexis
parent dfc5c0f1e8
commit 5fa9de16df
12 changed files with 917 additions and 876 deletions

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@ use core::ops::{Index, IndexMut};
use core::{iter, fmt, mem}; use core::{iter, fmt, mem};
use Bound::{self, Included, Excluded, Unbounded}; use Bound::{self, Included, Excluded, Unbounded};
use ring_buf::RingBuf; use vec_deque::VecDeque;
use self::Continuation::{Continue, Finished}; use self::Continuation::{Continue, Finished};
use self::StackOp::*; use self::StackOp::*;
@ -75,7 +75,7 @@ pub struct BTreeMap<K, V> {
/// An abstract base over-which all other BTree iterators are built. /// An abstract base over-which all other BTree iterators are built.
struct AbsIter<T> { struct AbsIter<T> {
traversals: RingBuf<T>, traversals: VecDeque<T>,
size: usize, size: usize,
} }
@ -1189,7 +1189,7 @@ impl<K, V> BTreeMap<K, V> {
pub fn iter(&self) -> Iter<K, V> { pub fn iter(&self) -> Iter<K, V> {
let len = self.len(); let len = self.len();
// NB. The initial capacity for ringbuf is large enough to avoid reallocs in many cases. // NB. The initial capacity for ringbuf is large enough to avoid reallocs in many cases.
let mut lca = RingBuf::new(); let mut lca = VecDeque::new();
lca.push_back(Traverse::traverse(&self.root)); lca.push_back(Traverse::traverse(&self.root));
Iter { Iter {
inner: AbsIter { inner: AbsIter {
@ -1221,7 +1221,7 @@ impl<K, V> BTreeMap<K, V> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<K, V> { pub fn iter_mut(&mut self) -> IterMut<K, V> {
let len = self.len(); let len = self.len();
let mut lca = RingBuf::new(); let mut lca = VecDeque::new();
lca.push_back(Traverse::traverse(&mut self.root)); lca.push_back(Traverse::traverse(&mut self.root));
IterMut { IterMut {
inner: AbsIter { inner: AbsIter {
@ -1250,7 +1250,7 @@ impl<K, V> BTreeMap<K, V> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<K, V> { pub fn into_iter(self) -> IntoIter<K, V> {
let len = self.len(); let len = self.len();
let mut lca = RingBuf::new(); let mut lca = VecDeque::new();
lca.push_back(Traverse::traverse(self.root)); lca.push_back(Traverse::traverse(self.root));
IntoIter { IntoIter {
inner: AbsIter { inner: AbsIter {
@ -1342,7 +1342,7 @@ macro_rules! range_impl {
// A deque that encodes two search paths containing (left-to-right): // A deque that encodes two search paths containing (left-to-right):
// a series of truncated-from-the-left iterators, the LCA's doubly-truncated iterator, // a series of truncated-from-the-left iterators, the LCA's doubly-truncated iterator,
// and a series of truncated-from-the-right iterators. // and a series of truncated-from-the-right iterators.
let mut traversals = RingBuf::new(); let mut traversals = VecDeque::new();
let (root, min, max) = ($root, $min, $max); let (root, min, max) = ($root, $min, $max);
let mut leftmost = None; let mut leftmost = None;

View File

@ -49,17 +49,33 @@ extern crate alloc;
#[cfg(test)] #[macro_use] extern crate log; #[cfg(test)] #[macro_use] extern crate log;
pub use binary_heap::BinaryHeap; pub use binary_heap::BinaryHeap;
pub use bitv::Bitv; pub use bit_vec::BitVec;
pub use bitv_set::BitvSet; pub use bit_set::BitSet;
pub use btree_map::BTreeMap; pub use btree_map::BTreeMap;
pub use btree_set::BTreeSet; pub use btree_set::BTreeSet;
pub use dlist::DList; pub use linked_list::LinkedList;
pub use enum_set::EnumSet; pub use enum_set::EnumSet;
pub use ring_buf::RingBuf; pub use vec_deque::VecDeque;
pub use string::String; pub use string::String;
pub use vec::Vec; pub use vec::Vec;
pub use vec_map::VecMap; pub use vec_map::VecMap;
#[deprecated(since = "1.0.0", reason = "renamed to vec_deque")]
#[unstable(feature = "collections")]
pub use vec_deque as ring_buf;
#[deprecated(since = "1.0.0", reason = "renamed to linked_list")]
#[unstable(feature = "collections")]
pub use linked_list as dlist;
#[deprecated(since = "1.0.0", reason = "renamed to bit_vec")]
#[unstable(feature = "collections")]
pub use bit_vec as bitv;
#[deprecated(since = "1.0.0", reason = "renamed to bit_set")]
#[unstable(feature = "collections")]
pub use bit_set as bitv_set;
// Needed for the vec! macro // Needed for the vec! macro
pub use alloc::boxed; pub use alloc::boxed;
@ -71,10 +87,10 @@ mod macros;
pub mod binary_heap; pub mod binary_heap;
mod bit; mod bit;
mod btree; mod btree;
pub mod dlist; pub mod linked_list;
pub mod enum_set; pub mod enum_set;
pub mod fmt; pub mod fmt;
pub mod ring_buf; pub mod vec_deque;
pub mod slice; pub mod slice;
pub mod str; pub mod str;
pub mod string; pub mod string;
@ -83,15 +99,23 @@ pub mod vec_map;
#[unstable(feature = "collections", #[unstable(feature = "collections",
reason = "RFC 509")] reason = "RFC 509")]
pub mod bitv { pub mod bit_vec {
pub use bit::{Bitv, Iter}; pub use bit::{BitVec, Iter};
#[deprecated(since = "1.0.0", reason = "renamed to BitVec")]
#[unstable(feature = "collections")]
pub use bit::BitVec as Bitv;
} }
#[unstable(feature = "collections", #[unstable(feature = "collections",
reason = "RFC 509")] reason = "RFC 509")]
pub mod bitv_set { pub mod bit_set {
pub use bit::{BitvSet, Union, Intersection, Difference, SymmetricDifference}; pub use bit::{BitSet, Union, Intersection, Difference, SymmetricDifference};
pub use bit::SetIter as Iter; pub use bit::SetIter as Iter;
#[deprecated(since = "1.0.0", reason = "renamed to BitSet")]
#[unstable(feature = "collections")]
pub use bit::BitSet as BitvSet;
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]

View File

@ -10,13 +10,13 @@
//! A doubly-linked list with owned nodes. //! A doubly-linked list with owned nodes.
//! //!
//! The `DList` allows pushing and popping elements at either end and is thus //! The `LinkedList` allows pushing and popping elements at either end and is thus
//! efficiently usable as a double-ended queue. //! efficiently usable as a double-ended queue.
// DList is constructed like a singly-linked list over the field `next`. // LinkedList is constructed like a singly-linked list over the field `next`.
// including the last link being None; each Node owns its `next` field. // including the last link being None; each Node owns its `next` field.
// //
// Backlinks over DList::prev are raw pointers that form a full chain in // Backlinks over LinkedList::prev are raw pointers that form a full chain in
// the reverse direction. // the reverse direction.
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]
@ -32,9 +32,13 @@ use core::iter::{self, FromIterator, IntoIterator};
use core::mem; use core::mem;
use core::ptr; use core::ptr;
#[deprecated(since = "1.0.0", reason = "renamed to LinkedList")]
#[unstable(feature = "collections")]
pub use LinkedList as DList;
/// A doubly-linked list. /// A doubly-linked list.
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct DList<T> { pub struct LinkedList<T> {
length: usize, length: usize,
list_head: Link<T>, list_head: Link<T>,
list_tail: Rawlink<Node<T>>, list_tail: Rawlink<Node<T>>,
@ -56,7 +60,7 @@ struct Node<T> {
value: T, value: T,
} }
/// An iterator over references to the items of a `DList`. /// An iterator over references to the items of a `LinkedList`.
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T:'a> { pub struct Iter<'a, T:'a> {
head: &'a Link<T>, head: &'a Link<T>,
@ -76,20 +80,20 @@ impl<'a, T> Clone for Iter<'a, T> {
} }
} }
/// An iterator over mutable references to the items of a `DList`. /// An iterator over mutable references to the items of a `LinkedList`.
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T:'a> { pub struct IterMut<'a, T:'a> {
list: &'a mut DList<T>, list: &'a mut LinkedList<T>,
head: Rawlink<Node<T>>, head: Rawlink<Node<T>>,
tail: Rawlink<Node<T>>, tail: Rawlink<Node<T>>,
nelem: usize, nelem: usize,
} }
/// An iterator over mutable references to the items of a `DList`. /// An iterator over mutable references to the items of a `LinkedList`.
#[derive(Clone)] #[derive(Clone)]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> { pub struct IntoIter<T> {
list: DList<T> list: LinkedList<T>
} }
/// Rawlink is a type like Option<T> but for holding a raw pointer /// Rawlink is a type like Option<T> but for holding a raw pointer
@ -147,7 +151,7 @@ fn link_with_prev<T>(mut next: Box<Node<T>>, prev: Rawlink<Node<T>>)
} }
// private methods // private methods
impl<T> DList<T> { impl<T> LinkedList<T> {
/// Add a Node first in the list /// Add a Node first in the list
#[inline] #[inline]
fn push_front_node(&mut self, mut new_head: Box<Node<T>>) { fn push_front_node(&mut self, mut new_head: Box<Node<T>>) {
@ -207,18 +211,18 @@ impl<T> DList<T> {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for DList<T> { impl<T> Default for LinkedList<T> {
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
fn default() -> DList<T> { DList::new() } fn default() -> LinkedList<T> { LinkedList::new() }
} }
impl<T> DList<T> { impl<T> LinkedList<T> {
/// Creates an empty `DList`. /// Creates an empty `LinkedList`.
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> DList<T> { pub fn new() -> LinkedList<T> {
DList{list_head: None, list_tail: Rawlink::none(), length: 0} LinkedList{list_head: None, list_tail: Rawlink::none(), length: 0}
} }
/// Moves all elements from `other` to the end of the list. /// Moves all elements from `other` to the end of the list.
@ -231,10 +235,10 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut a = DList::new(); /// let mut a = LinkedList::new();
/// let mut b = DList::new(); /// let mut b = LinkedList::new();
/// a.push_back(1); /// a.push_back(1);
/// a.push_back(2); /// a.push_back(2);
/// b.push_back(3); /// b.push_back(3);
@ -247,7 +251,7 @@ impl<T> DList<T> {
/// } /// }
/// println!("{}", b.len()); // prints 0 /// println!("{}", b.len()); // prints 0
/// ``` /// ```
pub fn append(&mut self, other: &mut DList<T>) { pub fn append(&mut self, other: &mut LinkedList<T>) {
match self.list_tail.resolve() { match self.list_tail.resolve() {
None => { None => {
self.length = other.length; self.length = other.length;
@ -301,16 +305,16 @@ impl<T> DList<T> {
IntoIter{list: self} IntoIter{list: self}
} }
/// Returns `true` if the `DList` is empty. /// Returns `true` if the `LinkedList` is empty.
/// ///
/// This operation should compute in O(1) time. /// This operation should compute in O(1) time.
/// ///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut dl = DList::new(); /// let mut dl = LinkedList::new();
/// assert!(dl.is_empty()); /// assert!(dl.is_empty());
/// ///
/// dl.push_front("foo"); /// dl.push_front("foo");
@ -322,16 +326,16 @@ impl<T> DList<T> {
self.list_head.is_none() self.list_head.is_none()
} }
/// Returns the length of the `DList`. /// Returns the length of the `LinkedList`.
/// ///
/// This operation should compute in O(1) time. /// This operation should compute in O(1) time.
/// ///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut dl = DList::new(); /// let mut dl = LinkedList::new();
/// ///
/// dl.push_front(2); /// dl.push_front(2);
/// assert_eq!(dl.len(), 1); /// assert_eq!(dl.len(), 1);
@ -349,16 +353,16 @@ impl<T> DList<T> {
self.length self.length
} }
/// Removes all elements from the `DList`. /// Removes all elements from the `LinkedList`.
/// ///
/// This operation should compute in O(n) time. /// This operation should compute in O(n) time.
/// ///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut dl = DList::new(); /// let mut dl = LinkedList::new();
/// ///
/// dl.push_front(2); /// dl.push_front(2);
/// dl.push_front(1); /// dl.push_front(1);
@ -373,7 +377,7 @@ impl<T> DList<T> {
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) { pub fn clear(&mut self) {
*self = DList::new() *self = LinkedList::new()
} }
/// Provides a reference to the front element, or `None` if the list is /// Provides a reference to the front element, or `None` if the list is
@ -382,9 +386,9 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut dl = DList::new(); /// let mut dl = LinkedList::new();
/// assert_eq!(dl.front(), None); /// assert_eq!(dl.front(), None);
/// ///
/// dl.push_front(1); /// dl.push_front(1);
@ -403,9 +407,9 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut dl = DList::new(); /// let mut dl = LinkedList::new();
/// assert_eq!(dl.front(), None); /// assert_eq!(dl.front(), None);
/// ///
/// dl.push_front(1); /// dl.push_front(1);
@ -430,9 +434,9 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut dl = DList::new(); /// let mut dl = LinkedList::new();
/// assert_eq!(dl.back(), None); /// assert_eq!(dl.back(), None);
/// ///
/// dl.push_back(1); /// dl.push_back(1);
@ -451,9 +455,9 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut dl = DList::new(); /// let mut dl = LinkedList::new();
/// assert_eq!(dl.back(), None); /// assert_eq!(dl.back(), None);
/// ///
/// dl.push_back(1); /// dl.push_back(1);
@ -479,9 +483,9 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut dl = DList::new(); /// let mut dl = LinkedList::new();
/// ///
/// dl.push_front(2); /// dl.push_front(2);
/// assert_eq!(dl.front().unwrap(), &2); /// assert_eq!(dl.front().unwrap(), &2);
@ -503,9 +507,9 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut d = DList::new(); /// let mut d = LinkedList::new();
/// assert_eq!(d.pop_front(), None); /// assert_eq!(d.pop_front(), None);
/// ///
/// d.push_front(1); /// d.push_front(1);
@ -526,9 +530,9 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut d = DList::new(); /// let mut d = LinkedList::new();
/// d.push_back(1); /// d.push_back(1);
/// d.push_back(3); /// d.push_back(3);
/// assert_eq!(3, *d.back().unwrap()); /// assert_eq!(3, *d.back().unwrap());
@ -544,9 +548,9 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut d = DList::new(); /// let mut d = LinkedList::new();
/// assert_eq!(d.pop_back(), None); /// assert_eq!(d.pop_back(), None);
/// d.push_back(1); /// d.push_back(1);
/// d.push_back(3); /// d.push_back(3);
@ -569,9 +573,9 @@ impl<T> DList<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut d = DList::new(); /// let mut d = LinkedList::new();
/// ///
/// d.push_front(1); /// d.push_front(1);
/// d.push_front(2); /// d.push_front(2);
@ -583,13 +587,13 @@ impl<T> DList<T> {
/// assert_eq!(splitted.pop_front(), None); /// assert_eq!(splitted.pop_front(), None);
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn split_off(&mut self, at: usize) -> DList<T> { pub fn split_off(&mut self, at: usize) -> LinkedList<T> {
let len = self.len(); let len = self.len();
assert!(at <= len, "Cannot split off at a nonexistent index"); assert!(at <= len, "Cannot split off at a nonexistent index");
if at == 0 { if at == 0 {
return mem::replace(self, DList::new()); return mem::replace(self, LinkedList::new());
} else if at == len { } else if at == len {
return DList::new(); return LinkedList::new();
} }
// Below, we iterate towards the `i-1`th node, either from the start or the end, // Below, we iterate towards the `i-1`th node, either from the start or the end,
@ -612,7 +616,7 @@ impl<T> DList<T> {
iter.tail iter.tail
}; };
let mut splitted_list = DList { let mut splitted_list = LinkedList {
list_head: None, list_head: None,
list_tail: self.list_tail, list_tail: self.list_tail,
length: len - at length: len - at
@ -628,9 +632,9 @@ impl<T> DList<T> {
#[unsafe_destructor] #[unsafe_destructor]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for DList<T> { impl<T> Drop for LinkedList<T> {
fn drop(&mut self) { fn drop(&mut self) {
// Dissolve the dlist in backwards direction // Dissolve the linked_list in backwards direction
// Just dropping the list_head can lead to stack exhaustion // Just dropping the list_head can lead to stack exhaustion
// when length is >> 1_000_000 // when length is >> 1_000_000
let mut tail = self.list_tail; let mut tail = self.list_tail;
@ -761,9 +765,9 @@ impl<'a, A> IterMut<'a, A> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut list: DList<_> = vec![1, 3, 4].into_iter().collect(); /// let mut list: LinkedList<_> = vec![1, 3, 4].into_iter().collect();
/// ///
/// { /// {
/// let mut it = list.iter_mut(); /// let mut it = list.iter_mut();
@ -788,9 +792,9 @@ impl<'a, A> IterMut<'a, A> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::DList; /// use std::collections::LinkedList;
/// ///
/// let mut list: DList<_> = vec![1, 2, 3].into_iter().collect(); /// let mut list: LinkedList<_> = vec![1, 2, 3].into_iter().collect();
/// ///
/// let mut it = list.iter_mut(); /// let mut it = list.iter_mut();
/// assert_eq!(it.next().unwrap(), &1); /// assert_eq!(it.next().unwrap(), &1);
@ -829,16 +833,16 @@ impl<A> DoubleEndedIterator for IntoIter<A> {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A> FromIterator<A> for DList<A> { impl<A> FromIterator<A> for LinkedList<A> {
fn from_iter<T: Iterator<Item=A>>(iterator: T) -> DList<A> { fn from_iter<T: Iterator<Item=A>>(iterator: T) -> LinkedList<A> {
let mut ret = DList::new(); let mut ret = LinkedList::new();
ret.extend(iterator); ret.extend(iterator);
ret ret
} }
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T> IntoIterator for DList<T> { impl<T> IntoIterator for LinkedList<T> {
type Item = T; type Item = T;
type IntoIter = IntoIter<T>; type IntoIter = IntoIter<T>;
@ -848,7 +852,7 @@ impl<T> IntoIterator for DList<T> {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a DList<T> { impl<'a, T> IntoIterator for &'a LinkedList<T> {
type Item = &'a T; type Item = &'a T;
type IntoIter = Iter<'a, T>; type IntoIter = Iter<'a, T>;
@ -857,7 +861,7 @@ impl<'a, T> IntoIterator for &'a DList<T> {
} }
} }
impl<'a, T> IntoIterator for &'a mut DList<T> { impl<'a, T> IntoIterator for &'a mut LinkedList<T> {
type Item = &'a mut T; type Item = &'a mut T;
type IntoIter = IterMut<'a, T>; type IntoIter = IterMut<'a, T>;
@ -867,54 +871,54 @@ impl<'a, T> IntoIterator for &'a mut DList<T> {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A> Extend<A> for DList<A> { impl<A> Extend<A> for LinkedList<A> {
fn extend<T: Iterator<Item=A>>(&mut self, iterator: T) { fn extend<T: Iterator<Item=A>>(&mut self, iterator: T) {
for elt in iterator { self.push_back(elt); } for elt in iterator { self.push_back(elt); }
} }
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialEq> PartialEq for DList<A> { impl<A: PartialEq> PartialEq for LinkedList<A> {
fn eq(&self, other: &DList<A>) -> bool { fn eq(&self, other: &LinkedList<A>) -> bool {
self.len() == other.len() && self.len() == other.len() &&
iter::order::eq(self.iter(), other.iter()) iter::order::eq(self.iter(), other.iter())
} }
fn ne(&self, other: &DList<A>) -> bool { fn ne(&self, other: &LinkedList<A>) -> bool {
self.len() != other.len() || self.len() != other.len() ||
iter::order::ne(self.iter(), other.iter()) iter::order::ne(self.iter(), other.iter())
} }
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: Eq> Eq for DList<A> {} impl<A: Eq> Eq for LinkedList<A> {}
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialOrd> PartialOrd for DList<A> { impl<A: PartialOrd> PartialOrd for LinkedList<A> {
fn partial_cmp(&self, other: &DList<A>) -> Option<Ordering> { fn partial_cmp(&self, other: &LinkedList<A>) -> Option<Ordering> {
iter::order::partial_cmp(self.iter(), other.iter()) iter::order::partial_cmp(self.iter(), other.iter())
} }
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: Ord> Ord for DList<A> { impl<A: Ord> Ord for LinkedList<A> {
#[inline] #[inline]
fn cmp(&self, other: &DList<A>) -> Ordering { fn cmp(&self, other: &LinkedList<A>) -> Ordering {
iter::order::cmp(self.iter(), other.iter()) iter::order::cmp(self.iter(), other.iter())
} }
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: Clone> Clone for DList<A> { impl<A: Clone> Clone for LinkedList<A> {
fn clone(&self) -> DList<A> { fn clone(&self) -> LinkedList<A> {
self.iter().map(|x| x.clone()).collect() self.iter().map(|x| x.clone()).collect()
} }
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: fmt::Debug> fmt::Debug for DList<A> { impl<A: fmt::Debug> fmt::Debug for LinkedList<A> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "DList [")); try!(write!(f, "LinkedList ["));
for (i, e) in self.iter().enumerate() { for (i, e) in self.iter().enumerate() {
if i != 0 { try!(write!(f, ", ")); } if i != 0 { try!(write!(f, ", ")); }
@ -926,7 +930,7 @@ impl<A: fmt::Debug> fmt::Debug for DList<A> {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<S: Writer + Hasher, A: Hash<S>> Hash<S> for DList<A> { impl<S: Writer + Hasher, A: Hash<S>> Hash<S> for LinkedList<A> {
fn hash(&self, state: &mut S) { fn hash(&self, state: &mut S) {
self.len().hash(state); self.len().hash(state);
for elt in self { for elt in self {
@ -944,9 +948,9 @@ mod tests {
use test::Bencher; use test::Bencher;
use test; use test;
use super::{DList, Node}; use super::{LinkedList, Node};
pub fn check_links<T>(list: &DList<T>) { pub fn check_links<T>(list: &LinkedList<T>) {
let mut len = 0; let mut len = 0;
let mut last_ptr: Option<&Node<T>> = None; let mut last_ptr: Option<&Node<T>> = None;
let mut node_ptr: &Node<T>; let mut node_ptr: &Node<T>;
@ -980,7 +984,7 @@ mod tests {
#[test] #[test]
fn test_basic() { fn test_basic() {
let mut m = DList::new(); let mut m = LinkedList::new();
assert_eq!(m.pop_front(), None); assert_eq!(m.pop_front(), None);
assert_eq!(m.pop_back(), None); assert_eq!(m.pop_back(), None);
assert_eq!(m.pop_front(), None); assert_eq!(m.pop_front(), None);
@ -999,7 +1003,7 @@ mod tests {
m.push_back(box 7); m.push_back(box 7);
assert_eq!(m.pop_front(), Some(box 1)); assert_eq!(m.pop_front(), Some(box 1));
let mut n = DList::new(); let mut n = LinkedList::new();
n.push_front(2); n.push_front(2);
n.push_front(3); n.push_front(3);
{ {
@ -1019,12 +1023,12 @@ mod tests {
} }
#[cfg(test)] #[cfg(test)]
fn generate_test() -> DList<i32> { fn generate_test() -> LinkedList<i32> {
list_from(&[0,1,2,3,4,5,6]) list_from(&[0,1,2,3,4,5,6])
} }
#[cfg(test)] #[cfg(test)]
fn list_from<T: Clone>(v: &[T]) -> DList<T> { fn list_from<T: Clone>(v: &[T]) -> LinkedList<T> {
v.iter().map(|x| (*x).clone()).collect() v.iter().map(|x| (*x).clone()).collect()
} }
@ -1032,8 +1036,8 @@ mod tests {
fn test_append() { fn test_append() {
// Empty to empty // Empty to empty
{ {
let mut m = DList::<i32>::new(); let mut m = LinkedList::<i32>::new();
let mut n = DList::new(); let mut n = LinkedList::new();
m.append(&mut n); m.append(&mut n);
check_links(&m); check_links(&m);
assert_eq!(m.len(), 0); assert_eq!(m.len(), 0);
@ -1041,8 +1045,8 @@ mod tests {
} }
// Non-empty to empty // Non-empty to empty
{ {
let mut m = DList::new(); let mut m = LinkedList::new();
let mut n = DList::new(); let mut n = LinkedList::new();
n.push_back(2); n.push_back(2);
m.append(&mut n); m.append(&mut n);
check_links(&m); check_links(&m);
@ -1053,8 +1057,8 @@ mod tests {
} }
// Empty to non-empty // Empty to non-empty
{ {
let mut m = DList::new(); let mut m = LinkedList::new();
let mut n = DList::new(); let mut n = LinkedList::new();
m.push_back(2); m.push_back(2);
m.append(&mut n); m.append(&mut n);
check_links(&m); check_links(&m);
@ -1089,7 +1093,7 @@ mod tests {
fn test_split_off() { fn test_split_off() {
// singleton // singleton
{ {
let mut m = DList::new(); let mut m = LinkedList::new();
m.push_back(1); m.push_back(1);
let p = m.split_off(0); let p = m.split_off(0);
@ -1130,7 +1134,7 @@ mod tests {
// no-op on the last index // no-op on the last index
{ {
let mut m = DList::new(); let mut m = LinkedList::new();
m.push_back(1); m.push_back(1);
let p = m.split_off(1); let p = m.split_off(1);
@ -1148,7 +1152,7 @@ mod tests {
for (i, elt) in m.iter().enumerate() { for (i, elt) in m.iter().enumerate() {
assert_eq!(i as i32, *elt); assert_eq!(i as i32, *elt);
} }
let mut n = DList::new(); let mut n = LinkedList::new();
assert_eq!(n.iter().next(), None); assert_eq!(n.iter().next(), None);
n.push_front(4); n.push_front(4);
let mut it = n.iter(); let mut it = n.iter();
@ -1160,7 +1164,7 @@ mod tests {
#[test] #[test]
fn test_iterator_clone() { fn test_iterator_clone() {
let mut n = DList::new(); let mut n = LinkedList::new();
n.push_back(2); n.push_back(2);
n.push_back(3); n.push_back(3);
n.push_back(4); n.push_back(4);
@ -1174,7 +1178,7 @@ mod tests {
#[test] #[test]
fn test_iterator_double_end() { fn test_iterator_double_end() {
let mut n = DList::new(); let mut n = LinkedList::new();
assert_eq!(n.iter().next(), None); assert_eq!(n.iter().next(), None);
n.push_front(4); n.push_front(4);
n.push_front(5); n.push_front(5);
@ -1196,7 +1200,7 @@ mod tests {
for (i, elt) in m.iter().rev().enumerate() { for (i, elt) in m.iter().rev().enumerate() {
assert_eq!((6 - i) as i32, *elt); assert_eq!((6 - i) as i32, *elt);
} }
let mut n = DList::new(); let mut n = LinkedList::new();
assert_eq!(n.iter().rev().next(), None); assert_eq!(n.iter().rev().next(), None);
n.push_front(4); n.push_front(4);
let mut it = n.iter().rev(); let mut it = n.iter().rev();
@ -1215,7 +1219,7 @@ mod tests {
len -= 1; len -= 1;
} }
assert_eq!(len, 0); assert_eq!(len, 0);
let mut n = DList::new(); let mut n = LinkedList::new();
assert!(n.iter_mut().next().is_none()); assert!(n.iter_mut().next().is_none());
n.push_front(4); n.push_front(4);
n.push_back(5); n.push_back(5);
@ -1229,7 +1233,7 @@ mod tests {
#[test] #[test]
fn test_iterator_mut_double_end() { fn test_iterator_mut_double_end() {
let mut n = DList::new(); let mut n = LinkedList::new();
assert!(n.iter_mut().next_back().is_none()); assert!(n.iter_mut().next_back().is_none());
n.push_front(4); n.push_front(4);
n.push_front(5); n.push_front(5);
@ -1278,7 +1282,7 @@ mod tests {
for (i, elt) in m.iter_mut().rev().enumerate() { for (i, elt) in m.iter_mut().rev().enumerate() {
assert_eq!((6 - i) as i32, *elt); assert_eq!((6 - i) as i32, *elt);
} }
let mut n = DList::new(); let mut n = LinkedList::new();
assert!(n.iter_mut().rev().next().is_none()); assert!(n.iter_mut().rev().next().is_none());
n.push_front(4); n.push_front(4);
let mut it = n.iter_mut().rev(); let mut it = n.iter_mut().rev();
@ -1313,8 +1317,8 @@ mod tests {
#[test] #[test]
fn test_hash() { fn test_hash() {
let mut x = DList::new(); let mut x = LinkedList::new();
let mut y = DList::new(); let mut y = LinkedList::new();
assert!(hash::hash::<_, SipHasher>(&x) == hash::hash::<_, SipHasher>(&y)); assert!(hash::hash::<_, SipHasher>(&x) == hash::hash::<_, SipHasher>(&y));
@ -1382,16 +1386,16 @@ mod tests {
#[test] #[test]
fn test_show() { fn test_show() {
let list: DList<_> = (0..10).collect(); let list: LinkedList<_> = (0..10).collect();
assert_eq!(format!("{:?}", list), "DList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); assert_eq!(format!("{:?}", list), "LinkedList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
let list: DList<_> = vec!["just", "one", "test", "more"].iter().cloned().collect(); let list: LinkedList<_> = vec!["just", "one", "test", "more"].iter().cloned().collect();
assert_eq!(format!("{:?}", list), "DList [\"just\", \"one\", \"test\", \"more\"]"); assert_eq!(format!("{:?}", list), "LinkedList [\"just\", \"one\", \"test\", \"more\"]");
} }
#[cfg(test)] #[cfg(test)]
fn fuzz_test(sz: i32) { fn fuzz_test(sz: i32) {
let mut m: DList<_> = DList::new(); let mut m: LinkedList<_> = LinkedList::new();
let mut v = vec![]; let mut v = vec![];
for i in 0..sz { for i in 0..sz {
check_links(&m); check_links(&m);
@ -1432,13 +1436,13 @@ mod tests {
fn bench_collect_into(b: &mut test::Bencher) { fn bench_collect_into(b: &mut test::Bencher) {
let v = &[0; 64]; let v = &[0; 64];
b.iter(|| { b.iter(|| {
let _: DList<_> = v.iter().cloned().collect(); let _: LinkedList<_> = v.iter().cloned().collect();
}) })
} }
#[bench] #[bench]
fn bench_push_front(b: &mut test::Bencher) { fn bench_push_front(b: &mut test::Bencher) {
let mut m: DList<_> = DList::new(); let mut m: LinkedList<_> = LinkedList::new();
b.iter(|| { b.iter(|| {
m.push_front(0); m.push_front(0);
}) })
@ -1446,7 +1450,7 @@ mod tests {
#[bench] #[bench]
fn bench_push_back(b: &mut test::Bencher) { fn bench_push_back(b: &mut test::Bencher) {
let mut m: DList<_> = DList::new(); let mut m: LinkedList<_> = LinkedList::new();
b.iter(|| { b.iter(|| {
m.push_back(0); m.push_back(0);
}) })
@ -1454,7 +1458,7 @@ mod tests {
#[bench] #[bench]
fn bench_push_back_pop_back(b: &mut test::Bencher) { fn bench_push_back_pop_back(b: &mut test::Bencher) {
let mut m: DList<_> = DList::new(); let mut m: LinkedList<_> = LinkedList::new();
b.iter(|| { b.iter(|| {
m.push_back(0); m.push_back(0);
m.pop_back(); m.pop_back();
@ -1463,7 +1467,7 @@ mod tests {
#[bench] #[bench]
fn bench_push_front_pop_front(b: &mut test::Bencher) { fn bench_push_front_pop_front(b: &mut test::Bencher) {
let mut m: DList<_> = DList::new(); let mut m: LinkedList<_> = LinkedList::new();
b.iter(|| { b.iter(|| {
m.push_front(0); m.push_front(0);
m.pop_front(); m.pop_front();
@ -1473,7 +1477,7 @@ mod tests {
#[bench] #[bench]
fn bench_iter(b: &mut test::Bencher) { fn bench_iter(b: &mut test::Bencher) {
let v = &[0; 128]; let v = &[0; 128];
let m: DList<_> = v.iter().cloned().collect(); let m: LinkedList<_> = v.iter().cloned().collect();
b.iter(|| { b.iter(|| {
assert!(m.iter().count() == 128); assert!(m.iter().count() == 128);
}) })
@ -1481,7 +1485,7 @@ mod tests {
#[bench] #[bench]
fn bench_iter_mut(b: &mut test::Bencher) { fn bench_iter_mut(b: &mut test::Bencher) {
let v = &[0; 128]; let v = &[0; 128];
let mut m: DList<_> = v.iter().cloned().collect(); let mut m: LinkedList<_> = v.iter().cloned().collect();
b.iter(|| { b.iter(|| {
assert!(m.iter_mut().count() == 128); assert!(m.iter_mut().count() == 128);
}) })
@ -1489,7 +1493,7 @@ mod tests {
#[bench] #[bench]
fn bench_iter_rev(b: &mut test::Bencher) { fn bench_iter_rev(b: &mut test::Bencher) {
let v = &[0; 128]; let v = &[0; 128];
let m: DList<_> = v.iter().cloned().collect(); let m: LinkedList<_> = v.iter().cloned().collect();
b.iter(|| { b.iter(|| {
assert!(m.iter().rev().count() == 128); assert!(m.iter().rev().count() == 128);
}) })
@ -1497,7 +1501,7 @@ mod tests {
#[bench] #[bench]
fn bench_iter_mut_rev(b: &mut test::Bencher) { fn bench_iter_mut_rev(b: &mut test::Bencher) {
let v = &[0; 128]; let v = &[0; 128];
let mut m: DList<_> = v.iter().cloned().collect(); let mut m: LinkedList<_> = v.iter().cloned().collect();
b.iter(|| { b.iter(|| {
assert!(m.iter_mut().rev().count() == 128); assert!(m.iter_mut().rev().count() == 128);
}) })

View File

@ -68,7 +68,7 @@ use core::slice::AsSlice;
use core::str as core_str; use core::str as core_str;
use unicode::str::{UnicodeStr, Utf16Encoder}; use unicode::str::{UnicodeStr, Utf16Encoder};
use ring_buf::RingBuf; use vec_deque::VecDeque;
use slice::SliceExt; use slice::SliceExt;
use string::String; use string::String;
use unicode; use unicode;
@ -261,7 +261,7 @@ enum RecompositionState {
pub struct Recompositions<'a> { pub struct Recompositions<'a> {
iter: Decompositions<'a>, iter: Decompositions<'a>,
state: RecompositionState, state: RecompositionState,
buffer: RingBuf<char>, buffer: VecDeque<char>,
composee: Option<char>, composee: Option<char>,
last_ccc: Option<u8> last_ccc: Option<u8>
} }
@ -496,7 +496,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
Recompositions { Recompositions {
iter: self.nfd_chars(), iter: self.nfd_chars(),
state: Composing, state: Composing,
buffer: RingBuf::new(), buffer: VecDeque::new(),
composee: None, composee: None,
last_ccc: None last_ccc: None
} }
@ -511,7 +511,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
Recompositions { Recompositions {
iter: self.nfkd_chars(), iter: self.nfkd_chars(),
state: Composing, state: Composing,
buffer: RingBuf::new(), buffer: VecDeque::new(),
composee: None, composee: None,
last_ccc: None last_ccc: None
} }

View File

@ -37,7 +37,7 @@ use util::ppaux::{ty_to_string};
use util::nodemap::{FnvHashMap, NodeSet}; use util::nodemap::{FnvHashMap, NodeSet};
use lint::{Level, Context, LintPass, LintArray, Lint}; use lint::{Level, Context, LintPass, LintArray, Lint};
use std::collections::BitvSet; use std::collections::BitSet;
use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::num::SignedInt; use std::num::SignedInt;
use std::{cmp, slice}; use std::{cmp, slice};
@ -1792,7 +1792,7 @@ impl LintPass for UnconditionalRecursion {
let mut work_queue = vec![cfg.entry]; let mut work_queue = vec![cfg.entry];
let mut reached_exit_without_self_call = false; let mut reached_exit_without_self_call = false;
let mut self_call_spans = vec![]; let mut self_call_spans = vec![];
let mut visited = BitvSet::new(); let mut visited = BitSet::new();
while let Some(idx) = work_queue.pop() { while let Some(idx) = work_queue.pop() {
let cfg_id = idx.node_id(); let cfg_id = idx.node_id();

View File

@ -34,7 +34,7 @@
use std::fmt::{Formatter, Error, Debug}; use std::fmt::{Formatter, Error, Debug};
use std::usize; use std::usize;
use std::collections::BitvSet; use std::collections::BitSet;
pub struct Graph<N,E> { pub struct Graph<N,E> {
nodes: Vec<Node<N>> , nodes: Vec<Node<N>> ,
@ -292,7 +292,7 @@ impl<N,E> Graph<N,E> {
DepthFirstTraversal { DepthFirstTraversal {
graph: self, graph: self,
stack: vec![start], stack: vec![start],
visited: BitvSet::new() visited: BitSet::new()
} }
} }
} }
@ -300,7 +300,7 @@ impl<N,E> Graph<N,E> {
pub struct DepthFirstTraversal<'g, N:'g, E:'g> { pub struct DepthFirstTraversal<'g, N:'g, E:'g> {
graph: &'g Graph<N, E>, graph: &'g Graph<N, E>,
stack: Vec<NodeIndex>, stack: Vec<NodeIndex>,
visited: BitvSet visited: BitSet
} }
impl<'g, N, E> Iterator for DepthFirstTraversal<'g, N, E> { impl<'g, N, E> Iterator for DepthFirstTraversal<'g, N, E> {

View File

@ -16,12 +16,12 @@ use std::hash::{Hash, Hasher};
use std::collections::hash_state::HashState; use std::collections::hash_state::HashState;
use {Decodable, Encodable, Decoder, Encoder}; use {Decodable, Encodable, Decoder, Encoder};
use std::collections::{DList, RingBuf, BTreeMap, BTreeSet, HashMap, HashSet, VecMap}; use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSet, VecMap};
use collections::enum_set::{EnumSet, CLike}; use collections::enum_set::{EnumSet, CLike};
impl< impl<
T: Encodable T: Encodable
> Encodable for DList<T> { > Encodable for LinkedList<T> {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| { s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() { for (i, e) in self.iter().enumerate() {
@ -32,10 +32,10 @@ impl<
} }
} }
impl<T:Decodable> Decodable for DList<T> { impl<T:Decodable> Decodable for LinkedList<T> {
fn decode<D: Decoder>(d: &mut D) -> Result<DList<T>, D::Error> { fn decode<D: Decoder>(d: &mut D) -> Result<LinkedList<T>, D::Error> {
d.read_seq(|d, len| { d.read_seq(|d, len| {
let mut list = DList::new(); let mut list = LinkedList::new();
for i in 0..len { for i in 0..len {
list.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d)))); list.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
} }
@ -44,7 +44,7 @@ impl<T:Decodable> Decodable for DList<T> {
} }
} }
impl<T: Encodable> Encodable for RingBuf<T> { impl<T: Encodable> Encodable for VecDeque<T> {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| { s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() { for (i, e) in self.iter().enumerate() {
@ -55,10 +55,10 @@ impl<T: Encodable> Encodable for RingBuf<T> {
} }
} }
impl<T:Decodable> Decodable for RingBuf<T> { impl<T:Decodable> Decodable for VecDeque<T> {
fn decode<D: Decoder>(d: &mut D) -> Result<RingBuf<T>, D::Error> { fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> {
d.read_seq(|d, len| { d.read_seq(|d, len| {
let mut deque: RingBuf<T> = RingBuf::new(); let mut deque: VecDeque<T> = VecDeque::new();
for i in 0..len { for i in 0..len {
deque.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d)))); deque.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
} }

View File

@ -23,7 +23,7 @@
//! //!
//! Rust's collections can be grouped into four major categories: //! Rust's collections can be grouped into four major categories:
//! //!
//! * Sequences: `Vec`, `RingBuf`, `DList`, `BitV` //! * Sequences: `Vec`, `VecDeque`, `LinkedList`, `BitV`
//! * Maps: `HashMap`, `BTreeMap`, `VecMap` //! * Maps: `HashMap`, `BTreeMap`, `VecMap`
//! * Sets: `HashSet`, `BTreeSet`, `BitVSet` //! * Sets: `HashSet`, `BTreeSet`, `BitVSet`
//! * Misc: `BinaryHeap` //! * Misc: `BinaryHeap`
@ -43,13 +43,13 @@
//! * You want a resizable array. //! * You want a resizable array.
//! * You want a heap-allocated array. //! * You want a heap-allocated array.
//! //!
//! ### Use a `RingBuf` when: //! ### Use a `VecDeque` when:
//! * You want a `Vec` that supports efficient insertion at both ends of the sequence. //! * You want a `Vec` that supports efficient insertion at both ends of the sequence.
//! * You want a queue. //! * You want a queue.
//! * You want a double-ended queue (deque). //! * You want a double-ended queue (deque).
//! //!
//! ### Use a `DList` when: //! ### Use a `LinkedList` when:
//! * You want a `Vec` or `RingBuf` of unknown size, and can't tolerate amortization. //! * You want a `Vec` or `VecDeque` of unknown size, and can't tolerate amortization.
//! * You want to efficiently split and append lists. //! * You want to efficiently split and append lists.
//! * You are *absolutely* certain you *really*, *truly*, want a doubly linked list. //! * You are *absolutely* certain you *really*, *truly*, want a doubly linked list.
//! //!
@ -75,7 +75,7 @@
//! //!
//! ### Use a `BitV` when: //! ### Use a `BitV` when:
//! * You want to store an unbounded number of booleans in a small space. //! * You want to store an unbounded number of booleans in a small space.
//! * You want a bitvector. //! * You want a bit vector.
//! //!
//! ### Use a `BitVSet` when: //! ### Use a `BitVSet` when:
//! * You want a `VecSet`. //! * You want a `VecSet`.
@ -106,20 +106,20 @@
//! //!
//! ## Sequences //! ## Sequences
//! //!
//! | | get(i) | insert(i) | remove(i) | append | split_off(i) | //! | | get(i) | insert(i) | remove(i) | append | split_off(i) |
//! |---------|----------------|-----------------|----------------|--------|----------------| //! |--------------|----------------|-----------------|----------------|--------|----------------|
//! | Vec | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) | //! | Vec | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
//! | RingBuf | O(1) | O(min(i, n-i))* | O(min(i, n-i)) | O(m)* | O(min(i, n-i)) | //! | VecDeque | O(1) | O(min(i, n-i))* | O(min(i, n-i)) | O(m)* | O(min(i, n-i)) |
//! | DList | O(min(i, n-i)) | O(min(i, n-i)) | O(min(i, n-i)) | O(1) | O(min(i, n-i)) | //! | LinkedList | O(min(i, n-i)) | O(min(i, n-i)) | O(min(i, n-i)) | O(1) | O(min(i, n-i)) |
//! | Bitv | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) | //! | BitVec | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
//! //!
//! Note that where ties occur, Vec is generally going to be faster than RingBuf, and RingBuf //! Note that where ties occur, Vec is generally going to be faster than VecDeque, and VecDeque
//! is generally going to be faster than DList. Bitv is not a general purpose collection, and //! is generally going to be faster than LinkedList. BitVec is not a general purpose collection, and
//! therefore cannot reasonably be compared. //! therefore cannot reasonably be compared.
//! //!
//! ## Maps //! ## Maps
//! //!
//! For Sets, all operations have the cost of the equivalent Map operation. For BitvSet, //! For Sets, all operations have the cost of the equivalent Map operation. For BitSet,
//! refer to VecMap. //! refer to VecMap.
//! //!
//! | | get | insert | remove | predecessor | //! | | get | insert | remove | predecessor |
@ -166,7 +166,7 @@
//! //!
//! Any `with_capacity` constructor will instruct the collection to allocate enough space //! Any `with_capacity` constructor will instruct the collection to allocate enough space
//! for the specified number of elements. Ideally this will be for exactly that many //! for the specified number of elements. Ideally this will be for exactly that many
//! elements, but some implementation details may prevent this. `Vec` and `RingBuf` can //! elements, but some implementation details may prevent this. `Vec` and `VecDeque` can
//! be relied on to allocate exactly the requested amount, though. Use `with_capacity` //! be relied on to allocate exactly the requested amount, though. Use `with_capacity`
//! when you know exactly how many elements will be inserted, or at least have a //! when you know exactly how many elements will be inserted, or at least have a
//! reasonable upper-bound on that number. //! reasonable upper-bound on that number.
@ -240,10 +240,10 @@
//! ``` //! ```
//! //!
//! ``` //! ```
//! use std::collections::RingBuf; //! use std::collections::VecDeque;
//! //!
//! let vec = vec![1, 2, 3, 4]; //! let vec = vec![1, 2, 3, 4];
//! let buf: RingBuf<_> = vec.into_iter().collect(); //! let buf: VecDeque<_> = vec.into_iter().collect();
//! ``` //! ```
//! //!
//! Iterators also provide a series of *adapter* methods for performing common tasks to //! Iterators also provide a series of *adapter* methods for performing common tasks to
@ -362,11 +362,11 @@
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]
pub use core_collections::Bound; pub use core_collections::Bound;
pub use core_collections::{BinaryHeap, Bitv, BitvSet, BTreeMap, BTreeSet}; pub use core_collections::{BinaryHeap, BitVec, BitSet, BTreeMap, BTreeSet};
pub use core_collections::{DList, RingBuf, VecMap}; pub use core_collections::{LinkedList, VecDeque, VecMap};
pub use core_collections::{binary_heap, bitv, bitv_set, btree_map, btree_set}; pub use core_collections::{binary_heap, bit_vec, bit_set, btree_map, btree_set};
pub use core_collections::{dlist, ring_buf, vec_map}; pub use core_collections::{linked_list, vec_deque, vec_map};
pub use self::hash_map::HashMap; pub use self::hash_map::HashMap;
pub use self::hash_set::HashSet; pub use self::hash_set::HashSet;

View File

@ -26,11 +26,11 @@ use parse::token;
use ptr::P; use ptr::P;
use std::cell::{RefCell, Cell}; use std::cell::{RefCell, Cell};
use std::collections::BitvSet; use std::collections::BitSet;
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt; use std::fmt;
thread_local! { static USED_ATTRS: RefCell<BitvSet> = RefCell::new(BitvSet::new()) } thread_local! { static USED_ATTRS: RefCell<BitSet> = RefCell::new(BitSet::new()) }
pub fn mark_used(attr: &Attribute) { pub fn mark_used(attr: &Attribute) {
let AttrId(id) = attr.node.id; let AttrId(id) = attr.node.id;

View File

@ -16,7 +16,7 @@ extern crate collections;
extern crate rand; extern crate rand;
use std::collections::BTreeSet; use std::collections::BTreeSet;
use std::collections::BitvSet; use std::collections::BitSet;
use std::collections::HashSet; use std::collections::HashSet;
use std::collections::hash_map::Hasher; use std::collections::hash_map::Hasher;
use std::hash::Hash; use std::hash::Hash;
@ -53,7 +53,7 @@ impl<T: Ord> MutableSet<T> for BTreeSet<T> {
fn remove(&mut self, k: &T) -> bool { self.remove(k) } fn remove(&mut self, k: &T) -> bool { self.remove(k) }
fn contains(&self, k: &T) -> bool { self.contains(k) } fn contains(&self, k: &T) -> bool { self.contains(k) }
} }
impl MutableSet<usize> for BitvSet { impl MutableSet<usize> for BitSet {
fn insert(&mut self, k: usize) { self.insert(k); } fn insert(&mut self, k: usize) { self.insert(k); }
fn remove(&mut self, k: &usize) -> bool { self.remove(k) } fn remove(&mut self, k: &usize) -> bool { self.remove(k) }
fn contains(&self, k: &usize) -> bool { self.contains(k) } fn contains(&self, k: &usize) -> bool { self.contains(k) }
@ -222,7 +222,7 @@ fn main() {
{ {
let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(seed); let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(seed);
let mut results = empty_results(); let mut results = empty_results();
results.bench_int(&mut rng, num_keys, max, || BitvSet::new()); results.bench_int(&mut rng, num_keys, max, || BitSet::new());
write_results("collections::bitv::BitvSet", &results); write_results("collections::bit_vec::BitSet", &results);
} }
} }