use cmp;
use iterator::*;
use libc::c_void;
-use num::Zero;
+use num::{Integer, Zero, CheckedAdd, Saturating};
use option::{None, Option, Some};
use ptr::to_unsafe_ptr;
use ptr;
}
impl<'self, T> Iterator<&'self [T]> for SplitIterator<'self, T> {
+ #[inline]
fn next(&mut self) -> Option<&'self [T]> {
if self.finished { return None; }
}
}
}
+
+ #[inline]
+ fn size_hint(&self) -> (uint, Option<uint>) {
+ if self.finished {
+ return (0, Some(0))
+ }
+ // if the predicate doesn't match anything, we yield one slice
+ // if it matches every element, we yield N+1 empty slices where
+ // N is either the number of elements or the number of splits.
+ match (self.v.len(), self.n) {
+ (0,_) => (1, Some(1)),
+ (_,0) => (1, Some(1)),
+ (l,n) => (1, cmp::min(l,n).checked_add(&1u))
+ }
+ }
}
/// An iterator over the slices of a vector separated by elements that
}
impl<'self, T> Iterator<&'self [T]> for RSplitIterator<'self, T> {
+ #[inline]
fn next(&mut self) -> Option<&'self [T]> {
if self.finished { return None; }
}
}
}
+
+ #[inline]
+ fn size_hint(&self) -> (uint, Option<uint>) {
+ if self.finished {
+ return (0, Some(0))
+ }
+ match (self.v.len(), self.n) {
+ (0,_) => (1, Some(1)),
+ (_,0) => (1, Some(1)),
+ (l,n) => (1, cmp::min(l,n).checked_add(&1u))
+ }
+ }
}
// Appending
}
impl<'self, T> Iterator<&'self [T]> for WindowIter<'self, T> {
+ #[inline]
fn next(&mut self) -> Option<&'self [T]> {
if self.size > self.v.len() {
None
ret
}
}
+
+ #[inline]
+ fn size_hint(&self) -> (uint, Option<uint>) {
+ if self.size > self.v.len() {
+ (0, Some(0))
+ } else {
+ let x = self.v.len() - self.size;
+ (x.saturating_add(1), x.checked_add(&1u))
+ }
+ }
}
/// An iterator over a vector in (non-overlapping) chunks (`size`
}
impl<'self, T> Iterator<&'self [T]> for ChunkIter<'self, T> {
+ #[inline]
fn next(&mut self) -> Option<&'self [T]> {
if self.v.len() == 0 {
None
Some(fst)
}
}
+
+ #[inline]
+ fn size_hint(&self) -> (uint, Option<uint>) {
+ if self.v.len() == 0 {
+ (0, Some(0))
+ } else {
+ let (n, rem) = self.v.len().div_rem(&self.size);
+ let n = if rem > 0 { n+1 } else { n };
+ (n, Some(n))
+ }
+ }
}
impl<'self, T> DoubleEndedIterator<&'self [T]> for ChunkIter<'self, T> {
+ #[inline]
fn next_back(&mut self) -> Option<&'self [T]> {
if self.v.len() == 0 {
None
exact
}
+ #[inline]
fn idx(&self, index: uint) -> Option<&'self T> {
unsafe {
if index < self.indexable() {
}
impl<T> Iterator<T> for MoveIterator<T> {
+ #[inline]
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
self.v.pop_opt()
}
+
+ #[inline]
+ fn size_hint(&self) -> (uint, Option<uint>) {
+ let l = self.v.len();
+ (l, Some(l))
+ }
}
/// An iterator that moves out of a vector in reverse order.
}
impl<T> Iterator<T> for MoveRevIterator<T> {
+ #[inline]
fn next(&mut self) -> Option<T> {
self.v.pop_opt()
}
+
+ #[inline]
+ fn size_hint(&self) -> (uint, Option<uint>) {
+ let l = self.v.len();
+ (l, Some(l))
+ }
}
impl<A> FromIterator<A> for ~[A] {