Refactored vec and str iterators to remove prefixes
This commit is contained in:
parent
293ec2c582
commit
a0f0f3012e
@ -18,7 +18,8 @@
|
||||
use std::iterator::{Iterator, IteratorUtil, EnumerateIterator, FilterMapIterator, InvertIterator};
|
||||
use std::uint;
|
||||
use std::util::replace;
|
||||
use std::vec::{VecIterator, VecMutIterator, VecConsumeIterator};
|
||||
use std::vec::{VecIterator, VecMutIterator};
|
||||
use std::vec;
|
||||
|
||||
#[allow(missing_doc)]
|
||||
pub struct SmallIntMap<T> {
|
||||
@ -204,7 +205,7 @@ impl<V> SmallIntMap<V> {
|
||||
/// Empties the hash map, moving all values into the specified closure
|
||||
pub fn consume(&mut self)
|
||||
-> FilterMapIterator<(uint, Option<V>), (uint, V),
|
||||
EnumerateIterator<VecConsumeIterator<Option<V>>>>
|
||||
EnumerateIterator<vec::ConsumeIterator<Option<V>>>>
|
||||
{
|
||||
let values = replace(&mut self.v, ~[]);
|
||||
values.consume_iter().enumerate().filter_map(|(i, v)| {
|
||||
|
@ -538,7 +538,7 @@ pub struct HashMapMutIterator<'self, K, V> {
|
||||
|
||||
/// HashMap consume iterator
|
||||
pub struct HashMapConsumeIterator<K, V> {
|
||||
priv iter: vec::VecConsumeRevIterator<Option<Bucket<K, V>>>,
|
||||
priv iter: vec::ConsumeRevIterator<Option<Bucket<K, V>>>,
|
||||
}
|
||||
|
||||
/// HashSet iterator
|
||||
@ -549,7 +549,7 @@ pub struct HashSetIterator<'self, K> {
|
||||
|
||||
/// HashSet consume iterator
|
||||
pub struct HashSetConsumeIterator<K> {
|
||||
priv iter: vec::VecConsumeRevIterator<Option<Bucket<K, ()>>>,
|
||||
priv iter: vec::ConsumeRevIterator<Option<Bucket<K, ()>>>,
|
||||
}
|
||||
|
||||
impl<'self, K, V> Iterator<(&'self K, &'self V)> for HashMapIterator<'self, K, V> {
|
||||
|
@ -281,7 +281,7 @@ impl<'self, C: CharEq> CharEq for &'self [C] {
|
||||
|
||||
/// An iterator over the substrings of a string, separated by `sep`.
|
||||
#[deriving(Clone)]
|
||||
pub struct StrCharSplitIterator<'self,Sep> {
|
||||
pub struct CharSplitIterator<'self,Sep> {
|
||||
priv string: &'self str,
|
||||
priv position: uint,
|
||||
priv sep: Sep,
|
||||
@ -296,13 +296,13 @@ pub struct StrCharSplitIterator<'self,Sep> {
|
||||
/// An iterator over the words of a string, separated by an sequence of whitespace
|
||||
pub type WordIterator<'self> =
|
||||
FilterIterator<'self, &'self str,
|
||||
StrCharSplitIterator<'self, extern "Rust" fn(char) -> bool>>;
|
||||
CharSplitIterator<'self, extern "Rust" fn(char) -> bool>>;
|
||||
|
||||
/// An iterator over the lines of a string, separated by either `\n` or (`\r\n`).
|
||||
pub type AnyLineIterator<'self> =
|
||||
MapIterator<'self, &'self str, &'self str, StrCharSplitIterator<'self, char>>;
|
||||
MapIterator<'self, &'self str, &'self str, CharSplitIterator<'self, char>>;
|
||||
|
||||
impl<'self, Sep: CharEq> Iterator<&'self str> for StrCharSplitIterator<'self, Sep> {
|
||||
impl<'self, Sep: CharEq> Iterator<&'self str> for CharSplitIterator<'self, Sep> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'self str> {
|
||||
if self.finished { return None }
|
||||
@ -349,7 +349,7 @@ impl<'self, Sep: CharEq> Iterator<&'self str> for StrCharSplitIterator<'self, Se
|
||||
/// An iterator over the start and end indicies of the matches of a
|
||||
/// substring within a larger string
|
||||
#[deriving(Clone)]
|
||||
pub struct StrMatchesIndexIterator<'self> {
|
||||
pub struct MatchesIndexIterator<'self> {
|
||||
priv haystack: &'self str,
|
||||
priv needle: &'self str,
|
||||
priv position: uint,
|
||||
@ -358,13 +358,13 @@ pub struct StrMatchesIndexIterator<'self> {
|
||||
/// An iterator over the substrings of a string separated by a given
|
||||
/// search string
|
||||
#[deriving(Clone)]
|
||||
pub struct StrStrSplitIterator<'self> {
|
||||
priv it: StrMatchesIndexIterator<'self>,
|
||||
pub struct StrSplitIterator<'self> {
|
||||
priv it: MatchesIndexIterator<'self>,
|
||||
priv last_end: uint,
|
||||
priv finished: bool
|
||||
}
|
||||
|
||||
impl<'self> Iterator<(uint, uint)> for StrMatchesIndexIterator<'self> {
|
||||
impl<'self> Iterator<(uint, uint)> for MatchesIndexIterator<'self> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<(uint, uint)> {
|
||||
// See Issue #1932 for why this is a naive search
|
||||
@ -395,7 +395,7 @@ impl<'self> Iterator<(uint, uint)> for StrMatchesIndexIterator<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'self> Iterator<&'self str> for StrStrSplitIterator<'self> {
|
||||
impl<'self> Iterator<&'self str> for StrSplitIterator<'self> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'self str> {
|
||||
if self.finished { return None; }
|
||||
@ -1126,17 +1126,17 @@ impl Mutable for ~str {
|
||||
pub trait StrSlice<'self> {
|
||||
fn contains<'a>(&self, needle: &'a str) -> bool;
|
||||
fn contains_char(&self, needle: char) -> bool;
|
||||
fn iter(&self) -> StrCharIterator<'self>;
|
||||
fn rev_iter(&self) -> StrCharRevIterator<'self>;
|
||||
fn bytes_iter(&self) -> StrBytesIterator<'self>;
|
||||
fn bytes_rev_iter(&self) -> StrBytesRevIterator<'self>;
|
||||
fn split_iter<Sep: CharEq>(&self, sep: Sep) -> StrCharSplitIterator<'self, Sep>;
|
||||
fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> StrCharSplitIterator<'self, Sep>;
|
||||
fn iter(&self) -> CharIterator<'self>;
|
||||
fn rev_iter(&self) -> CharRevIterator<'self>;
|
||||
fn bytes_iter(&self) -> BytesIterator<'self>;
|
||||
fn bytes_rev_iter(&self) -> BytesRevIterator<'self>;
|
||||
fn split_iter<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep>;
|
||||
fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitIterator<'self, Sep>;
|
||||
fn split_options_iter<Sep: CharEq>(&self, sep: Sep, count: uint, allow_trailing_empty: bool)
|
||||
-> StrCharSplitIterator<'self, Sep>;
|
||||
fn matches_index_iter(&self, sep: &'self str) -> StrMatchesIndexIterator<'self>;
|
||||
fn split_str_iter(&self, &'self str) -> StrStrSplitIterator<'self>;
|
||||
fn line_iter(&self) -> StrCharSplitIterator<'self, char>;
|
||||
-> CharSplitIterator<'self, Sep>;
|
||||
fn matches_index_iter(&self, sep: &'self str) -> MatchesIndexIterator<'self>;
|
||||
fn split_str_iter(&self, &'self str) -> StrSplitIterator<'self>;
|
||||
fn line_iter(&self) -> CharSplitIterator<'self, char>;
|
||||
fn any_line_iter(&self) -> AnyLineIterator<'self>;
|
||||
fn word_iter(&self) -> WordIterator<'self>;
|
||||
fn ends_with(&self, needle: &str) -> bool;
|
||||
@ -1222,16 +1222,16 @@ impl<'self> StrSlice<'self> for &'self str {
|
||||
/// assert_eq!(v, ~['a', 'b', 'c', ' ', 'å', 'ä', 'ö']);
|
||||
/// ~~~
|
||||
#[inline]
|
||||
fn iter(&self) -> StrCharIterator<'self> {
|
||||
StrCharIterator {
|
||||
fn iter(&self) -> CharIterator<'self> {
|
||||
CharIterator {
|
||||
index: 0,
|
||||
string: *self
|
||||
}
|
||||
}
|
||||
/// An iterator over the characters of `self`, in reverse order.
|
||||
#[inline]
|
||||
fn rev_iter(&self) -> StrCharRevIterator<'self> {
|
||||
StrCharRevIterator {
|
||||
fn rev_iter(&self) -> CharRevIterator<'self> {
|
||||
CharRevIterator {
|
||||
index: self.len(),
|
||||
string: *self
|
||||
}
|
||||
@ -1239,13 +1239,13 @@ impl<'self> StrSlice<'self> for &'self str {
|
||||
|
||||
/// An iterator over the bytes of `self`
|
||||
#[inline]
|
||||
fn bytes_iter(&self) -> StrBytesIterator<'self> {
|
||||
StrBytesIterator { it: self.as_bytes().iter() }
|
||||
fn bytes_iter(&self) -> BytesIterator<'self> {
|
||||
BytesIterator { it: self.as_bytes().iter() }
|
||||
}
|
||||
/// An iterator over the bytes of `self`, in reverse order
|
||||
#[inline]
|
||||
fn bytes_rev_iter(&self) -> StrBytesRevIterator<'self> {
|
||||
StrBytesRevIterator { it: self.as_bytes().rev_iter() }
|
||||
fn bytes_rev_iter(&self) -> BytesRevIterator<'self> {
|
||||
BytesRevIterator { it: self.as_bytes().rev_iter() }
|
||||
}
|
||||
|
||||
/// An iterator over substrings of `self`, separated by characters
|
||||
@ -1261,7 +1261,7 @@ impl<'self> StrSlice<'self> for &'self str {
|
||||
/// assert_eq!(v, ~["abc", "def", "ghi"]);
|
||||
/// ~~~
|
||||
#[inline]
|
||||
fn split_iter<Sep: CharEq>(&self, sep: Sep) -> StrCharSplitIterator<'self, Sep> {
|
||||
fn split_iter<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep> {
|
||||
self.split_options_iter(sep, self.len(), true)
|
||||
}
|
||||
|
||||
@ -1269,7 +1269,7 @@ impl<'self> StrSlice<'self> for &'self str {
|
||||
/// matched by `sep`, restricted to splitting at most `count`
|
||||
/// times.
|
||||
#[inline]
|
||||
fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> StrCharSplitIterator<'self, Sep> {
|
||||
fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitIterator<'self, Sep> {
|
||||
self.split_options_iter(sep, count, true)
|
||||
}
|
||||
|
||||
@ -1279,9 +1279,9 @@ impl<'self> StrSlice<'self> for &'self str {
|
||||
/// exists.
|
||||
#[inline]
|
||||
fn split_options_iter<Sep: CharEq>(&self, sep: Sep, count: uint, allow_trailing_empty: bool)
|
||||
-> StrCharSplitIterator<'self, Sep> {
|
||||
-> CharSplitIterator<'self, Sep> {
|
||||
let only_ascii = sep.only_ascii();
|
||||
StrCharSplitIterator {
|
||||
CharSplitIterator {
|
||||
string: *self,
|
||||
position: 0,
|
||||
sep: sep,
|
||||
@ -1294,9 +1294,9 @@ impl<'self> StrSlice<'self> for &'self str {
|
||||
/// An iterator over the start and end indices of each match of
|
||||
/// `sep` within `self`.
|
||||
#[inline]
|
||||
fn matches_index_iter(&self, sep: &'self str) -> StrMatchesIndexIterator<'self> {
|
||||
fn matches_index_iter(&self, sep: &'self str) -> MatchesIndexIterator<'self> {
|
||||
assert!(!sep.is_empty())
|
||||
StrMatchesIndexIterator {
|
||||
MatchesIndexIterator {
|
||||
haystack: *self,
|
||||
needle: sep,
|
||||
position: 0
|
||||
@ -1313,8 +1313,8 @@ impl<'self> StrSlice<'self> for &'self str {
|
||||
* ~~~
|
||||
*/
|
||||
#[inline]
|
||||
fn split_str_iter(&self, sep: &'self str) -> StrStrSplitIterator<'self> {
|
||||
StrStrSplitIterator {
|
||||
fn split_str_iter(&self, sep: &'self str) -> StrSplitIterator<'self> {
|
||||
StrSplitIterator {
|
||||
it: self.matches_index_iter(sep),
|
||||
last_end: 0,
|
||||
finished: false
|
||||
@ -1324,7 +1324,7 @@ impl<'self> StrSlice<'self> for &'self str {
|
||||
/// An iterator over the lines of a string (subsequences separated
|
||||
/// by `\n`).
|
||||
#[inline]
|
||||
fn line_iter(&self) -> StrCharSplitIterator<'self, char> {
|
||||
fn line_iter(&self) -> CharSplitIterator<'self, char> {
|
||||
self.split_options_iter('\n', self.len(), false)
|
||||
}
|
||||
|
||||
@ -2253,12 +2253,12 @@ impl Clone for @str {
|
||||
/// External iterator for a string's characters. Use with the `std::iterator`
|
||||
/// module.
|
||||
#[deriving(Clone)]
|
||||
pub struct StrCharIterator<'self> {
|
||||
pub struct CharIterator<'self> {
|
||||
priv index: uint,
|
||||
priv string: &'self str,
|
||||
}
|
||||
|
||||
impl<'self> Iterator<char> for StrCharIterator<'self> {
|
||||
impl<'self> Iterator<char> for CharIterator<'self> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<char> {
|
||||
if self.index < self.string.len() {
|
||||
@ -2273,12 +2273,12 @@ impl<'self> Iterator<char> for StrCharIterator<'self> {
|
||||
/// External iterator for a string's characters in reverse order. Use
|
||||
/// with the `std::iterator` module.
|
||||
#[deriving(Clone)]
|
||||
pub struct StrCharRevIterator<'self> {
|
||||
pub struct CharRevIterator<'self> {
|
||||
priv index: uint,
|
||||
priv string: &'self str,
|
||||
}
|
||||
|
||||
impl<'self> Iterator<char> for StrCharRevIterator<'self> {
|
||||
impl<'self> Iterator<char> for CharRevIterator<'self> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<char> {
|
||||
if self.index > 0 {
|
||||
@ -2294,11 +2294,11 @@ impl<'self> Iterator<char> for StrCharRevIterator<'self> {
|
||||
/// External iterator for a string's bytes. Use with the `std::iterator`
|
||||
/// module.
|
||||
#[deriving(Clone)]
|
||||
pub struct StrBytesIterator<'self> {
|
||||
pub struct BytesIterator<'self> {
|
||||
priv it: vec::VecIterator<'self, u8>
|
||||
}
|
||||
|
||||
impl<'self> Iterator<u8> for StrBytesIterator<'self> {
|
||||
impl<'self> Iterator<u8> for BytesIterator<'self> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<u8> {
|
||||
self.it.next().map_consume(|&x| x)
|
||||
@ -2308,11 +2308,11 @@ impl<'self> Iterator<u8> for StrBytesIterator<'self> {
|
||||
/// External iterator for a string's bytes in reverse order. Use with
|
||||
/// the `std::iterator` module.
|
||||
#[deriving(Clone)]
|
||||
pub struct StrBytesRevIterator<'self> {
|
||||
priv it: vec::VecRevIterator<'self, u8>
|
||||
pub struct BytesRevIterator<'self> {
|
||||
priv it: vec::RevIterator<'self, u8>
|
||||
}
|
||||
|
||||
impl<'self> Iterator<u8> for StrBytesRevIterator<'self> {
|
||||
impl<'self> Iterator<u8> for BytesRevIterator<'self> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<u8> {
|
||||
self.it.next().map_consume(|&x| x)
|
||||
|
@ -157,14 +157,14 @@ pub fn build_sized_opt<A>(size: Option<uint>,
|
||||
|
||||
/// An iterator over the slices of a vector separated by elements that
|
||||
/// match a predicate function.
|
||||
pub struct VecSplitIterator<'self, T> {
|
||||
pub struct SplitIterator<'self, T> {
|
||||
priv v: &'self [T],
|
||||
priv n: uint,
|
||||
priv pred: &'self fn(t: &T) -> bool,
|
||||
priv finished: bool
|
||||
}
|
||||
|
||||
impl<'self, T> Iterator<&'self [T]> for VecSplitIterator<'self, T> {
|
||||
impl<'self, T> Iterator<&'self [T]> for SplitIterator<'self, T> {
|
||||
fn next(&mut self) -> Option<&'self [T]> {
|
||||
if self.finished { return None; }
|
||||
|
||||
@ -190,14 +190,14 @@ impl<'self, T> Iterator<&'self [T]> for VecSplitIterator<'self, T> {
|
||||
|
||||
/// An iterator over the slices of a vector separated by elements that
|
||||
/// match a predicate function, from back to front.
|
||||
pub struct VecRSplitIterator<'self, T> {
|
||||
pub struct RSplitIterator<'self, T> {
|
||||
priv v: &'self [T],
|
||||
priv n: uint,
|
||||
priv pred: &'self fn(t: &T) -> bool,
|
||||
priv finished: bool
|
||||
}
|
||||
|
||||
impl<'self, T> Iterator<&'self [T]> for VecRSplitIterator<'self, T> {
|
||||
impl<'self, T> Iterator<&'self [T]> for RSplitIterator<'self, T> {
|
||||
fn next(&mut self) -> Option<&'self [T]> {
|
||||
if self.finished { return None; }
|
||||
|
||||
@ -435,12 +435,12 @@ pub fn each_permutation<T:Clone>(values: &[T], fun: &fn(perm : &[T]) -> bool) ->
|
||||
|
||||
/// An iterator over the (overlapping) slices of length `size` within
|
||||
/// a vector.
|
||||
pub struct VecWindowIter<'self, T> {
|
||||
pub struct WindowIter<'self, T> {
|
||||
priv v: &'self [T],
|
||||
priv size: uint
|
||||
}
|
||||
|
||||
impl<'self, T> Iterator<&'self [T]> for VecWindowIter<'self, T> {
|
||||
impl<'self, T> Iterator<&'self [T]> for WindowIter<'self, T> {
|
||||
fn next(&mut self) -> Option<&'self [T]> {
|
||||
if self.size > self.v.len() {
|
||||
None
|
||||
@ -454,12 +454,12 @@ impl<'self, T> Iterator<&'self [T]> for VecWindowIter<'self, T> {
|
||||
|
||||
/// An iterator over a vector in (non-overlapping) chunks (`size`
|
||||
/// elements at a time).
|
||||
pub struct VecChunkIter<'self, T> {
|
||||
pub struct ChunkIter<'self, T> {
|
||||
priv v: &'self [T],
|
||||
priv size: uint
|
||||
}
|
||||
|
||||
impl<'self, T> Iterator<&'self [T]> for VecChunkIter<'self, T> {
|
||||
impl<'self, T> Iterator<&'self [T]> for ChunkIter<'self, T> {
|
||||
fn next(&mut self) -> Option<&'self [T]> {
|
||||
if self.size == 0 {
|
||||
None
|
||||
@ -691,14 +691,14 @@ pub trait ImmutableVector<'self, T> {
|
||||
fn slice_from(&self, start: uint) -> &'self [T];
|
||||
fn slice_to(&self, end: uint) -> &'self [T];
|
||||
fn iter(self) -> VecIterator<'self, T>;
|
||||
fn rev_iter(self) -> VecRevIterator<'self, T>;
|
||||
fn split_iter(self, pred: &'self fn(&T) -> bool) -> VecSplitIterator<'self, T>;
|
||||
fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> VecSplitIterator<'self, T>;
|
||||
fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> VecRSplitIterator<'self, T>;
|
||||
fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> VecRSplitIterator<'self, T>;
|
||||
fn rev_iter(self) -> RevIterator<'self, T>;
|
||||
fn split_iter(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>;
|
||||
fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>;
|
||||
fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>;
|
||||
fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>;
|
||||
|
||||
fn window_iter(self, size: uint) -> VecWindowIter<'self, T>;
|
||||
fn chunk_iter(self, size: uint) -> VecChunkIter<'self, T>;
|
||||
fn window_iter(self, size: uint) -> WindowIter<'self, T>;
|
||||
fn chunk_iter(self, size: uint) -> ChunkIter<'self, T>;
|
||||
|
||||
fn head(&self) -> &'self T;
|
||||
fn head_opt(&self) -> Option<&'self T>;
|
||||
@ -774,22 +774,22 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn rev_iter(self) -> VecRevIterator<'self, T> {
|
||||
fn rev_iter(self) -> RevIterator<'self, T> {
|
||||
self.iter().invert()
|
||||
}
|
||||
|
||||
/// Returns an iterator over the subslices of the vector which are
|
||||
/// separated by elements that match `pred`.
|
||||
#[inline]
|
||||
fn split_iter(self, pred: &'self fn(&T) -> bool) -> VecSplitIterator<'self, T> {
|
||||
fn split_iter(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> {
|
||||
self.splitn_iter(uint::max_value, pred)
|
||||
}
|
||||
/// Returns an iterator over the subslices of the vector which are
|
||||
/// separated by elements that match `pred`, limited to splitting
|
||||
/// at most `n` times.
|
||||
#[inline]
|
||||
fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> VecSplitIterator<'self, T> {
|
||||
VecSplitIterator {
|
||||
fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> {
|
||||
SplitIterator {
|
||||
v: self,
|
||||
n: n,
|
||||
pred: pred,
|
||||
@ -800,7 +800,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||
/// separated by elements that match `pred`. This starts at the
|
||||
/// end of the vector and works backwards.
|
||||
#[inline]
|
||||
fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> VecRSplitIterator<'self, T> {
|
||||
fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> {
|
||||
self.rsplitn_iter(uint::max_value, pred)
|
||||
}
|
||||
/// Returns an iterator over the subslices of the vector which are
|
||||
@ -808,8 +808,8 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||
/// at most `n` times. This starts at the end of the vector and
|
||||
/// works backwards.
|
||||
#[inline]
|
||||
fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> VecRSplitIterator<'self, T> {
|
||||
VecRSplitIterator {
|
||||
fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> {
|
||||
RSplitIterator {
|
||||
v: self,
|
||||
n: n,
|
||||
pred: pred,
|
||||
@ -839,9 +839,9 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||
* ~~~
|
||||
*
|
||||
*/
|
||||
fn window_iter(self, size: uint) -> VecWindowIter<'self, T> {
|
||||
fn window_iter(self, size: uint) -> WindowIter<'self, T> {
|
||||
assert!(size != 0);
|
||||
VecWindowIter { v: self, size: size }
|
||||
WindowIter { v: self, size: size }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -868,9 +868,9 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||
* ~~~
|
||||
*
|
||||
*/
|
||||
fn chunk_iter(self, size: uint) -> VecChunkIter<'self, T> {
|
||||
fn chunk_iter(self, size: uint) -> ChunkIter<'self, T> {
|
||||
assert!(size != 0);
|
||||
VecChunkIter { v: self, size: size }
|
||||
ChunkIter { v: self, size: size }
|
||||
}
|
||||
|
||||
/// Returns the first element of a vector, failing if the vector is empty.
|
||||
@ -1086,8 +1086,8 @@ impl<'self,T:Clone> ImmutableCopyableVector<T> for &'self [T] {
|
||||
|
||||
#[allow(missing_doc)]
|
||||
pub trait OwnedVector<T> {
|
||||
fn consume_iter(self) -> VecConsumeIterator<T>;
|
||||
fn consume_rev_iter(self) -> VecConsumeRevIterator<T>;
|
||||
fn consume_iter(self) -> ConsumeIterator<T>;
|
||||
fn consume_rev_iter(self) -> ConsumeRevIterator<T>;
|
||||
|
||||
fn reserve(&mut self, n: uint);
|
||||
fn reserve_at_least(&mut self, n: uint);
|
||||
@ -1128,14 +1128,14 @@ impl<T> OwnedVector<T> for ~[T] {
|
||||
/// println(s);
|
||||
/// }
|
||||
/// ~~~
|
||||
fn consume_iter(self) -> VecConsumeIterator<T> {
|
||||
VecConsumeIterator { v: self, idx: 0 }
|
||||
fn consume_iter(self) -> ConsumeIterator<T> {
|
||||
ConsumeIterator { v: self, idx: 0 }
|
||||
}
|
||||
/// Creates a consuming iterator that moves out of the vector in
|
||||
/// reverse order. Also see `consume_iter`, however note that this
|
||||
/// is more efficient.
|
||||
fn consume_rev_iter(self) -> VecConsumeRevIterator<T> {
|
||||
VecConsumeRevIterator { v: self }
|
||||
fn consume_rev_iter(self) -> ConsumeRevIterator<T> {
|
||||
ConsumeRevIterator { v: self }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1657,7 +1657,7 @@ pub trait MutableVector<'self, T> {
|
||||
fn mut_slice_from(self, start: uint) -> &'self mut [T];
|
||||
fn mut_slice_to(self, end: uint) -> &'self mut [T];
|
||||
fn mut_iter(self) -> VecMutIterator<'self, T>;
|
||||
fn mut_rev_iter(self) -> VecMutRevIterator<'self, T>;
|
||||
fn mut_rev_iter(self) -> MutRevIterator<'self, T>;
|
||||
|
||||
fn swap(self, a: uint, b: uint);
|
||||
|
||||
@ -1751,7 +1751,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mut_rev_iter(self) -> VecMutRevIterator<'self, T> {
|
||||
fn mut_rev_iter(self) -> MutRevIterator<'self, T> {
|
||||
self.mut_iter().invert()
|
||||
}
|
||||
|
||||
@ -2166,7 +2166,7 @@ pub struct VecIterator<'self, T> {
|
||||
iterator!{impl VecIterator -> &'self T}
|
||||
double_ended_iterator!{impl VecIterator -> &'self T}
|
||||
random_access_iterator!{impl VecIterator -> &'self T}
|
||||
pub type VecRevIterator<'self, T> = InvertIterator<VecIterator<'self, T>>;
|
||||
pub type RevIterator<'self, T> = InvertIterator<VecIterator<'self, T>>;
|
||||
|
||||
impl<'self, T> Clone for VecIterator<'self, T> {
|
||||
fn clone(&self) -> VecIterator<'self, T> { *self }
|
||||
@ -2182,16 +2182,16 @@ pub struct VecMutIterator<'self, T> {
|
||||
iterator!{impl VecMutIterator -> &'self mut T}
|
||||
double_ended_iterator!{impl VecMutIterator -> &'self mut T}
|
||||
random_access_iterator!{impl VecMutIterator -> &'self mut T}
|
||||
pub type VecMutRevIterator<'self, T> = InvertIterator<VecMutIterator<'self, T>>;
|
||||
pub type MutRevIterator<'self, T> = InvertIterator<VecMutIterator<'self, T>>;
|
||||
|
||||
/// An iterator that moves out of a vector.
|
||||
#[deriving(Clone)]
|
||||
pub struct VecConsumeIterator<T> {
|
||||
pub struct ConsumeIterator<T> {
|
||||
priv v: ~[T],
|
||||
priv idx: uint,
|
||||
}
|
||||
|
||||
impl<T> Iterator<T> for VecConsumeIterator<T> {
|
||||
impl<T> Iterator<T> for ConsumeIterator<T> {
|
||||
fn next(&mut self) -> Option<T> {
|
||||
// this is peculiar, but is required for safety with respect
|
||||
// to dtors. It traverses the first half of the vec, and
|
||||
@ -2213,11 +2213,11 @@ impl<T> Iterator<T> for VecConsumeIterator<T> {
|
||||
|
||||
/// An iterator that moves out of a vector in reverse order.
|
||||
#[deriving(Clone)]
|
||||
pub struct VecConsumeRevIterator<T> {
|
||||
pub struct ConsumeRevIterator<T> {
|
||||
priv v: ~[T]
|
||||
}
|
||||
|
||||
impl<T> Iterator<T> for VecConsumeRevIterator<T> {
|
||||
impl<T> Iterator<T> for ConsumeRevIterator<T> {
|
||||
fn next(&mut self) -> Option<T> {
|
||||
self.v.pop_opt()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user