rollup merge of #22491: Gankro/into_iter
Conflicts: src/libcollections/bit.rs src/libcollections/linked_list.rs src/libcollections/vec_deque.rs src/libstd/sys/common/wtf8.rs
This commit is contained in:
commit
5a32b4a34f
28 changed files with 990 additions and 938 deletions
|
@ -650,8 +650,8 @@ impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {}
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Ord> FromIterator<T> for BinaryHeap<T> {
|
||||
fn from_iter<Iter: Iterator<Item=T>>(iter: Iter) -> BinaryHeap<T> {
|
||||
BinaryHeap::from_vec(iter.collect())
|
||||
fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> BinaryHeap<T> {
|
||||
BinaryHeap::from_vec(iter.into_iter().collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -677,7 +677,8 @@ impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Ord> Extend<T> for BinaryHeap<T> {
|
||||
fn extend<Iter: Iterator<Item=T>>(&mut self, iter: Iter) {
|
||||
fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
|
||||
let iter = iterable.into_iter();
|
||||
let (lower, _) = iter.size_hint();
|
||||
|
||||
self.reserve(lower);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -29,7 +29,7 @@ use core::ops::{Index, IndexMut};
|
|||
use core::{iter, fmt, mem};
|
||||
use Bound::{self, Included, Excluded, Unbounded};
|
||||
|
||||
use ring_buf::RingBuf;
|
||||
use vec_deque::VecDeque;
|
||||
|
||||
use self::Continuation::{Continue, Finished};
|
||||
use self::StackOp::*;
|
||||
|
@ -75,7 +75,7 @@ pub struct BTreeMap<K, V> {
|
|||
|
||||
/// An abstract base over-which all other BTree iterators are built.
|
||||
struct AbsIter<T> {
|
||||
traversals: RingBuf<T>,
|
||||
traversals: VecDeque<T>,
|
||||
size: usize,
|
||||
}
|
||||
|
||||
|
@ -826,7 +826,7 @@ mod stack {
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
|
||||
fn from_iter<T: Iterator<Item=(K, V)>>(iter: T) -> BTreeMap<K, V> {
|
||||
fn from_iter<T: IntoIterator<Item=(K, V)>>(iter: T) -> BTreeMap<K, V> {
|
||||
let mut map = BTreeMap::new();
|
||||
map.extend(iter);
|
||||
map
|
||||
|
@ -836,7 +836,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
|
||||
#[inline]
|
||||
fn extend<T: Iterator<Item=(K, V)>>(&mut self, iter: T) {
|
||||
fn extend<T: IntoIterator<Item=(K, V)>>(&mut self, iter: T) {
|
||||
for (k, v) in iter {
|
||||
self.insert(k, v);
|
||||
}
|
||||
|
@ -1199,7 +1199,7 @@ impl<K, V> BTreeMap<K, V> {
|
|||
pub fn iter(&self) -> Iter<K, V> {
|
||||
let len = self.len();
|
||||
// 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));
|
||||
Iter {
|
||||
inner: AbsIter {
|
||||
|
@ -1231,7 +1231,7 @@ impl<K, V> BTreeMap<K, V> {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn iter_mut(&mut self) -> IterMut<K, V> {
|
||||
let len = self.len();
|
||||
let mut lca = RingBuf::new();
|
||||
let mut lca = VecDeque::new();
|
||||
lca.push_back(Traverse::traverse(&mut self.root));
|
||||
IterMut {
|
||||
inner: AbsIter {
|
||||
|
@ -1260,7 +1260,7 @@ impl<K, V> BTreeMap<K, V> {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn into_iter(self) -> IntoIter<K, V> {
|
||||
let len = self.len();
|
||||
let mut lca = RingBuf::new();
|
||||
let mut lca = VecDeque::new();
|
||||
lca.push_back(Traverse::traverse(self.root));
|
||||
IntoIter {
|
||||
inner: AbsIter {
|
||||
|
@ -1352,7 +1352,7 @@ macro_rules! range_impl {
|
|||
// 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,
|
||||
// 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 mut leftmost = None;
|
||||
|
|
|
@ -473,7 +473,7 @@ impl<T: Ord> BTreeSet<T> {
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Ord> FromIterator<T> for BTreeSet<T> {
|
||||
fn from_iter<Iter: Iterator<Item=T>>(iter: Iter) -> BTreeSet<T> {
|
||||
fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> BTreeSet<T> {
|
||||
let mut set = BTreeSet::new();
|
||||
set.extend(iter);
|
||||
set
|
||||
|
@ -503,7 +503,7 @@ impl<'a, T> IntoIterator for &'a BTreeSet<T> {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Ord> Extend<T> for BTreeSet<T> {
|
||||
#[inline]
|
||||
fn extend<Iter: Iterator<Item=T>>(&mut self, iter: Iter) {
|
||||
fn extend<Iter: IntoIterator<Item=T>>(&mut self, iter: Iter) {
|
||||
for elem in iter {
|
||||
self.insert(elem);
|
||||
}
|
||||
|
|
|
@ -250,9 +250,9 @@ impl<E:CLike> Iterator for Iter<E> {
|
|||
}
|
||||
|
||||
impl<E:CLike> FromIterator<E> for EnumSet<E> {
|
||||
fn from_iter<I:Iterator<Item=E>>(iterator: I) -> EnumSet<E> {
|
||||
fn from_iter<I: IntoIterator<Item=E>>(iter: I) -> EnumSet<E> {
|
||||
let mut ret = EnumSet::new();
|
||||
ret.extend(iterator);
|
||||
ret.extend(iter);
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
@ -268,8 +268,8 @@ impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike {
|
|||
}
|
||||
|
||||
impl<E:CLike> Extend<E> for EnumSet<E> {
|
||||
fn extend<I: Iterator<Item=E>>(&mut self, iterator: I) {
|
||||
for element in iterator {
|
||||
fn extend<I: IntoIterator<Item=E>>(&mut self, iter: I) {
|
||||
for element in iter {
|
||||
self.insert(element);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,17 +48,33 @@ extern crate alloc;
|
|||
#[cfg(test)] #[macro_use] extern crate log;
|
||||
|
||||
pub use binary_heap::BinaryHeap;
|
||||
pub use bitv::Bitv;
|
||||
pub use bitv_set::BitvSet;
|
||||
pub use bit_vec::BitVec;
|
||||
pub use bit_set::BitSet;
|
||||
pub use btree_map::BTreeMap;
|
||||
pub use btree_set::BTreeSet;
|
||||
pub use dlist::DList;
|
||||
pub use linked_list::LinkedList;
|
||||
pub use enum_set::EnumSet;
|
||||
pub use ring_buf::RingBuf;
|
||||
pub use vec_deque::VecDeque;
|
||||
pub use string::String;
|
||||
pub use vec::Vec;
|
||||
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
|
||||
pub use alloc::boxed;
|
||||
|
||||
|
@ -70,10 +86,10 @@ mod macros;
|
|||
pub mod binary_heap;
|
||||
mod bit;
|
||||
mod btree;
|
||||
pub mod dlist;
|
||||
pub mod linked_list;
|
||||
pub mod enum_set;
|
||||
pub mod fmt;
|
||||
pub mod ring_buf;
|
||||
pub mod vec_deque;
|
||||
pub mod slice;
|
||||
pub mod str;
|
||||
pub mod string;
|
||||
|
@ -82,15 +98,23 @@ pub mod vec_map;
|
|||
|
||||
#[unstable(feature = "collections",
|
||||
reason = "RFC 509")]
|
||||
pub mod bitv {
|
||||
pub use bit::{Bitv, Iter};
|
||||
pub mod bit_vec {
|
||||
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",
|
||||
reason = "RFC 509")]
|
||||
pub mod bitv_set {
|
||||
pub use bit::{BitvSet, Union, Intersection, Difference, SymmetricDifference};
|
||||
pub mod bit_set {
|
||||
pub use bit::{BitSet, Union, Intersection, Difference, SymmetricDifference};
|
||||
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")]
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
|
||||
//! 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.
|
||||
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -34,9 +34,13 @@ use core::iter::{self, FromIterator, IntoIterator};
|
|||
use core::mem;
|
||||
use core::ptr;
|
||||
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to LinkedList")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub use LinkedList as DList;
|
||||
|
||||
/// A doubly-linked list.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct DList<T> {
|
||||
pub struct LinkedList<T> {
|
||||
length: usize,
|
||||
list_head: Link<T>,
|
||||
list_tail: Rawlink<Node<T>>,
|
||||
|
@ -58,7 +62,7 @@ struct Node<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")]
|
||||
pub struct Iter<'a, T:'a> {
|
||||
head: &'a Link<T>,
|
||||
|
@ -78,20 +82,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")]
|
||||
pub struct IterMut<'a, T:'a> {
|
||||
list: &'a mut DList<T>,
|
||||
list: &'a mut LinkedList<T>,
|
||||
head: Rawlink<Node<T>>,
|
||||
tail: Rawlink<Node<T>>,
|
||||
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)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct IntoIter<T> {
|
||||
list: DList<T>
|
||||
list: LinkedList<T>
|
||||
}
|
||||
|
||||
/// Rawlink is a type like Option<T> but for holding a raw pointer
|
||||
|
@ -149,7 +153,7 @@ fn link_with_prev<T>(mut next: Box<Node<T>>, prev: Rawlink<Node<T>>)
|
|||
}
|
||||
|
||||
// private methods
|
||||
impl<T> DList<T> {
|
||||
impl<T> LinkedList<T> {
|
||||
/// Add a Node first in the list
|
||||
#[inline]
|
||||
fn push_front_node(&mut self, mut new_head: Box<Node<T>>) {
|
||||
|
@ -209,18 +213,18 @@ impl<T> DList<T> {
|
|||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> Default for DList<T> {
|
||||
impl<T> Default for LinkedList<T> {
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn default() -> DList<T> { DList::new() }
|
||||
fn default() -> LinkedList<T> { LinkedList::new() }
|
||||
}
|
||||
|
||||
impl<T> DList<T> {
|
||||
/// Creates an empty `DList`.
|
||||
impl<T> LinkedList<T> {
|
||||
/// Creates an empty `LinkedList`.
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn new() -> DList<T> {
|
||||
DList{list_head: None, list_tail: Rawlink::none(), length: 0}
|
||||
pub fn new() -> LinkedList<T> {
|
||||
LinkedList{list_head: None, list_tail: Rawlink::none(), length: 0}
|
||||
}
|
||||
|
||||
/// Moves all elements from `other` to the end of the list.
|
||||
|
@ -233,10 +237,10 @@ impl<T> DList<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
/// use std::collections::LinkedList;
|
||||
///
|
||||
/// let mut a = DList::new();
|
||||
/// let mut b = DList::new();
|
||||
/// let mut a = LinkedList::new();
|
||||
/// let mut b = LinkedList::new();
|
||||
/// a.push_back(1);
|
||||
/// a.push_back(2);
|
||||
/// b.push_back(3);
|
||||
|
@ -249,7 +253,7 @@ impl<T> DList<T> {
|
|||
/// }
|
||||
/// 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() {
|
||||
None => {
|
||||
self.length = other.length;
|
||||
|
@ -303,16 +307,16 @@ impl<T> DList<T> {
|
|||
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.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
/// use std::collections::LinkedList;
|
||||
///
|
||||
/// let mut dl = DList::new();
|
||||
/// let mut dl = LinkedList::new();
|
||||
/// assert!(dl.is_empty());
|
||||
///
|
||||
/// dl.push_front("foo");
|
||||
|
@ -324,16 +328,16 @@ impl<T> DList<T> {
|
|||
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.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
/// use std::collections::LinkedList;
|
||||
///
|
||||
/// let mut dl = DList::new();
|
||||
/// let mut dl = LinkedList::new();
|
||||
///
|
||||
/// dl.push_front(2);
|
||||
/// assert_eq!(dl.len(), 1);
|
||||
|
@ -351,16 +355,16 @@ impl<T> DList<T> {
|
|||
self.length
|
||||
}
|
||||
|
||||
/// Removes all elements from the `DList`.
|
||||
/// Removes all elements from the `LinkedList`.
|
||||
///
|
||||
/// This operation should compute in O(n) time.
|
||||
///
|
||||
/// # 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(1);
|
||||
|
@ -375,7 +379,7 @@ impl<T> DList<T> {
|
|||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn clear(&mut self) {
|
||||
*self = DList::new()
|
||||
*self = LinkedList::new()
|
||||
}
|
||||
|
||||
/// Provides a reference to the front element, or `None` if the list is
|
||||
|
@ -384,9 +388,9 @@ impl<T> DList<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
/// use std::collections::LinkedList;
|
||||
///
|
||||
/// let mut dl = DList::new();
|
||||
/// let mut dl = LinkedList::new();
|
||||
/// assert_eq!(dl.front(), None);
|
||||
///
|
||||
/// dl.push_front(1);
|
||||
|
@ -405,9 +409,9 @@ impl<T> DList<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
/// use std::collections::LinkedList;
|
||||
///
|
||||
/// let mut dl = DList::new();
|
||||
/// let mut dl = LinkedList::new();
|
||||
/// assert_eq!(dl.front(), None);
|
||||
///
|
||||
/// dl.push_front(1);
|
||||
|
@ -432,9 +436,9 @@ impl<T> DList<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
/// use std::collections::LinkedList;
|
||||
///
|
||||
/// let mut dl = DList::new();
|
||||
/// let mut dl = LinkedList::new();
|
||||
/// assert_eq!(dl.back(), None);
|
||||
///
|
||||
/// dl.push_back(1);
|
||||
|
@ -453,9 +457,9 @@ impl<T> DList<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
/// use std::collections::LinkedList;
|
||||
///
|
||||
/// let mut dl = DList::new();
|
||||
/// let mut dl = LinkedList::new();
|
||||
/// assert_eq!(dl.back(), None);
|
||||
///
|
||||
/// dl.push_back(1);
|
||||
|
@ -481,9 +485,9 @@ impl<T> DList<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
/// use std::collections::LinkedList;
|
||||
///
|
||||
/// let mut dl = DList::new();
|
||||
/// let mut dl = LinkedList::new();
|
||||
///
|
||||
/// dl.push_front(2);
|
||||
/// assert_eq!(dl.front().unwrap(), &2);
|
||||
|
@ -505,9 +509,9 @@ impl<T> DList<T> {
|
|||
/// # 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);
|
||||
///
|
||||
/// d.push_front(1);
|
||||
|
@ -528,9 +532,9 @@ impl<T> DList<T> {
|
|||
/// # 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(3);
|
||||
/// assert_eq!(3, *d.back().unwrap());
|
||||
|
@ -546,9 +550,9 @@ impl<T> DList<T> {
|
|||
/// # 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);
|
||||
/// d.push_back(1);
|
||||
/// d.push_back(3);
|
||||
|
@ -571,9 +575,9 @@ impl<T> DList<T> {
|
|||
/// # 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(2);
|
||||
|
@ -585,13 +589,13 @@ impl<T> DList<T> {
|
|||
/// assert_eq!(splitted.pop_front(), None);
|
||||
/// ```
|
||||
#[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();
|
||||
assert!(at <= len, "Cannot split off at a nonexistent index");
|
||||
if at == 0 {
|
||||
return mem::replace(self, DList::new());
|
||||
return mem::replace(self, LinkedList::new());
|
||||
} 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,
|
||||
|
@ -614,7 +618,7 @@ impl<T> DList<T> {
|
|||
iter.tail
|
||||
};
|
||||
|
||||
let mut splitted_list = DList {
|
||||
let mut splitted_list = LinkedList {
|
||||
list_head: None,
|
||||
list_tail: self.list_tail,
|
||||
length: len - at
|
||||
|
@ -630,9 +634,9 @@ impl<T> DList<T> {
|
|||
|
||||
#[unsafe_destructor]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> Drop for DList<T> {
|
||||
impl<T> Drop for LinkedList<T> {
|
||||
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
|
||||
// when length is >> 1_000_000
|
||||
let mut tail = self.list_tail;
|
||||
|
@ -763,9 +767,9 @@ impl<'a, A> IterMut<'a, A> {
|
|||
/// # 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();
|
||||
|
@ -790,9 +794,9 @@ impl<'a, A> IterMut<'a, A> {
|
|||
/// # 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();
|
||||
/// assert_eq!(it.next().unwrap(), &1);
|
||||
|
@ -831,16 +835,16 @@ impl<A> DoubleEndedIterator for IntoIter<A> {
|
|||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A> FromIterator<A> for DList<A> {
|
||||
fn from_iter<T: Iterator<Item=A>>(iterator: T) -> DList<A> {
|
||||
impl<A> FromIterator<A> for LinkedList<A> {
|
||||
fn from_iter<T: IntoIterator<Item=A>>(iter: T) -> LinkedList<A> {
|
||||
let mut ret = DList::new();
|
||||
ret.extend(iterator);
|
||||
ret.extend(iter);
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> IntoIterator for DList<T> {
|
||||
impl<T> IntoIterator for LinkedList<T> {
|
||||
type Item = T;
|
||||
type IntoIter = IntoIter<T>;
|
||||
|
||||
|
@ -850,7 +854,7 @@ impl<T> IntoIterator for DList<T> {
|
|||
}
|
||||
|
||||
#[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 IntoIter = Iter<'a, T>;
|
||||
|
||||
|
@ -859,7 +863,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 IntoIter = IterMut<'a, T>;
|
||||
|
||||
|
@ -869,54 +873,54 @@ impl<'a, T> IntoIterator for &'a mut DList<T> {
|
|||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A> Extend<A> for DList<A> {
|
||||
fn extend<T: Iterator<Item=A>>(&mut self, iterator: T) {
|
||||
for elt in iterator { self.push_back(elt); }
|
||||
impl<A> Extend<A> for LinkedList<A> {
|
||||
fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T) {
|
||||
for elt in iter { self.push_back(elt); }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: PartialEq> PartialEq for DList<A> {
|
||||
fn eq(&self, other: &DList<A>) -> bool {
|
||||
impl<A: PartialEq> PartialEq for LinkedList<A> {
|
||||
fn eq(&self, other: &LinkedList<A>) -> bool {
|
||||
self.len() == other.len() &&
|
||||
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() ||
|
||||
iter::order::ne(self.iter(), other.iter())
|
||||
}
|
||||
}
|
||||
|
||||
#[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")]
|
||||
impl<A: PartialOrd> PartialOrd for DList<A> {
|
||||
fn partial_cmp(&self, other: &DList<A>) -> Option<Ordering> {
|
||||
impl<A: PartialOrd> PartialOrd for LinkedList<A> {
|
||||
fn partial_cmp(&self, other: &LinkedList<A>) -> Option<Ordering> {
|
||||
iter::order::partial_cmp(self.iter(), other.iter())
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: Ord> Ord for DList<A> {
|
||||
impl<A: Ord> Ord for LinkedList<A> {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &DList<A>) -> Ordering {
|
||||
fn cmp(&self, other: &LinkedList<A>) -> Ordering {
|
||||
iter::order::cmp(self.iter(), other.iter())
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: Clone> Clone for DList<A> {
|
||||
fn clone(&self) -> DList<A> {
|
||||
impl<A: Clone> Clone for LinkedList<A> {
|
||||
fn clone(&self) -> LinkedList<A> {
|
||||
self.iter().cloned().collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[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 {
|
||||
try!(write!(f, "DList ["));
|
||||
try!(write!(f, "LinkedList ["));
|
||||
|
||||
for (i, e) in self.iter().enumerate() {
|
||||
if i != 0 { try!(write!(f, ", ")); }
|
||||
|
@ -929,7 +933,7 @@ impl<A: fmt::Debug> fmt::Debug for DList<A> {
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg(stage0)]
|
||||
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) {
|
||||
self.len().hash(state);
|
||||
for elt in self {
|
||||
|
@ -939,7 +943,7 @@ impl<S: Writer + Hasher, A: Hash<S>> Hash<S> for DList<A> {
|
|||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg(not(stage0))]
|
||||
impl<A: Hash> Hash for DList<A> {
|
||||
impl<A: Hash> Hash for LinkedList<A> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.len().hash(state);
|
||||
for elt in self {
|
||||
|
@ -957,9 +961,9 @@ mod tests {
|
|||
use test::Bencher;
|
||||
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 last_ptr: Option<&Node<T>> = None;
|
||||
let mut node_ptr: &Node<T>;
|
||||
|
@ -993,7 +997,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
let mut m = DList::new();
|
||||
let mut m = LinkedList::new();
|
||||
assert_eq!(m.pop_front(), None);
|
||||
assert_eq!(m.pop_back(), None);
|
||||
assert_eq!(m.pop_front(), None);
|
||||
|
@ -1012,7 +1016,7 @@ mod tests {
|
|||
m.push_back(box 7);
|
||||
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(3);
|
||||
{
|
||||
|
@ -1032,7 +1036,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn generate_test() -> DList<i32> {
|
||||
fn generate_test() -> LinkedList<i32> {
|
||||
list_from(&[0,1,2,3,4,5,6])
|
||||
}
|
||||
|
||||
|
@ -1045,8 +1049,8 @@ mod tests {
|
|||
fn test_append() {
|
||||
// Empty to empty
|
||||
{
|
||||
let mut m = DList::<i32>::new();
|
||||
let mut n = DList::new();
|
||||
let mut m = LinkedList::<i32>::new();
|
||||
let mut n = LinkedList::new();
|
||||
m.append(&mut n);
|
||||
check_links(&m);
|
||||
assert_eq!(m.len(), 0);
|
||||
|
@ -1054,8 +1058,8 @@ mod tests {
|
|||
}
|
||||
// Non-empty to empty
|
||||
{
|
||||
let mut m = DList::new();
|
||||
let mut n = DList::new();
|
||||
let mut m = LinkedList::new();
|
||||
let mut n = LinkedList::new();
|
||||
n.push_back(2);
|
||||
m.append(&mut n);
|
||||
check_links(&m);
|
||||
|
@ -1066,8 +1070,8 @@ mod tests {
|
|||
}
|
||||
// Empty to non-empty
|
||||
{
|
||||
let mut m = DList::new();
|
||||
let mut n = DList::new();
|
||||
let mut m = LinkedList::new();
|
||||
let mut n = LinkedList::new();
|
||||
m.push_back(2);
|
||||
m.append(&mut n);
|
||||
check_links(&m);
|
||||
|
@ -1102,7 +1106,7 @@ mod tests {
|
|||
fn test_split_off() {
|
||||
// singleton
|
||||
{
|
||||
let mut m = DList::new();
|
||||
let mut m = LinkedList::new();
|
||||
m.push_back(1);
|
||||
|
||||
let p = m.split_off(0);
|
||||
|
@ -1143,7 +1147,7 @@ mod tests {
|
|||
|
||||
// no-op on the last index
|
||||
{
|
||||
let mut m = DList::new();
|
||||
let mut m = LinkedList::new();
|
||||
m.push_back(1);
|
||||
|
||||
let p = m.split_off(1);
|
||||
|
@ -1161,7 +1165,7 @@ mod tests {
|
|||
for (i, elt) in m.iter().enumerate() {
|
||||
assert_eq!(i as i32, *elt);
|
||||
}
|
||||
let mut n = DList::new();
|
||||
let mut n = LinkedList::new();
|
||||
assert_eq!(n.iter().next(), None);
|
||||
n.push_front(4);
|
||||
let mut it = n.iter();
|
||||
|
@ -1173,7 +1177,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_iterator_clone() {
|
||||
let mut n = DList::new();
|
||||
let mut n = LinkedList::new();
|
||||
n.push_back(2);
|
||||
n.push_back(3);
|
||||
n.push_back(4);
|
||||
|
@ -1187,7 +1191,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_iterator_double_end() {
|
||||
let mut n = DList::new();
|
||||
let mut n = LinkedList::new();
|
||||
assert_eq!(n.iter().next(), None);
|
||||
n.push_front(4);
|
||||
n.push_front(5);
|
||||
|
@ -1209,7 +1213,7 @@ mod tests {
|
|||
for (i, elt) in m.iter().rev().enumerate() {
|
||||
assert_eq!((6 - i) as i32, *elt);
|
||||
}
|
||||
let mut n = DList::new();
|
||||
let mut n = LinkedList::new();
|
||||
assert_eq!(n.iter().rev().next(), None);
|
||||
n.push_front(4);
|
||||
let mut it = n.iter().rev();
|
||||
|
@ -1228,7 +1232,7 @@ mod tests {
|
|||
len -= 1;
|
||||
}
|
||||
assert_eq!(len, 0);
|
||||
let mut n = DList::new();
|
||||
let mut n = LinkedList::new();
|
||||
assert!(n.iter_mut().next().is_none());
|
||||
n.push_front(4);
|
||||
n.push_back(5);
|
||||
|
@ -1242,7 +1246,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_iterator_mut_double_end() {
|
||||
let mut n = DList::new();
|
||||
let mut n = LinkedList::new();
|
||||
assert!(n.iter_mut().next_back().is_none());
|
||||
n.push_front(4);
|
||||
n.push_front(5);
|
||||
|
@ -1291,7 +1295,7 @@ mod tests {
|
|||
for (i, elt) in m.iter_mut().rev().enumerate() {
|
||||
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());
|
||||
n.push_front(4);
|
||||
let mut it = n.iter_mut().rev();
|
||||
|
@ -1326,8 +1330,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_hash() {
|
||||
let mut x = DList::new();
|
||||
let mut y = DList::new();
|
||||
let mut x = LinkedList::new();
|
||||
let mut y = LinkedList::new();
|
||||
|
||||
assert!(hash::hash::<_, SipHasher>(&x) == hash::hash::<_, SipHasher>(&y));
|
||||
|
||||
|
@ -1395,16 +1399,16 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
let list: DList<_> = (0..10).collect();
|
||||
assert_eq!(format!("{:?}", list), "DList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
|
||||
let list: LinkedList<_> = (0..10).collect();
|
||||
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();
|
||||
assert_eq!(format!("{:?}", list), "DList [\"just\", \"one\", \"test\", \"more\"]");
|
||||
let list: LinkedList<_> = vec!["just", "one", "test", "more"].iter().cloned().collect();
|
||||
assert_eq!(format!("{:?}", list), "LinkedList [\"just\", \"one\", \"test\", \"more\"]");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn fuzz_test(sz: i32) {
|
||||
let mut m: DList<_> = DList::new();
|
||||
let mut m: LinkedList<_> = LinkedList::new();
|
||||
let mut v = vec![];
|
||||
for i in 0..sz {
|
||||
check_links(&m);
|
||||
|
@ -1445,13 +1449,13 @@ mod tests {
|
|||
fn bench_collect_into(b: &mut test::Bencher) {
|
||||
let v = &[0; 64];
|
||||
b.iter(|| {
|
||||
let _: DList<_> = v.iter().cloned().collect();
|
||||
let _: LinkedList<_> = v.iter().cloned().collect();
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_push_front(b: &mut test::Bencher) {
|
||||
let mut m: DList<_> = DList::new();
|
||||
let mut m: LinkedList<_> = LinkedList::new();
|
||||
b.iter(|| {
|
||||
m.push_front(0);
|
||||
})
|
||||
|
@ -1459,7 +1463,7 @@ mod tests {
|
|||
|
||||
#[bench]
|
||||
fn bench_push_back(b: &mut test::Bencher) {
|
||||
let mut m: DList<_> = DList::new();
|
||||
let mut m: LinkedList<_> = LinkedList::new();
|
||||
b.iter(|| {
|
||||
m.push_back(0);
|
||||
})
|
||||
|
@ -1467,7 +1471,7 @@ mod tests {
|
|||
|
||||
#[bench]
|
||||
fn bench_push_back_pop_back(b: &mut test::Bencher) {
|
||||
let mut m: DList<_> = DList::new();
|
||||
let mut m: LinkedList<_> = LinkedList::new();
|
||||
b.iter(|| {
|
||||
m.push_back(0);
|
||||
m.pop_back();
|
||||
|
@ -1476,7 +1480,7 @@ mod tests {
|
|||
|
||||
#[bench]
|
||||
fn bench_push_front_pop_front(b: &mut test::Bencher) {
|
||||
let mut m: DList<_> = DList::new();
|
||||
let mut m: LinkedList<_> = LinkedList::new();
|
||||
b.iter(|| {
|
||||
m.push_front(0);
|
||||
m.pop_front();
|
||||
|
@ -1486,7 +1490,7 @@ mod tests {
|
|||
#[bench]
|
||||
fn bench_iter(b: &mut test::Bencher) {
|
||||
let v = &[0; 128];
|
||||
let m: DList<_> = v.iter().cloned().collect();
|
||||
let m: LinkedList<_> = v.iter().cloned().collect();
|
||||
b.iter(|| {
|
||||
assert!(m.iter().count() == 128);
|
||||
})
|
||||
|
@ -1494,7 +1498,7 @@ mod tests {
|
|||
#[bench]
|
||||
fn bench_iter_mut(b: &mut test::Bencher) {
|
||||
let v = &[0; 128];
|
||||
let mut m: DList<_> = v.iter().cloned().collect();
|
||||
let mut m: LinkedList<_> = v.iter().cloned().collect();
|
||||
b.iter(|| {
|
||||
assert!(m.iter_mut().count() == 128);
|
||||
})
|
||||
|
@ -1502,7 +1506,7 @@ mod tests {
|
|||
#[bench]
|
||||
fn bench_iter_rev(b: &mut test::Bencher) {
|
||||
let v = &[0; 128];
|
||||
let m: DList<_> = v.iter().cloned().collect();
|
||||
let m: LinkedList<_> = v.iter().cloned().collect();
|
||||
b.iter(|| {
|
||||
assert!(m.iter().rev().count() == 128);
|
||||
})
|
||||
|
@ -1510,7 +1514,7 @@ mod tests {
|
|||
#[bench]
|
||||
fn bench_iter_mut_rev(b: &mut test::Bencher) {
|
||||
let v = &[0; 128];
|
||||
let mut m: DList<_> = v.iter().cloned().collect();
|
||||
let mut m: LinkedList<_> = v.iter().cloned().collect();
|
||||
b.iter(|| {
|
||||
assert!(m.iter_mut().rev().count() == 128);
|
||||
})
|
|
@ -68,7 +68,7 @@ use core::slice::AsSlice;
|
|||
use core::str as core_str;
|
||||
use unicode::str::{UnicodeStr, Utf16Encoder};
|
||||
|
||||
use ring_buf::RingBuf;
|
||||
use vec_deque::VecDeque;
|
||||
use slice::SliceExt;
|
||||
use string::String;
|
||||
use unicode;
|
||||
|
@ -261,7 +261,7 @@ enum RecompositionState {
|
|||
pub struct Recompositions<'a> {
|
||||
iter: Decompositions<'a>,
|
||||
state: RecompositionState,
|
||||
buffer: RingBuf<char>,
|
||||
buffer: VecDeque<char>,
|
||||
composee: Option<char>,
|
||||
last_ccc: Option<u8>
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
|
|||
Recompositions {
|
||||
iter: self.nfd_chars(),
|
||||
state: Composing,
|
||||
buffer: RingBuf::new(),
|
||||
buffer: VecDeque::new(),
|
||||
composee: None,
|
||||
last_ccc: None
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
|
|||
Recompositions {
|
||||
iter: self.nfkd_chars(),
|
||||
state: Composing,
|
||||
buffer: RingBuf::new(),
|
||||
buffer: VecDeque::new(),
|
||||
composee: None,
|
||||
last_ccc: None
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use core::default::Default;
|
|||
use core::error::Error;
|
||||
use core::fmt;
|
||||
use core::hash;
|
||||
use core::iter::FromIterator;
|
||||
use core::iter::{IntoIterator, FromIterator};
|
||||
use core::mem;
|
||||
use core::ops::{self, Deref, Add, Index};
|
||||
use core::ptr;
|
||||
|
@ -709,18 +709,18 @@ impl Error for FromUtf16Error {
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl FromIterator<char> for String {
|
||||
fn from_iter<I:Iterator<Item=char>>(iterator: I) -> String {
|
||||
fn from_iter<I: IntoIterator<Item=char>>(iter: I) -> String {
|
||||
let mut buf = String::new();
|
||||
buf.extend(iterator);
|
||||
buf.extend(iter);
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a> FromIterator<&'a str> for String {
|
||||
fn from_iter<I:Iterator<Item=&'a str>>(iterator: I) -> String {
|
||||
fn from_iter<I: IntoIterator<Item=&'a str>>(iter: I) -> String {
|
||||
let mut buf = String::new();
|
||||
buf.extend(iterator);
|
||||
buf.extend(iter);
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
@ -728,7 +728,8 @@ impl<'a> FromIterator<&'a str> for String {
|
|||
#[unstable(feature = "collections",
|
||||
reason = "waiting on Extend stabilization")]
|
||||
impl Extend<char> for String {
|
||||
fn extend<I:Iterator<Item=char>>(&mut self, iterator: I) {
|
||||
fn extend<I: IntoIterator<Item=char>>(&mut self, iterable: I) {
|
||||
let iterator = iterable.into_iter();
|
||||
let (lower_bound, _) = iterator.size_hint();
|
||||
self.reserve(lower_bound);
|
||||
for ch in iterator {
|
||||
|
@ -740,7 +741,8 @@ impl Extend<char> for String {
|
|||
#[unstable(feature = "collections",
|
||||
reason = "waiting on Extend stabilization")]
|
||||
impl<'a> Extend<&'a str> for String {
|
||||
fn extend<I: Iterator<Item=&'a str>>(&mut self, iterator: I) {
|
||||
fn extend<I: IntoIterator<Item=&'a str>>(&mut self, iterable: I) {
|
||||
let iterator = iterable.into_iter();
|
||||
// A guess that at least one byte per iterator element will be needed.
|
||||
let (lower_bound, _) = iterator.size_hint();
|
||||
self.reserve(lower_bound);
|
||||
|
|
|
@ -1417,7 +1417,8 @@ impl<T> ops::DerefMut for Vec<T> {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> FromIterator<T> for Vec<T> {
|
||||
#[inline]
|
||||
fn from_iter<I:Iterator<Item=T>>(mut iterator: I) -> Vec<T> {
|
||||
fn from_iter<I: IntoIterator<Item=T>>(iterable: I) -> Vec<T> {
|
||||
let mut iterator = iterable.into_iter();
|
||||
let (lower, _) = iterator.size_hint();
|
||||
let mut vector = Vec::with_capacity(lower);
|
||||
|
||||
|
@ -1490,7 +1491,8 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
|
|||
#[unstable(feature = "collections", reason = "waiting on Extend stability")]
|
||||
impl<T> Extend<T> for Vec<T> {
|
||||
#[inline]
|
||||
fn extend<I: Iterator<Item=T>>(&mut self, iterator: I) {
|
||||
fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
|
||||
let iterator = iterable.into_iter();
|
||||
let (lower, _) = iterator.size_hint();
|
||||
self.reserve(lower);
|
||||
for element in iterator {
|
||||
|
@ -1664,7 +1666,7 @@ pub type CowVec<'a, T> = Cow<'a, Vec<T>, [T]>;
|
|||
|
||||
#[unstable(feature = "collections")]
|
||||
impl<'a, T> FromIterator<T> for CowVec<'a, T> where T: Clone {
|
||||
fn from_iter<I: Iterator<Item=T>>(it: I) -> CowVec<'a, T> {
|
||||
fn from_iter<I: IntoIterator<Item=T>>(it: I) -> CowVec<'a, T> {
|
||||
Cow::Owned(FromIterator::from_iter(it))
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -678,7 +678,7 @@ impl<V: fmt::Debug> fmt::Debug for VecMap<V> {
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<V> FromIterator<(usize, V)> for VecMap<V> {
|
||||
fn from_iter<Iter: Iterator<Item=(usize, V)>>(iter: Iter) -> VecMap<V> {
|
||||
fn from_iter<I: IntoIterator<Item=(usize, V)>>(iter: I) -> VecMap<V> {
|
||||
let mut map = VecMap::new();
|
||||
map.extend(iter);
|
||||
map
|
||||
|
@ -717,7 +717,7 @@ impl<'a, T> IntoIterator for &'a mut VecMap<T> {
|
|||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<V> Extend<(usize, V)> for VecMap<V> {
|
||||
fn extend<Iter: Iterator<Item=(usize, V)>>(&mut self, iter: Iter) {
|
||||
fn extend<I: IntoIterator<Item=(usize, V)>>(&mut self, iter: I) {
|
||||
for (k, v) in iter {
|
||||
self.insert(k, v);
|
||||
}
|
||||
|
|
|
@ -113,9 +113,9 @@ impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I {
|
|||
#[rustc_on_unimplemented="a collection of type `{Self}` cannot be \
|
||||
built from an iterator over elements of type `{A}`"]
|
||||
pub trait FromIterator<A> {
|
||||
/// Build a container with elements from an external iterator.
|
||||
/// Build a container with elements from something iterable.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn from_iter<T: Iterator<Item=A>>(iterator: T) -> Self;
|
||||
fn from_iter<T: IntoIterator<Item=A>>(iterator: T) -> Self;
|
||||
}
|
||||
|
||||
/// Conversion into an `Iterator`
|
||||
|
@ -147,7 +147,7 @@ impl<I: Iterator> IntoIterator for I {
|
|||
pub trait Extend<A> {
|
||||
/// Extend a container with the elements yielded by an arbitrary iterator
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn extend<T: Iterator<Item=A>>(&mut self, iterator: T);
|
||||
fn extend<T: IntoIterator<Item=A>>(&mut self, iterable: T);
|
||||
}
|
||||
|
||||
/// An extension trait providing numerous methods applicable to all iterators.
|
||||
|
|
|
@ -149,7 +149,7 @@ use clone::Clone;
|
|||
use cmp::{Eq, Ord};
|
||||
use default::Default;
|
||||
use iter::{ExactSizeIterator};
|
||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator};
|
||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, IntoIterator};
|
||||
use mem;
|
||||
use ops::{Deref, FnOnce};
|
||||
use result::Result::{Ok, Err};
|
||||
|
@ -909,7 +909,7 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
|
|||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn from_iter<I: Iterator<Item=Option<A>>>(iter: I) -> Option<V> {
|
||||
fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {
|
||||
// FIXME(#11084): This could be replaced with Iterator::scan when this
|
||||
// performance bug is closed.
|
||||
|
||||
|
@ -934,7 +934,7 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
|
|||
}
|
||||
}
|
||||
|
||||
let mut adapter = Adapter { iter: iter, found_none: false };
|
||||
let mut adapter = Adapter { iter: iter.into_iter(), found_none: false };
|
||||
let v: V = FromIterator::from_iter(adapter.by_ref());
|
||||
|
||||
if adapter.found_none {
|
||||
|
|
|
@ -230,7 +230,8 @@ use self::Result::{Ok, Err};
|
|||
|
||||
use clone::Clone;
|
||||
use fmt;
|
||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
|
||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator,
|
||||
FromIterator, ExactSizeIterator, IntoIterator};
|
||||
use ops::{FnMut, FnOnce};
|
||||
use option::Option::{self, None, Some};
|
||||
use slice::AsSlice;
|
||||
|
@ -906,7 +907,7 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
|
|||
/// assert!(res == Ok(vec!(2, 3)));
|
||||
/// ```
|
||||
#[inline]
|
||||
fn from_iter<I: Iterator<Item=Result<A, E>>>(iter: I) -> Result<V, E> {
|
||||
fn from_iter<I: IntoIterator<Item=Result<A, E>>>(iter: I) -> Result<V, E> {
|
||||
// FIXME(#11084): This could be replaced with Iterator::scan when this
|
||||
// performance bug is closed.
|
||||
|
||||
|
@ -931,7 +932,7 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
|
|||
}
|
||||
}
|
||||
|
||||
let mut adapter = Adapter { iter: iter, err: None };
|
||||
let mut adapter = Adapter { iter: iter.into_iter(), err: None };
|
||||
let v: V = FromIterator::from_iter(adapter.by_ref());
|
||||
|
||||
match adapter.err {
|
||||
|
|
|
@ -37,7 +37,7 @@ use util::ppaux::{ty_to_string};
|
|||
use util::nodemap::{FnvHashMap, NodeSet};
|
||||
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::num::SignedInt;
|
||||
use std::{cmp, slice};
|
||||
|
@ -1792,7 +1792,7 @@ impl LintPass for UnconditionalRecursion {
|
|||
let mut work_queue = vec![cfg.entry];
|
||||
let mut reached_exit_without_self_call = false;
|
||||
let mut self_call_spans = vec![];
|
||||
let mut visited = BitvSet::new();
|
||||
let mut visited = BitSet::new();
|
||||
|
||||
while let Some(idx) = work_queue.pop() {
|
||||
let cfg_id = idx.node_id();
|
||||
|
|
|
@ -25,7 +25,7 @@ use middle::ty::*;
|
|||
use middle::ty;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::iter::{range_inclusive, AdditiveIterator, FromIterator, repeat};
|
||||
use std::iter::{range_inclusive, AdditiveIterator, FromIterator, IntoIterator, repeat};
|
||||
use std::num::Float;
|
||||
use std::slice;
|
||||
use syntax::ast::{self, DUMMY_NODE_ID, NodeId, Pat};
|
||||
|
@ -94,8 +94,8 @@ impl<'a> fmt::Debug for Matrix<'a> {
|
|||
}
|
||||
|
||||
impl<'a> FromIterator<Vec<&'a Pat>> for Matrix<'a> {
|
||||
fn from_iter<T: Iterator<Item=Vec<&'a Pat>>>(iterator: T) -> Matrix<'a> {
|
||||
Matrix(iterator.collect())
|
||||
fn from_iter<T: IntoIterator<Item=Vec<&'a Pat>>>(iter: T) -> Matrix<'a> {
|
||||
Matrix(iter.into_iter().collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
use std::fmt::{Formatter, Error, Debug};
|
||||
use std::usize;
|
||||
use std::collections::BitvSet;
|
||||
use std::collections::BitSet;
|
||||
|
||||
pub struct Graph<N,E> {
|
||||
nodes: Vec<Node<N>> ,
|
||||
|
@ -292,7 +292,7 @@ impl<N,E> Graph<N,E> {
|
|||
DepthFirstTraversal {
|
||||
graph: self,
|
||||
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> {
|
||||
graph: &'g Graph<N, E>,
|
||||
stack: Vec<NodeIndex>,
|
||||
visited: BitvSet
|
||||
visited: BitSet
|
||||
}
|
||||
|
||||
impl<'g, N, E> Iterator for DepthFirstTraversal<'g, N, E> {
|
||||
|
|
|
@ -17,12 +17,12 @@ use std::hash::Hash;
|
|||
use std::collections::hash_state::HashState;
|
||||
|
||||
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};
|
||||
|
||||
impl<
|
||||
T: Encodable
|
||||
> Encodable for DList<T> {
|
||||
> Encodable for LinkedList<T> {
|
||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
for (i, e) in self.iter().enumerate() {
|
||||
|
@ -33,10 +33,10 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Decodable> Decodable for DList<T> {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<DList<T>, D::Error> {
|
||||
impl<T:Decodable> Decodable for LinkedList<T> {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<LinkedList<T>, D::Error> {
|
||||
d.read_seq(|d, len| {
|
||||
let mut list = DList::new();
|
||||
let mut list = LinkedList::new();
|
||||
for i in 0..len {
|
||||
list.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
|
||||
}
|
||||
|
@ -45,7 +45,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> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
for (i, e) in self.iter().enumerate() {
|
||||
|
@ -56,10 +56,10 @@ impl<T: Encodable> Encodable for RingBuf<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Decodable> Decodable for RingBuf<T> {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<RingBuf<T>, D::Error> {
|
||||
impl<T:Decodable> Decodable for VecDeque<T> {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> {
|
||||
d.read_seq(|d, len| {
|
||||
let mut deque: RingBuf<T> = RingBuf::new();
|
||||
let mut deque: VecDeque<T> = VecDeque::new();
|
||||
for i in 0..len {
|
||||
deque.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
|
||||
}
|
||||
|
|
|
@ -1534,7 +1534,8 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
|
|||
impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
|
||||
where K: Eq + Hash, S: HashState + Default
|
||||
{
|
||||
fn from_iter<T: Iterator<Item=(K, V)>>(iter: T) -> HashMap<K, V, S> {
|
||||
fn from_iter<T: IntoIterator<Item=(K, V)>>(iterable: T) -> HashMap<K, V, S> {
|
||||
let iter = iterable.into_iter();
|
||||
let lower = iter.size_hint().0;
|
||||
let mut map = HashMap::with_capacity_and_hash_state(lower,
|
||||
Default::default());
|
||||
|
@ -1547,7 +1548,7 @@ impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
|
|||
impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
|
||||
where K: Eq + Hash, S: HashState
|
||||
{
|
||||
fn extend<T: Iterator<Item=(K, V)>>(&mut self, iter: T) {
|
||||
fn extend<T: IntoIterator<Item=(K, V)>>(&mut self, iter: T) {
|
||||
for (k, v) in iter {
|
||||
self.insert(k, v);
|
||||
}
|
||||
|
|
|
@ -614,7 +614,8 @@ impl<T, S> FromIterator<T> for HashSet<T, S>
|
|||
where T: Eq + Hash,
|
||||
S: HashState + Default,
|
||||
{
|
||||
fn from_iter<I: Iterator<Item=T>>(iter: I) -> HashSet<T, S> {
|
||||
fn from_iter<I: IntoIterator<Item=T>>(iterable: I) -> HashSet<T, S> {
|
||||
let iter = iterable.into_iter();
|
||||
let lower = iter.size_hint().0;
|
||||
let mut set = HashSet::with_capacity_and_hash_state(lower, Default::default());
|
||||
set.extend(iter);
|
||||
|
@ -627,7 +628,7 @@ impl<T, S> Extend<T> for HashSet<T, S>
|
|||
where T: Eq + Hash,
|
||||
S: HashState,
|
||||
{
|
||||
fn extend<I: Iterator<Item=T>>(&mut self, iter: I) {
|
||||
fn extend<I: IntoIterator<Item=T>>(&mut self, iter: I) {
|
||||
for k in iter {
|
||||
self.insert(k);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
//!
|
||||
//! Rust's collections can be grouped into four major categories:
|
||||
//!
|
||||
//! * Sequences: `Vec`, `RingBuf`, `DList`, `BitV`
|
||||
//! * Sequences: `Vec`, `VecDeque`, `LinkedList`, `BitV`
|
||||
//! * Maps: `HashMap`, `BTreeMap`, `VecMap`
|
||||
//! * Sets: `HashSet`, `BTreeSet`, `BitVSet`
|
||||
//! * Misc: `BinaryHeap`
|
||||
|
@ -43,13 +43,13 @@
|
|||
//! * You want a resizable 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 queue.
|
||||
//! * You want a double-ended queue (deque).
|
||||
//!
|
||||
//! ### Use a `DList` when:
|
||||
//! * You want a `Vec` or `RingBuf` of unknown size, and can't tolerate amortization.
|
||||
//! ### Use a `LinkedList` when:
|
||||
//! * You want a `Vec` or `VecDeque` of unknown size, and can't tolerate amortization.
|
||||
//! * You want to efficiently split and append lists.
|
||||
//! * You are *absolutely* certain you *really*, *truly*, want a doubly linked list.
|
||||
//!
|
||||
|
@ -75,7 +75,7 @@
|
|||
//!
|
||||
//! ### Use a `BitV` when:
|
||||
//! * 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:
|
||||
//! * You want a `VecSet`.
|
||||
|
@ -106,20 +106,20 @@
|
|||
//!
|
||||
//! ## Sequences
|
||||
//!
|
||||
//! | | get(i) | insert(i) | remove(i) | append | split_off(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)) |
|
||||
//! | DList | 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) |
|
||||
//! | | get(i) | insert(i) | remove(i) | append | split_off(i) |
|
||||
//! |--------------|----------------|-----------------|----------------|--------|----------------|
|
||||
//! | Vec | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
|
||||
//! | VecDeque | O(1) | O(min(i, n-i))* | O(min(i, n-i)) | O(m)* | 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)) |
|
||||
//! | 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
|
||||
//! is generally going to be faster than DList. Bitv is not a general purpose collection, and
|
||||
//! Note that where ties occur, Vec is generally going to be faster than VecDeque, and VecDeque
|
||||
//! is generally going to be faster than LinkedList. BitVec is not a general purpose collection, and
|
||||
//! therefore cannot reasonably be compared.
|
||||
//!
|
||||
//! ## 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.
|
||||
//!
|
||||
//! | | get | insert | remove | predecessor |
|
||||
|
@ -166,7 +166,7 @@
|
|||
//!
|
||||
//! 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
|
||||
//! 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`
|
||||
//! when you know exactly how many elements will be inserted, or at least have a
|
||||
//! 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 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
|
||||
|
@ -362,11 +362,11 @@
|
|||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
pub use core_collections::Bound;
|
||||
pub use core_collections::{BinaryHeap, Bitv, BitvSet, BTreeMap, BTreeSet};
|
||||
pub use core_collections::{DList, RingBuf, VecMap};
|
||||
pub use core_collections::{BinaryHeap, BitVec, BitSet, BTreeMap, BTreeSet};
|
||||
pub use core_collections::{LinkedList, VecDeque, VecMap};
|
||||
|
||||
pub use core_collections::{binary_heap, bitv, bitv_set, btree_map, btree_set};
|
||||
pub use core_collections::{dlist, ring_buf, vec_map};
|
||||
pub use core_collections::{binary_heap, bit_vec, bit_set, btree_map, btree_set};
|
||||
pub use core_collections::{linked_list, vec_deque, vec_map};
|
||||
|
||||
pub use self::hash_map::HashMap;
|
||||
pub use self::hash_set::HashSet;
|
||||
|
|
|
@ -110,7 +110,7 @@ use core::prelude::*;
|
|||
use ascii::*;
|
||||
use borrow::BorrowFrom;
|
||||
use cmp;
|
||||
use iter;
|
||||
use iter::{self, IntoIterator};
|
||||
use mem;
|
||||
use ops::{self, Deref};
|
||||
use string::CowString;
|
||||
|
@ -953,7 +953,7 @@ impl PathBuf {
|
|||
}
|
||||
|
||||
impl<'a, P: ?Sized + 'a> iter::FromIterator<&'a P> for PathBuf where P: AsPath {
|
||||
fn from_iter<I: Iterator<Item = &'a P>>(iter: I) -> PathBuf {
|
||||
fn from_iter<I: IntoIterator<Item = &'a P>>(iter: I) -> PathBuf {
|
||||
let mut buf = PathBuf::new("");
|
||||
buf.extend(iter);
|
||||
buf
|
||||
|
@ -961,7 +961,7 @@ impl<'a, P: ?Sized + 'a> iter::FromIterator<&'a P> for PathBuf where P: AsPath {
|
|||
}
|
||||
|
||||
impl<'a, P: ?Sized + 'a> iter::Extend<&'a P> for PathBuf where P: AsPath {
|
||||
fn extend<I: Iterator<Item = &'a P>>(&mut self, iter: I) {
|
||||
fn extend<I: IntoIterator<Item = &'a P>>(&mut self, iter: I) {
|
||||
for p in iter {
|
||||
self.push(p)
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ use cmp;
|
|||
use fmt;
|
||||
use hash::{Hash, Hasher};
|
||||
#[cfg(stage0)] use hash::Writer;
|
||||
use iter::FromIterator;
|
||||
use iter::{FromIterator, IntoIterator};
|
||||
use mem;
|
||||
use num::Int;
|
||||
use ops;
|
||||
|
@ -357,9 +357,9 @@ impl Wtf8Buf {
|
|||
/// This replaces surrogate code point pairs with supplementary code points,
|
||||
/// like concatenating ill-formed UTF-16 strings effectively would.
|
||||
impl FromIterator<CodePoint> for Wtf8Buf {
|
||||
fn from_iter<T: Iterator<Item=CodePoint>>(iterator: T) -> Wtf8Buf {
|
||||
fn from_iter<T: IntoIterator<Item=CodePoint>>(iter: T) -> Wtf8Buf {
|
||||
let mut string = Wtf8Buf::new();
|
||||
string.extend(iterator);
|
||||
string.extend(iter);
|
||||
string
|
||||
}
|
||||
}
|
||||
|
@ -369,7 +369,8 @@ impl FromIterator<CodePoint> for Wtf8Buf {
|
|||
/// This replaces surrogate code point pairs with supplementary code points,
|
||||
/// like concatenating ill-formed UTF-16 strings effectively would.
|
||||
impl Extend<CodePoint> for Wtf8Buf {
|
||||
fn extend<T: Iterator<Item=CodePoint>>(&mut self, iterator: T) {
|
||||
fn extend<T: IntoIterator<Item=CodePoint>>(&mut self, iterable: T) {
|
||||
let iterator = iterable.into_iter();
|
||||
let (low, _high) = iterator.size_hint();
|
||||
// Lower bound of one byte per code point (ASCII only)
|
||||
self.bytes.reserve(low);
|
||||
|
|
|
@ -26,11 +26,11 @@ use parse::token;
|
|||
use ptr::P;
|
||||
|
||||
use std::cell::{RefCell, Cell};
|
||||
use std::collections::BitvSet;
|
||||
use std::collections::BitSet;
|
||||
use std::collections::HashSet;
|
||||
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) {
|
||||
let AttrId(id) = attr.node.id;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use std::default::Default;
|
||||
use std::fmt;
|
||||
use std::iter::FromIterator;
|
||||
use std::iter::{IntoIterator, FromIterator};
|
||||
use std::ops::Deref;
|
||||
use std::vec;
|
||||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||
|
@ -77,8 +77,8 @@ impl<T: Clone> Clone for OwnedSlice<T> {
|
|||
}
|
||||
|
||||
impl<T> FromIterator<T> for OwnedSlice<T> {
|
||||
fn from_iter<I: Iterator<Item=T>>(iter: I) -> OwnedSlice<T> {
|
||||
OwnedSlice::from_vec(iter.collect())
|
||||
fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> OwnedSlice<T> {
|
||||
OwnedSlice::from_vec(iter.into_iter().collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
use self::SmallVectorRepr::*;
|
||||
use self::IntoIterRepr::*;
|
||||
|
||||
use std::iter::FromIterator;
|
||||
use std::iter::{IntoIterator, FromIterator};
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
use std::vec;
|
||||
|
@ -30,7 +30,7 @@ enum SmallVectorRepr<T> {
|
|||
}
|
||||
|
||||
impl<T> FromIterator<T> for SmallVector<T> {
|
||||
fn from_iter<I: Iterator<Item=T>>(iter: I) -> SmallVector<T> {
|
||||
fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> SmallVector<T> {
|
||||
let mut v = SmallVector::zero();
|
||||
v.extend(iter);
|
||||
v
|
||||
|
@ -38,7 +38,7 @@ impl<T> FromIterator<T> for SmallVector<T> {
|
|||
}
|
||||
|
||||
impl<T> Extend<T> for SmallVector<T> {
|
||||
fn extend<I: Iterator<Item=T>>(&mut self, iter: I) {
|
||||
fn extend<I: IntoIterator<Item=T>>(&mut self, iter: I) {
|
||||
for val in iter {
|
||||
self.push(val);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ extern crate collections;
|
|||
extern crate rand;
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::BitvSet;
|
||||
use std::collections::BitSet;
|
||||
use std::collections::HashSet;
|
||||
use std::hash::Hash;
|
||||
use std::env;
|
||||
|
@ -52,7 +52,7 @@ impl<T: Ord> MutableSet<T> for BTreeSet<T> {
|
|||
fn remove(&mut self, k: &T) -> bool { self.remove(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 remove(&mut self, k: &usize) -> bool { self.remove(k) }
|
||||
fn contains(&self, k: &usize) -> bool { self.contains(k) }
|
||||
|
@ -221,7 +221,7 @@ fn main() {
|
|||
{
|
||||
let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(seed);
|
||||
let mut results = empty_results();
|
||||
results.bench_int(&mut rng, num_keys, max, || BitvSet::new());
|
||||
write_results("collections::bitv::BitvSet", &results);
|
||||
results.bench_int(&mut rng, num_keys, max, || BitSet::new());
|
||||
write_results("collections::bit_vec::BitSet", &results);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue