make way for a new iter module
This commit is contained in:
parent
9f03d45c56
commit
46f91a0fa9
@ -1981,7 +1981,7 @@ struct TimeBomb {
|
||||
|
||||
impl Drop for TimeBomb {
|
||||
fn finalize(&self) {
|
||||
for iter::repeat(self.explosivity) {
|
||||
for old_iter::repeat(self.explosivity) {
|
||||
io::println("blam!");
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
use cast::transmute;
|
||||
use kinds::Copy;
|
||||
use iter;
|
||||
use old_iter;
|
||||
use option::Option;
|
||||
use ptr::addr_of;
|
||||
use sys;
|
||||
@ -125,7 +125,7 @@ pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
|
||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||
* to the value returned by the function `op`.
|
||||
*/
|
||||
pub fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
|
||||
pub fn from_fn<T>(n_elts: uint, op: old_iter::InitOp<T>) -> @[T] {
|
||||
do build_sized(n_elts) |push| {
|
||||
let mut i: uint = 0u;
|
||||
while i < n_elts { push(op(i)); i += 1u; }
|
||||
|
@ -99,9 +99,10 @@ pub use container::{Container, Mutable};
|
||||
pub use vec::{CopyableVector, ImmutableVector};
|
||||
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
|
||||
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};
|
||||
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
|
||||
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
|
||||
pub use iter::{ExtendedMutableIter};
|
||||
pub use old_iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
|
||||
pub use old_iter::{CopyableOrderedIter, CopyableNonstrictIter};
|
||||
pub use old_iter::{ExtendedMutableIter};
|
||||
pub use iter::Times;
|
||||
|
||||
pub use num::{Num, NumCast};
|
||||
pub use num::{Orderable, Signed, Unsigned, Integer};
|
||||
@ -188,6 +189,7 @@ pub mod from_str;
|
||||
#[path = "num/num.rs"]
|
||||
pub mod num;
|
||||
pub mod iter;
|
||||
pub mod old_iter;
|
||||
pub mod iterator;
|
||||
pub mod to_str;
|
||||
pub mod to_bytes;
|
||||
|
@ -16,9 +16,9 @@
|
||||
use container::{Container, Mutable, Map, Set};
|
||||
use cmp::{Eq, Equiv};
|
||||
use hash::Hash;
|
||||
use iter::BaseIter;
|
||||
use old_iter::BaseIter;
|
||||
use hash::Hash;
|
||||
use iter;
|
||||
use old_iter;
|
||||
use option::{None, Option, Some};
|
||||
use rand::RngUtil;
|
||||
use rand;
|
||||
@ -757,12 +757,12 @@ fn remove(&mut self, value: &T) -> bool { self.map.remove(value) }
|
||||
/// Return true if the set has no elements in common with `other`.
|
||||
/// This is equivalent to checking for an empty intersection.
|
||||
fn is_disjoint(&self, other: &HashSet<T>) -> bool {
|
||||
iter::all(self, |v| !other.contains(v))
|
||||
old_iter::all(self, |v| !other.contains(v))
|
||||
}
|
||||
|
||||
/// Return true if the set is a subset of another
|
||||
fn is_subset(&self, other: &HashSet<T>) -> bool {
|
||||
iter::all(self, |v| other.contains(v))
|
||||
old_iter::all(self, |v| other.contains(v))
|
||||
}
|
||||
|
||||
/// Return true if the set is a superset of another
|
||||
|
@ -8,369 +8,124 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
/*!
|
||||
/*! Composable internal iterators
|
||||
|
||||
The iteration traits and common implementation
|
||||
Internal iterators are functions implementing the protocol used by the `for` loop.
|
||||
|
||||
An internal iterator takes `fn(...) -> bool` as a parameter, with returning `false` used to signal
|
||||
breaking out of iteration. The adaptors in the module work with any such iterator, not just ones
|
||||
tied to specific traits. For example:
|
||||
|
||||
~~~~
|
||||
use core::iter::iter_to_vec;
|
||||
println(iter_to_vec(|f| uint::range(0, 20, f)).to_str());
|
||||
~~~~
|
||||
|
||||
An external iterator object implementing the interface in the `iterator` module can be used as an
|
||||
internal iterator by calling the `advance` method. For example:
|
||||
|
||||
~~~~
|
||||
use core::iterator::*;
|
||||
|
||||
let xs = [0u, 1, 2, 3, 4, 5];
|
||||
let ys = [30, 40, 50, 60];
|
||||
let mut it = xs.iter().chain(ys.iter());
|
||||
for it.advance |&x: &uint| {
|
||||
println(x.to_str());
|
||||
}
|
||||
~~~~
|
||||
|
||||
Internal iterators provide a subset of the functionality of an external iterator. It's not possible
|
||||
to interleave them to implement algorithms like `zip`, `union` and `merge`. However, they're often
|
||||
much easier to implement.
|
||||
|
||||
*/
|
||||
|
||||
use cmp::{Eq, Ord};
|
||||
use kinds::Copy;
|
||||
use option::{None, Option, Some};
|
||||
use vec;
|
||||
|
||||
/// A function used to initialize the elements of a sequence
|
||||
pub type InitOp<'self,T> = &'self fn(uint) -> T;
|
||||
|
||||
pub trait BaseIter<A> {
|
||||
fn each(&self, blk: &fn(v: &A) -> bool);
|
||||
fn size_hint(&self) -> Option<uint>;
|
||||
}
|
||||
|
||||
pub trait ReverseIter<A>: BaseIter<A> {
|
||||
fn each_reverse(&self, blk: &fn(&A) -> bool);
|
||||
}
|
||||
|
||||
pub trait MutableIter<A>: BaseIter<A> {
|
||||
fn each_mut(&mut self, blk: &fn(&mut A) -> bool);
|
||||
}
|
||||
|
||||
pub trait ExtendedIter<A> {
|
||||
fn eachi(&self, blk: &fn(uint, v: &A) -> bool);
|
||||
fn all(&self, blk: &fn(&A) -> bool) -> bool;
|
||||
fn any(&self, blk: &fn(&A) -> bool) -> bool;
|
||||
fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B;
|
||||
fn position(&self, f: &fn(&A) -> bool) -> Option<uint>;
|
||||
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B];
|
||||
fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B];
|
||||
}
|
||||
|
||||
pub trait ExtendedMutableIter<A> {
|
||||
fn eachi_mut(&mut self, blk: &fn(uint, &mut A) -> bool);
|
||||
}
|
||||
|
||||
pub trait EqIter<A:Eq> {
|
||||
fn contains(&self, x: &A) -> bool;
|
||||
fn count(&self, x: &A) -> uint;
|
||||
}
|
||||
|
||||
pub trait Times {
|
||||
fn times(&self, it: &fn() -> bool);
|
||||
}
|
||||
|
||||
pub trait CopyableIter<A:Copy> {
|
||||
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A];
|
||||
fn to_vec(&self) -> ~[A];
|
||||
fn find(&self, p: &fn(&A) -> bool) -> Option<A>;
|
||||
}
|
||||
|
||||
pub trait CopyableOrderedIter<A:Copy + Ord> {
|
||||
fn min(&self) -> A;
|
||||
fn max(&self) -> A;
|
||||
}
|
||||
|
||||
pub trait CopyableNonstrictIter<A:Copy> {
|
||||
// Like "each", but copies out the value. If the receiver is mutated while
|
||||
// iterating over it, the semantics must not be memory-unsafe but are
|
||||
// otherwise undefined.
|
||||
fn each_val(&const self, f: &fn(A) -> bool);
|
||||
}
|
||||
|
||||
// A trait for sequences that can be built by imperatively pushing elements
|
||||
// onto them.
|
||||
pub trait Buildable<A> {
|
||||
/**
|
||||
* Builds a buildable sequence by calling a provided function with
|
||||
* an argument function that pushes an element onto the back of
|
||||
* the sequence.
|
||||
* This version takes an initial size for the sequence.
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * size - A hint for an initial size of the sequence
|
||||
* * builder - A function that will construct the sequence. It receives
|
||||
* as an argument a function that will push an element
|
||||
* onto the sequence being constructed.
|
||||
*/
|
||||
fn build_sized(size: uint, builder: &fn(push: &fn(A))) -> Self;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) {
|
||||
let mut i = 0;
|
||||
for self.each |a| {
|
||||
if !blk(i, a) { break; }
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn all<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
|
||||
for self.each |a| {
|
||||
if !blk(a) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn any<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
|
||||
for self.each |a| {
|
||||
if blk(a) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: &IA,
|
||||
prd: &fn(&A) -> bool)
|
||||
-> ~[A] {
|
||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||
for self.each |a| {
|
||||
if prd(a) { push(*a); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA, op: &fn(&A) -> B) -> ~[B] {
|
||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||
for self.each |a| {
|
||||
push(op(a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(self: &IA,
|
||||
op: &fn(&A) -> IB)
|
||||
-> ~[B] {
|
||||
do vec::build |push| {
|
||||
for self.each |a| {
|
||||
for op(a).each |&b| {
|
||||
push(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B, blk: &fn(&B, &A) -> B)
|
||||
-> B {
|
||||
let mut b = b0;
|
||||
for self.each |a| {
|
||||
b = blk(&b, a);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
|
||||
map_to_vec(self, |&x| x)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
|
||||
for self.each |a| {
|
||||
if *a == *x { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
|
||||
do foldl(self, 0) |count, value| {
|
||||
if *value == *x {
|
||||
*count + 1
|
||||
} else {
|
||||
*count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
|
||||
-> Option<uint> {
|
||||
let mut i = 0;
|
||||
for self.each |a| {
|
||||
if f(a) { return Some(i); }
|
||||
i += 1;
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
// note: 'rposition' would only make sense to provide with a bidirectional
|
||||
// iter interface, such as would provide "reach" in addition to "each". As is,
|
||||
// it would have to be implemented with foldr, which is too inefficient.
|
||||
|
||||
#[inline(always)]
|
||||
pub fn repeat(times: uint, blk: &fn() -> bool) {
|
||||
let mut i = 0;
|
||||
while i < times {
|
||||
if !blk() { break }
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||
match a {
|
||||
&Some(ref a_) if *a_ < *b => {
|
||||
*(a)
|
||||
}
|
||||
_ => Some(*b)
|
||||
}
|
||||
} {
|
||||
Some(val) => val,
|
||||
None => fail!(~"min called on empty iterator")
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||
match a {
|
||||
&Some(ref a_) if *a_ > *b => {
|
||||
*(a)
|
||||
}
|
||||
_ => Some(*b)
|
||||
}
|
||||
} {
|
||||
Some(val) => val,
|
||||
None => fail!(~"max called on empty iterator")
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn find<A:Copy,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
|
||||
-> Option<A> {
|
||||
for self.each |i| {
|
||||
if f(i) { return Some(*i) }
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
// Some functions for just building
|
||||
|
||||
/**
|
||||
* Builds a sequence by calling a provided function with an argument
|
||||
* function that pushes an element to the back of a sequence.
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * builder - A function that will construct the sequence. It receives
|
||||
* as an argument a function that will push an element
|
||||
* onto the sequence being constructed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn build<A,B: Buildable<A>>(builder: &fn(push: &fn(A))) -> B {
|
||||
Buildable::build_sized(4, builder)
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a sequence by calling a provided function with an argument
|
||||
* function that pushes an element to the back of the sequence.
|
||||
* This version takes an initial size for the sequence.
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * size - An option, maybe containing initial size of the sequence
|
||||
* to reserve.
|
||||
* * builder - A function that will construct the sequence. It receives
|
||||
* as an argument a function that will push an element
|
||||
* onto the sequence being constructed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn build_sized_opt<A,B: Buildable<A>>(size: Option<uint>,
|
||||
builder: &fn(push: &fn(A))) -> B {
|
||||
Buildable::build_sized(size.get_or_default(4), builder)
|
||||
}
|
||||
|
||||
// Functions that combine iteration and building
|
||||
|
||||
/// Applies a function to each element of an iterable and returns the results
|
||||
/// in a sequence built via `BU`. See also `map_to_vec`.
|
||||
#[inline(always)]
|
||||
pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
|
||||
-> BU {
|
||||
do build_sized_opt(v.size_hint()) |push| {
|
||||
for v.each() |elem| {
|
||||
push(f(elem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes a generic sequence from a function.
|
||||
*
|
||||
* Creates a generic sequence of size `n_elts` and initializes the elements
|
||||
* to the value returned by the function `op`.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn from_fn<T,BT: Buildable<T>>(n_elts: uint, op: InitOp<T>) -> BT {
|
||||
do Buildable::build_sized(n_elts) |push| {
|
||||
let mut i: uint = 0u;
|
||||
while i < n_elts { push(op(i)); i += 1u; }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes a generic sequence with some elements.
|
||||
*
|
||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||
* to the value `t`.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn from_elem<T:Copy,BT:Buildable<T>>(n_elts: uint, t: T) -> BT {
|
||||
do Buildable::build_sized(n_elts) |push| {
|
||||
let mut i: uint = 0;
|
||||
while i < n_elts { push(t); i += 1; }
|
||||
}
|
||||
}
|
||||
|
||||
/// Appends two generic sequences.
|
||||
#[inline(always)]
|
||||
pub fn append<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(lhs: &IT, rhs: &IT)
|
||||
-> BT {
|
||||
let size_opt = lhs.size_hint().chain_ref(
|
||||
|sz1| rhs.size_hint().map(|sz2| *sz1+*sz2));
|
||||
do build_sized_opt(size_opt) |push| {
|
||||
for lhs.each |x| { push(*x); }
|
||||
for rhs.each |x| { push(*x); }
|
||||
}
|
||||
}
|
||||
|
||||
/// Copies a generic sequence, possibly converting it to a different
|
||||
/// type of sequence.
|
||||
#[inline(always)]
|
||||
pub fn copy_seq<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(v: &IT) -> BT {
|
||||
do build_sized_opt(v.size_hint()) |push| {
|
||||
for v.each |x| { push(*x); }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to transform an internal iterator into an owned vector.
|
||||
* Transform an internal iterator into an owned vector.
|
||||
*
|
||||
* # Example:
|
||||
*
|
||||
* ~~~
|
||||
* let v = ~[1, 2, 3];
|
||||
* let v2 = do iter_to_vec |f| { v.each(|e| f(*e)) };
|
||||
* if v != v2 { fail!() }
|
||||
* let xs = ~[1, 2, 3];
|
||||
* let ys = do iter_to_vec |f| { xs.each(|x| f(*x)) };
|
||||
* assert_eq!(xs, ys);
|
||||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn iter_to_vec<T>(pusher: &fn(it: &fn(T) -> bool)) -> ~[T] {
|
||||
pub fn iter_to_vec<T>(iter: &fn(f: &fn(T) -> bool)) -> ~[T] {
|
||||
let mut v = ~[];
|
||||
let pushf = |e| {v.push(e); true};
|
||||
pusher(pushf);
|
||||
for iter |x| { v.push(x) }
|
||||
v
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iter_to_vec() {
|
||||
let v = ~[1, 2, 3];
|
||||
let v2 = do iter_to_vec |f| { v.each(|e| f(*e)) };
|
||||
if v != v2 { fail!() }
|
||||
/**
|
||||
* Return true if `predicate` is true for any values yielded by an internal iterator.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ~~~~
|
||||
* let xs = ~[1u, 2, 3, 4, 5];
|
||||
* assert!(any(|&x: &uint| x > 2, |f| xs.each(f)));
|
||||
* assert!(!any(|&x: &uint| x > 5, |f| xs.each(f)));
|
||||
* ~~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn any<T>(predicate: &fn(T) -> bool, iter: &fn(f: &fn(T) -> bool)) -> bool {
|
||||
for iter |x| {
|
||||
if predicate(x) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if `predicate` is true for all values yielded by an internal iterator.
|
||||
*
|
||||
* # Example:
|
||||
*
|
||||
* ~~~~
|
||||
* assert!(all(|&x: &uint| x < 6, |f| uint::range(1, 6, f)));
|
||||
* assert!(!all(|&x: &uint| x < 5, |f| uint::range(1, 6, f)));
|
||||
* ~~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn all<T>(predicate: &fn(T) -> bool, iter: &fn(f: &fn(T) -> bool)) -> bool {
|
||||
for iter |x| {
|
||||
if !predicate(x) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_iter_to_vec() {
|
||||
let xs = ~[1, 2, 3];
|
||||
let ys = do iter_to_vec |f| { xs.each(|x| f(*x)) };
|
||||
assert_eq!(xs, ys);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_any() {
|
||||
let xs = ~[1u, 2, 3, 4, 5];
|
||||
assert!(any(|&x: &uint| x > 2, |f| xs.each(f)));
|
||||
assert!(!any(|&x: &uint| x > 5, |f| xs.each(f)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_all() {
|
||||
assert!(all(|x: uint| x < 6, |f| uint::range(1, 6, f)));
|
||||
assert!(!all(|x: uint| x < 5, |f| uint::range(1, 6, f)));
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
};
|
||||
|
||||
pub mod inst {
|
||||
use sys;
|
||||
use iter;
|
||||
use num::{Primitive, BitCount};
|
||||
use sys;
|
||||
|
||||
pub type T = uint;
|
||||
#[allow(non_camel_case_types)]
|
||||
|
346
src/libcore/old_iter.rs
Normal file
346
src/libcore/old_iter.rs
Normal file
@ -0,0 +1,346 @@
|
||||
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
/*!
|
||||
|
||||
**Deprecated** iteration traits and common implementations.
|
||||
|
||||
*/
|
||||
|
||||
use cmp::{Eq, Ord};
|
||||
use kinds::Copy;
|
||||
use option::{None, Option, Some};
|
||||
use vec;
|
||||
|
||||
/// A function used to initialize the elements of a sequence
|
||||
pub type InitOp<'self,T> = &'self fn(uint) -> T;
|
||||
|
||||
pub trait BaseIter<A> {
|
||||
fn each(&self, blk: &fn(v: &A) -> bool);
|
||||
fn size_hint(&self) -> Option<uint>;
|
||||
}
|
||||
|
||||
pub trait ReverseIter<A>: BaseIter<A> {
|
||||
fn each_reverse(&self, blk: &fn(&A) -> bool);
|
||||
}
|
||||
|
||||
pub trait MutableIter<A>: BaseIter<A> {
|
||||
fn each_mut(&mut self, blk: &fn(&mut A) -> bool);
|
||||
}
|
||||
|
||||
pub trait ExtendedIter<A> {
|
||||
fn eachi(&self, blk: &fn(uint, v: &A) -> bool);
|
||||
fn all(&self, blk: &fn(&A) -> bool) -> bool;
|
||||
fn any(&self, blk: &fn(&A) -> bool) -> bool;
|
||||
fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B;
|
||||
fn position(&self, f: &fn(&A) -> bool) -> Option<uint>;
|
||||
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B];
|
||||
fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B];
|
||||
}
|
||||
|
||||
pub trait ExtendedMutableIter<A> {
|
||||
fn eachi_mut(&mut self, blk: &fn(uint, &mut A) -> bool);
|
||||
}
|
||||
|
||||
pub trait EqIter<A:Eq> {
|
||||
fn contains(&self, x: &A) -> bool;
|
||||
fn count(&self, x: &A) -> uint;
|
||||
}
|
||||
|
||||
pub trait CopyableIter<A:Copy> {
|
||||
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A];
|
||||
fn to_vec(&self) -> ~[A];
|
||||
fn find(&self, p: &fn(&A) -> bool) -> Option<A>;
|
||||
}
|
||||
|
||||
pub trait CopyableOrderedIter<A:Copy + Ord> {
|
||||
fn min(&self) -> A;
|
||||
fn max(&self) -> A;
|
||||
}
|
||||
|
||||
pub trait CopyableNonstrictIter<A:Copy> {
|
||||
// Like "each", but copies out the value. If the receiver is mutated while
|
||||
// iterating over it, the semantics must not be memory-unsafe but are
|
||||
// otherwise undefined.
|
||||
fn each_val(&const self, f: &fn(A) -> bool);
|
||||
}
|
||||
|
||||
// A trait for sequences that can be built by imperatively pushing elements
|
||||
// onto them.
|
||||
pub trait Buildable<A> {
|
||||
/**
|
||||
* Builds a buildable sequence by calling a provided function with
|
||||
* an argument function that pushes an element onto the back of
|
||||
* the sequence.
|
||||
* This version takes an initial size for the sequence.
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * size - A hint for an initial size of the sequence
|
||||
* * builder - A function that will construct the sequence. It receives
|
||||
* as an argument a function that will push an element
|
||||
* onto the sequence being constructed.
|
||||
*/
|
||||
fn build_sized(size: uint, builder: &fn(push: &fn(A))) -> Self;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) {
|
||||
let mut i = 0;
|
||||
for self.each |a| {
|
||||
if !blk(i, a) { break; }
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn all<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
|
||||
for self.each |a| {
|
||||
if !blk(a) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn any<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
|
||||
for self.each |a| {
|
||||
if blk(a) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: &IA,
|
||||
prd: &fn(&A) -> bool)
|
||||
-> ~[A] {
|
||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||
for self.each |a| {
|
||||
if prd(a) { push(*a); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA, op: &fn(&A) -> B) -> ~[B] {
|
||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||
for self.each |a| {
|
||||
push(op(a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(self: &IA,
|
||||
op: &fn(&A) -> IB)
|
||||
-> ~[B] {
|
||||
do vec::build |push| {
|
||||
for self.each |a| {
|
||||
for op(a).each |&b| {
|
||||
push(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B, blk: &fn(&B, &A) -> B)
|
||||
-> B {
|
||||
let mut b = b0;
|
||||
for self.each |a| {
|
||||
b = blk(&b, a);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
|
||||
map_to_vec(self, |&x| x)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
|
||||
for self.each |a| {
|
||||
if *a == *x { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
|
||||
do foldl(self, 0) |count, value| {
|
||||
if *value == *x {
|
||||
*count + 1
|
||||
} else {
|
||||
*count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
|
||||
-> Option<uint> {
|
||||
let mut i = 0;
|
||||
for self.each |a| {
|
||||
if f(a) { return Some(i); }
|
||||
i += 1;
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
// note: 'rposition' would only make sense to provide with a bidirectional
|
||||
// iter interface, such as would provide "reach" in addition to "each". As is,
|
||||
// it would have to be implemented with foldr, which is too inefficient.
|
||||
|
||||
#[inline(always)]
|
||||
pub fn repeat(times: uint, blk: &fn() -> bool) {
|
||||
let mut i = 0;
|
||||
while i < times {
|
||||
if !blk() { break }
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||
match a {
|
||||
&Some(ref a_) if *a_ < *b => {
|
||||
*(a)
|
||||
}
|
||||
_ => Some(*b)
|
||||
}
|
||||
} {
|
||||
Some(val) => val,
|
||||
None => fail!(~"min called on empty iterator")
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||
match a {
|
||||
&Some(ref a_) if *a_ > *b => {
|
||||
*(a)
|
||||
}
|
||||
_ => Some(*b)
|
||||
}
|
||||
} {
|
||||
Some(val) => val,
|
||||
None => fail!(~"max called on empty iterator")
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn find<A:Copy,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
|
||||
-> Option<A> {
|
||||
for self.each |i| {
|
||||
if f(i) { return Some(*i) }
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
// Some functions for just building
|
||||
|
||||
/**
|
||||
* Builds a sequence by calling a provided function with an argument
|
||||
* function that pushes an element to the back of a sequence.
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * builder - A function that will construct the sequence. It receives
|
||||
* as an argument a function that will push an element
|
||||
* onto the sequence being constructed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn build<A,B: Buildable<A>>(builder: &fn(push: &fn(A))) -> B {
|
||||
Buildable::build_sized(4, builder)
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a sequence by calling a provided function with an argument
|
||||
* function that pushes an element to the back of the sequence.
|
||||
* This version takes an initial size for the sequence.
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * size - An option, maybe containing initial size of the sequence
|
||||
* to reserve.
|
||||
* * builder - A function that will construct the sequence. It receives
|
||||
* as an argument a function that will push an element
|
||||
* onto the sequence being constructed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn build_sized_opt<A,B: Buildable<A>>(size: Option<uint>,
|
||||
builder: &fn(push: &fn(A))) -> B {
|
||||
Buildable::build_sized(size.get_or_default(4), builder)
|
||||
}
|
||||
|
||||
// Functions that combine iteration and building
|
||||
|
||||
/// Applies a function to each element of an iterable and returns the results
|
||||
/// in a sequence built via `BU`. See also `map_to_vec`.
|
||||
#[inline(always)]
|
||||
pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
|
||||
-> BU {
|
||||
do build_sized_opt(v.size_hint()) |push| {
|
||||
for v.each() |elem| {
|
||||
push(f(elem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes a generic sequence from a function.
|
||||
*
|
||||
* Creates a generic sequence of size `n_elts` and initializes the elements
|
||||
* to the value returned by the function `op`.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn from_fn<T,BT: Buildable<T>>(n_elts: uint, op: InitOp<T>) -> BT {
|
||||
do Buildable::build_sized(n_elts) |push| {
|
||||
let mut i: uint = 0u;
|
||||
while i < n_elts { push(op(i)); i += 1u; }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes a generic sequence with some elements.
|
||||
*
|
||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||
* to the value `t`.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn from_elem<T:Copy,BT:Buildable<T>>(n_elts: uint, t: T) -> BT {
|
||||
do Buildable::build_sized(n_elts) |push| {
|
||||
let mut i: uint = 0;
|
||||
while i < n_elts { push(t); i += 1; }
|
||||
}
|
||||
}
|
||||
|
||||
/// Appends two generic sequences.
|
||||
#[inline(always)]
|
||||
pub fn append<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(lhs: &IT, rhs: &IT)
|
||||
-> BT {
|
||||
let size_opt = lhs.size_hint().chain_ref(
|
||||
|sz1| rhs.size_hint().map(|sz2| *sz1+*sz2));
|
||||
do build_sized_opt(size_opt) |push| {
|
||||
for lhs.each |x| { push(*x); }
|
||||
for rhs.each |x| { push(*x); }
|
||||
}
|
||||
}
|
||||
|
||||
/// Copies a generic sequence, possibly converting it to a different
|
||||
/// type of sequence.
|
||||
#[inline(always)]
|
||||
pub fn copy_seq<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(v: &IT) -> BT {
|
||||
do build_sized_opt(v.size_hint()) |push| {
|
||||
for v.each |x| { push(*x); }
|
||||
}
|
||||
}
|
@ -46,8 +46,8 @@
|
||||
use kinds::Copy;
|
||||
use util;
|
||||
use num::Zero;
|
||||
use iter::{BaseIter, MutableIter, ExtendedIter};
|
||||
use iter;
|
||||
use old_iter::{BaseIter, MutableIter, ExtendedIter};
|
||||
use old_iter;
|
||||
|
||||
#[cfg(test)] use ptr;
|
||||
#[cfg(test)] use str;
|
||||
@ -140,26 +140,26 @@ fn each_mut<'a>(&'a mut self, f: &fn(&'a mut T) -> bool) {
|
||||
|
||||
impl<A> ExtendedIter<A> for Option<A> {
|
||||
pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
|
||||
iter::eachi(self, blk)
|
||||
old_iter::eachi(self, blk)
|
||||
}
|
||||
pub fn all(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::all(self, blk)
|
||||
old_iter::all(self, blk)
|
||||
}
|
||||
pub fn any(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::any(self, blk)
|
||||
old_iter::any(self, blk)
|
||||
}
|
||||
pub fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
|
||||
iter::foldl(self, b0, blk)
|
||||
old_iter::foldl(self, b0, blk)
|
||||
}
|
||||
pub fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
|
||||
iter::position(self, f)
|
||||
old_iter::position(self, f)
|
||||
}
|
||||
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
|
||||
iter::map_to_vec(self, op)
|
||||
old_iter::map_to_vec(self, op)
|
||||
}
|
||||
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
|
||||
-> ~[B] {
|
||||
iter::flat_map_to_vec(self, op)
|
||||
old_iter::flat_map_to_vec(self, op)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,10 @@
|
||||
pub use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
|
||||
pub use container::{Container, Mutable, Map, Set};
|
||||
pub use hash::Hash;
|
||||
pub use iter::{BaseIter, ReverseIter, MutableIter, ExtendedIter, EqIter};
|
||||
pub use iter::{CopyableIter, CopyableOrderedIter, CopyableNonstrictIter};
|
||||
pub use iter::{Times, ExtendedMutableIter};
|
||||
pub use old_iter::{BaseIter, ReverseIter, MutableIter, ExtendedIter, EqIter};
|
||||
pub use old_iter::{CopyableIter, CopyableOrderedIter, CopyableNonstrictIter};
|
||||
pub use old_iter::{ExtendedMutableIter};
|
||||
pub use iter::Times;
|
||||
pub use num::{Num, NumCast};
|
||||
pub use num::{Orderable, Signed, Unsigned, Integer};
|
||||
pub use num::{Round, Fractional, Real, RealExt};
|
||||
@ -79,6 +80,7 @@
|
||||
pub use int;
|
||||
pub use io;
|
||||
pub use iter;
|
||||
pub use old_iter;
|
||||
pub use libc;
|
||||
pub use num;
|
||||
pub use ops;
|
||||
|
@ -687,7 +687,7 @@ fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
|
||||
let ch = ch.clone();
|
||||
do spawn_unlinked {
|
||||
// Give middle task a chance to fail-but-not-kill-us.
|
||||
for iter::repeat(16) { task::yield(); }
|
||||
for old_iter::repeat(16) { task::yield(); }
|
||||
ch.send(()); // If killed first, grandparent hangs.
|
||||
}
|
||||
fail!(); // Shouldn't kill either (grand)parent or (grand)child.
|
||||
@ -702,7 +702,7 @@ fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
|
||||
fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
|
||||
do spawn_supervised { fail!(); }
|
||||
// Give child a chance to fail-but-not-kill-us.
|
||||
for iter::repeat(16) { task::yield(); }
|
||||
for old_iter::repeat(16) { task::yield(); }
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_spawn_unlinked_sup_fail_down() {
|
||||
@ -783,7 +783,7 @@ fn test_spawn_failure_propagate_grandchild() {
|
||||
loop { task::yield(); }
|
||||
}
|
||||
}
|
||||
for iter::repeat(16) { task::yield(); }
|
||||
for old_iter::repeat(16) { task::yield(); }
|
||||
fail!();
|
||||
}
|
||||
|
||||
@ -795,7 +795,7 @@ fn test_spawn_failure_propagate_secondborn() {
|
||||
loop { task::yield(); }
|
||||
}
|
||||
}
|
||||
for iter::repeat(16) { task::yield(); }
|
||||
for old_iter::repeat(16) { task::yield(); }
|
||||
fail!();
|
||||
}
|
||||
|
||||
@ -807,7 +807,7 @@ fn test_spawn_failure_propagate_nephew_or_niece() {
|
||||
loop { task::yield(); }
|
||||
}
|
||||
}
|
||||
for iter::repeat(16) { task::yield(); }
|
||||
for old_iter::repeat(16) { task::yield(); }
|
||||
fail!();
|
||||
}
|
||||
|
||||
@ -819,7 +819,7 @@ fn test_spawn_linked_sup_propagate_sibling() {
|
||||
loop { task::yield(); }
|
||||
}
|
||||
}
|
||||
for iter::repeat(16) { task::yield(); }
|
||||
for old_iter::repeat(16) { task::yield(); }
|
||||
fail!();
|
||||
}
|
||||
|
||||
@ -971,7 +971,7 @@ fn test_spawn_sched_blocking() {
|
||||
|
||||
// Testing that a task in one scheduler can block in foreign code
|
||||
// without affecting other schedulers
|
||||
for iter::repeat(20u) {
|
||||
for old_iter::repeat(20u) {
|
||||
|
||||
let (start_po, start_ch) = stream();
|
||||
let (fin_po, fin_ch) = stream();
|
||||
@ -1088,7 +1088,7 @@ fn test_unkillable() {
|
||||
|
||||
// We want to do this after failing
|
||||
do spawn_unlinked {
|
||||
for iter::repeat(10) { yield() }
|
||||
for old_iter::repeat(10) { yield() }
|
||||
ch.send(());
|
||||
}
|
||||
|
||||
@ -1123,7 +1123,7 @@ fn test_unkillable_nested() {
|
||||
|
||||
// We want to do this after failing
|
||||
do spawn_unlinked || {
|
||||
for iter::repeat(10) { yield() }
|
||||
for old_iter::repeat(10) { yield() }
|
||||
ch.send(());
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,8 @@
|
||||
use container::{Container, Mutable};
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
|
||||
use clone::Clone;
|
||||
use iter::BaseIter;
|
||||
use iter;
|
||||
use old_iter::BaseIter;
|
||||
use old_iter;
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
@ -142,7 +142,7 @@ pub fn uniq_len<T>(v: &const ~[T]) -> uint {
|
||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||
* to the value returned by the function `op`.
|
||||
*/
|
||||
pub fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
|
||||
pub fn from_fn<T>(n_elts: uint, op: old_iter::InitOp<T>) -> ~[T] {
|
||||
unsafe {
|
||||
let mut v = with_capacity(n_elts);
|
||||
do as_mut_buf(v) |p, _len| {
|
||||
@ -786,7 +786,7 @@ pub fn grow<T:Copy>(v: &mut ~[T], n: uint, initval: &T) {
|
||||
* * init_op - A function to call to retreive each appended element's
|
||||
* value
|
||||
*/
|
||||
pub fn grow_fn<T>(v: &mut ~[T], n: uint, op: iter::InitOp<T>) {
|
||||
pub fn grow_fn<T>(v: &mut ~[T], n: uint, op: old_iter::InitOp<T>) {
|
||||
let new_len = v.len() + n;
|
||||
reserve_at_least(&mut *v, new_len);
|
||||
let mut i: uint = 0u;
|
||||
@ -2265,7 +2265,7 @@ pub trait OwnedVector<T> {
|
||||
fn consume_reverse(self, f: &fn(uint, v: T));
|
||||
fn filter(self, f: &fn(t: &T) -> bool) -> ~[T];
|
||||
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
|
||||
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>);
|
||||
fn grow_fn(&mut self, n: uint, op: old_iter::InitOp<T>);
|
||||
}
|
||||
|
||||
impl<T> OwnedVector<T> for ~[T] {
|
||||
@ -2344,7 +2344,7 @@ fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]) {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>) {
|
||||
fn grow_fn(&mut self, n: uint, op: old_iter::InitOp<T>) {
|
||||
grow_fn(self, n, op);
|
||||
}
|
||||
}
|
||||
@ -2643,7 +2643,7 @@ pub fn copy_memory(dst: &mut [u8], src: &const [u8], count: uint) {
|
||||
// ITERATION TRAIT METHODS
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<'self,A> iter::BaseIter<A> for &'self [A] {
|
||||
impl<'self,A> old_iter::BaseIter<A> for &'self [A] {
|
||||
#[inline(always)]
|
||||
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
|
||||
#[inline(always)]
|
||||
@ -2653,7 +2653,7 @@ fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<'self,A> iter::BaseIter<A> for &'self [A] {
|
||||
impl<'self,A> old_iter::BaseIter<A> for &'self [A] {
|
||||
#[inline(always)]
|
||||
fn each<'a>(&'a self, blk: &fn(v: &'a A) -> bool) { each(*self, blk) }
|
||||
#[inline(always)]
|
||||
@ -2662,7 +2662,7 @@ fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
#[cfg(stage0)]
|
||||
impl<A> iter::BaseIter<A> for ~[A] {
|
||||
impl<A> old_iter::BaseIter<A> for ~[A] {
|
||||
#[inline(always)]
|
||||
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
|
||||
#[inline(always)]
|
||||
@ -2673,7 +2673,7 @@ fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<A> iter::BaseIter<A> for ~[A] {
|
||||
impl<A> old_iter::BaseIter<A> for ~[A] {
|
||||
#[inline(always)]
|
||||
fn each<'a>(&'a self, blk: &fn(v: &'a A) -> bool) { each(*self, blk) }
|
||||
#[inline(always)]
|
||||
@ -2682,7 +2682,7 @@ fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
#[cfg(stage0)]
|
||||
impl<A> iter::BaseIter<A> for @[A] {
|
||||
impl<A> old_iter::BaseIter<A> for @[A] {
|
||||
#[inline(always)]
|
||||
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
|
||||
#[inline(always)]
|
||||
@ -2693,7 +2693,7 @@ fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<A> iter::BaseIter<A> for @[A] {
|
||||
impl<A> old_iter::BaseIter<A> for @[A] {
|
||||
#[inline(always)]
|
||||
fn each<'a>(&'a self, blk: &fn(v: &'a A) -> bool) { each(*self, blk) }
|
||||
#[inline(always)]
|
||||
@ -2701,7 +2701,7 @@ fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<'self,A> iter::MutableIter<A> for &'self mut [A] {
|
||||
impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
|
||||
#[inline(always)]
|
||||
fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) {
|
||||
each_mut(*self, blk)
|
||||
@ -2711,7 +2711,7 @@ fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) {
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<'self,A> iter::MutableIter<A> for &'self mut [A] {
|
||||
impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
|
||||
#[inline(always)]
|
||||
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) {
|
||||
each_mut(*self, blk)
|
||||
@ -2720,7 +2720,7 @@ fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) {
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
#[cfg(stage0)]
|
||||
impl<A> iter::MutableIter<A> for ~[A] {
|
||||
impl<A> old_iter::MutableIter<A> for ~[A] {
|
||||
#[inline(always)]
|
||||
fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) {
|
||||
each_mut(*self, blk)
|
||||
@ -2730,7 +2730,7 @@ fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) {
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<A> iter::MutableIter<A> for ~[A] {
|
||||
impl<A> old_iter::MutableIter<A> for ~[A] {
|
||||
#[inline(always)]
|
||||
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) {
|
||||
each_mut(*self, blk)
|
||||
@ -2738,39 +2738,39 @@ fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) {
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A> iter::MutableIter<A> for @mut [A] {
|
||||
impl<A> old_iter::MutableIter<A> for @mut [A] {
|
||||
#[inline(always)]
|
||||
fn each_mut(&mut self, blk: &fn(v: &mut A) -> bool) {
|
||||
each_mut(*self, blk)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'self,A> iter::ExtendedIter<A> for &'self [A] {
|
||||
impl<'self,A> old_iter::ExtendedIter<A> for &'self [A] {
|
||||
pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
|
||||
iter::eachi(self, blk)
|
||||
old_iter::eachi(self, blk)
|
||||
}
|
||||
pub fn all(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::all(self, blk)
|
||||
old_iter::all(self, blk)
|
||||
}
|
||||
pub fn any(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::any(self, blk)
|
||||
old_iter::any(self, blk)
|
||||
}
|
||||
pub fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
|
||||
iter::foldl(self, b0, blk)
|
||||
old_iter::foldl(self, b0, blk)
|
||||
}
|
||||
pub fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
|
||||
iter::position(self, f)
|
||||
old_iter::position(self, f)
|
||||
}
|
||||
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
|
||||
iter::map_to_vec(self, op)
|
||||
old_iter::map_to_vec(self, op)
|
||||
}
|
||||
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
|
||||
-> ~[B] {
|
||||
iter::flat_map_to_vec(self, op)
|
||||
old_iter::flat_map_to_vec(self, op)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'self,A> iter::ExtendedMutableIter<A> for &'self mut [A] {
|
||||
impl<'self,A> old_iter::ExtendedMutableIter<A> for &'self mut [A] {
|
||||
#[inline(always)]
|
||||
pub fn eachi_mut(&mut self, blk: &fn(uint, v: &mut A) -> bool) {
|
||||
eachi_mut(*self, blk)
|
||||
@ -2778,124 +2778,124 @@ pub fn eachi_mut(&mut self, blk: &fn(uint, v: &mut A) -> bool) {
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A> iter::ExtendedIter<A> for ~[A] {
|
||||
impl<A> old_iter::ExtendedIter<A> for ~[A] {
|
||||
pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
|
||||
iter::eachi(self, blk)
|
||||
old_iter::eachi(self, blk)
|
||||
}
|
||||
pub fn all(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::all(self, blk)
|
||||
old_iter::all(self, blk)
|
||||
}
|
||||
pub fn any(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::any(self, blk)
|
||||
old_iter::any(self, blk)
|
||||
}
|
||||
pub fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
|
||||
iter::foldl(self, b0, blk)
|
||||
old_iter::foldl(self, b0, blk)
|
||||
}
|
||||
pub fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
|
||||
iter::position(self, f)
|
||||
old_iter::position(self, f)
|
||||
}
|
||||
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
|
||||
iter::map_to_vec(self, op)
|
||||
old_iter::map_to_vec(self, op)
|
||||
}
|
||||
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
|
||||
-> ~[B] {
|
||||
iter::flat_map_to_vec(self, op)
|
||||
old_iter::flat_map_to_vec(self, op)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A> iter::ExtendedIter<A> for @[A] {
|
||||
impl<A> old_iter::ExtendedIter<A> for @[A] {
|
||||
pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
|
||||
iter::eachi(self, blk)
|
||||
old_iter::eachi(self, blk)
|
||||
}
|
||||
pub fn all(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::all(self, blk)
|
||||
old_iter::all(self, blk)
|
||||
}
|
||||
pub fn any(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::any(self, blk)
|
||||
old_iter::any(self, blk)
|
||||
}
|
||||
pub fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
|
||||
iter::foldl(self, b0, blk)
|
||||
old_iter::foldl(self, b0, blk)
|
||||
}
|
||||
pub fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
|
||||
iter::position(self, f)
|
||||
old_iter::position(self, f)
|
||||
}
|
||||
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
|
||||
iter::map_to_vec(self, op)
|
||||
old_iter::map_to_vec(self, op)
|
||||
}
|
||||
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
|
||||
-> ~[B] {
|
||||
iter::flat_map_to_vec(self, op)
|
||||
old_iter::flat_map_to_vec(self, op)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'self,A:Eq> iter::EqIter<A> for &'self [A] {
|
||||
pub fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
||||
pub fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
||||
impl<'self,A:Eq> old_iter::EqIter<A> for &'self [A] {
|
||||
pub fn contains(&self, x: &A) -> bool { old_iter::contains(self, x) }
|
||||
pub fn count(&self, x: &A) -> uint { old_iter::count(self, x) }
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A:Eq> iter::EqIter<A> for ~[A] {
|
||||
pub fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
||||
pub fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
||||
impl<A:Eq> old_iter::EqIter<A> for ~[A] {
|
||||
pub fn contains(&self, x: &A) -> bool { old_iter::contains(self, x) }
|
||||
pub fn count(&self, x: &A) -> uint { old_iter::count(self, x) }
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A:Eq> iter::EqIter<A> for @[A] {
|
||||
pub fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
||||
pub fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
||||
impl<A:Eq> old_iter::EqIter<A> for @[A] {
|
||||
pub fn contains(&self, x: &A) -> bool { old_iter::contains(self, x) }
|
||||
pub fn count(&self, x: &A) -> uint { old_iter::count(self, x) }
|
||||
}
|
||||
|
||||
impl<'self,A:Copy> iter::CopyableIter<A> for &'self [A] {
|
||||
impl<'self,A:Copy> old_iter::CopyableIter<A> for &'self [A] {
|
||||
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
|
||||
iter::filter_to_vec(self, pred)
|
||||
old_iter::filter_to_vec(self, pred)
|
||||
}
|
||||
fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
|
||||
fn to_vec(&self) -> ~[A] { old_iter::to_vec(self) }
|
||||
pub fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
|
||||
iter::find(self, f)
|
||||
old_iter::find(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A:Copy> iter::CopyableIter<A> for ~[A] {
|
||||
impl<A:Copy> old_iter::CopyableIter<A> for ~[A] {
|
||||
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
|
||||
iter::filter_to_vec(self, pred)
|
||||
old_iter::filter_to_vec(self, pred)
|
||||
}
|
||||
fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
|
||||
fn to_vec(&self) -> ~[A] { old_iter::to_vec(self) }
|
||||
pub fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
|
||||
iter::find(self, f)
|
||||
old_iter::find(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A:Copy> iter::CopyableIter<A> for @[A] {
|
||||
impl<A:Copy> old_iter::CopyableIter<A> for @[A] {
|
||||
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
|
||||
iter::filter_to_vec(self, pred)
|
||||
old_iter::filter_to_vec(self, pred)
|
||||
}
|
||||
fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
|
||||
fn to_vec(&self) -> ~[A] { old_iter::to_vec(self) }
|
||||
pub fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
|
||||
iter::find(self, f)
|
||||
old_iter::find(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'self,A:Copy + Ord> iter::CopyableOrderedIter<A> for &'self [A] {
|
||||
fn min(&self) -> A { iter::min(self) }
|
||||
fn max(&self) -> A { iter::max(self) }
|
||||
impl<'self,A:Copy + Ord> old_iter::CopyableOrderedIter<A> for &'self [A] {
|
||||
fn min(&self) -> A { old_iter::min(self) }
|
||||
fn max(&self) -> A { old_iter::max(self) }
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for ~[A] {
|
||||
fn min(&self) -> A { iter::min(self) }
|
||||
fn max(&self) -> A { iter::max(self) }
|
||||
impl<A:Copy + Ord> old_iter::CopyableOrderedIter<A> for ~[A] {
|
||||
fn min(&self) -> A { old_iter::min(self) }
|
||||
fn max(&self) -> A { old_iter::max(self) }
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for @[A] {
|
||||
fn min(&self) -> A { iter::min(self) }
|
||||
fn max(&self) -> A { iter::max(self) }
|
||||
impl<A:Copy + Ord> old_iter::CopyableOrderedIter<A> for @[A] {
|
||||
fn min(&self) -> A { old_iter::min(self) }
|
||||
fn max(&self) -> A { old_iter::max(self) }
|
||||
}
|
||||
|
||||
impl<'self,A:Copy> iter::CopyableNonstrictIter<A> for &'self [A] {
|
||||
impl<'self,A:Copy> old_iter::CopyableNonstrictIter<A> for &'self [A] {
|
||||
fn each_val(&const self, f: &fn(A) -> bool) {
|
||||
let mut i = 0;
|
||||
while i < self.len() {
|
||||
@ -2906,7 +2906,7 @@ fn each_val(&const self, f: &fn(A) -> bool) {
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A:Copy> iter::CopyableNonstrictIter<A> for ~[A] {
|
||||
impl<A:Copy> old_iter::CopyableNonstrictIter<A> for ~[A] {
|
||||
fn each_val(&const self, f: &fn(A) -> bool) {
|
||||
let mut i = 0;
|
||||
while i < uniq_len(self) {
|
||||
@ -2917,7 +2917,7 @@ fn each_val(&const self, f: &fn(A) -> bool) {
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
|
||||
impl<A:Copy> old_iter::CopyableNonstrictIter<A> for @[A] {
|
||||
fn each_val(&const self, f: &fn(A) -> bool) {
|
||||
let mut i = 0;
|
||||
while i < self.len() {
|
||||
|
@ -1071,7 +1071,7 @@ fn propagate_through_exprs(&self, exprs: &[@expr],
|
||||
|
||||
fn propagate_through_opt_expr(&self, opt_expr: Option<@expr>,
|
||||
succ: LiveNode) -> LiveNode {
|
||||
do iter::foldl(&opt_expr, succ) |succ, expr| {
|
||||
do old_iter::foldl(&opt_expr, succ) |succ, expr| {
|
||||
self.propagate_through_expr(*expr, *succ)
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ fn check_coherence(self, crate: @crate) {
|
||||
match item.node {
|
||||
item_impl(_, opt_trait, _, _) => {
|
||||
self.check_implementation(item,
|
||||
iter::to_vec(&opt_trait));
|
||||
old_iter::to_vec(&opt_trait));
|
||||
}
|
||||
_ => {
|
||||
// Nothing to do.
|
||||
|
@ -629,7 +629,7 @@ fn should_request_new_writer_for_each_page() {
|
||||
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
|
||||
write_markdown(doc, writer_factory);
|
||||
// We expect two pages to have been written
|
||||
for iter::repeat(2) {
|
||||
for old_iter::repeat(2) {
|
||||
po.recv();
|
||||
}
|
||||
}
|
||||
@ -641,7 +641,7 @@ fn should_write_title_for_each_page() {
|
||||
~"#[link(name = \"core\")]; mod a { }");
|
||||
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
|
||||
write_markdown(doc, writer_factory);
|
||||
for iter::repeat(2) {
|
||||
for old_iter::repeat(2) {
|
||||
let (page, markdown) = po.recv();
|
||||
match page {
|
||||
doc::CratePage(_) => {
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
//! Base64 binary-to-text encoding
|
||||
|
||||
use core::iter;
|
||||
use core::old_iter;
|
||||
use core::str;
|
||||
use core::vec;
|
||||
|
||||
@ -152,7 +152,7 @@ fn from_base64(&self) -> ~[u8] {
|
||||
while i < len {
|
||||
let mut n = 0u;
|
||||
|
||||
for iter::repeat(4u) {
|
||||
for old_iter::repeat(4u) {
|
||||
let ch = self[i] as char;
|
||||
n <<= 6u;
|
||||
|
||||
|
@ -483,7 +483,7 @@ fn tail(@mut self) -> T { self.tail_n().data }
|
||||
/// Get the elements of the list as a vector. O(n).
|
||||
fn to_vec(@mut self) -> ~[T] {
|
||||
let mut v = vec::with_capacity(self.size);
|
||||
for iter::eachi(&self) |index,data| {
|
||||
for old_iter::eachi(&self) |index,data| {
|
||||
v[index] = *data;
|
||||
}
|
||||
v
|
||||
@ -750,7 +750,7 @@ fn test_dlist_push_head() {
|
||||
#[test]
|
||||
fn test_dlist_foldl() {
|
||||
let l = from_vec(vec::from_fn(101, |x|x));
|
||||
assert_eq!(iter::foldl(&l, 0, |accum,elem| *accum+*elem), 5050);
|
||||
assert_eq!(old_iter::foldl(&l, 0, |accum,elem| *accum+*elem), 5050);
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_break_early() {
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
//! A priority queue implemented with a binary heap
|
||||
|
||||
use core::iter::BaseIter;
|
||||
use core::old_iter::BaseIter;
|
||||
use core::ptr::addr_of;
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
use core::container::{Container, Mutable, Map, Set};
|
||||
use core::iter::{BaseIter};
|
||||
use core::old_iter::{BaseIter};
|
||||
use core::option::{Some, None};
|
||||
|
||||
pub struct SmallIntMap<T> {
|
||||
|
@ -183,7 +183,7 @@ fn test_gl_timer_simple_sleep_test() {
|
||||
#[test]
|
||||
fn test_gl_timer_sleep_stress1() {
|
||||
let hl_loop = &uv::global_loop::get();
|
||||
for iter::repeat(50u) {
|
||||
for old_iter::repeat(50u) {
|
||||
sleep(hl_loop, 1u);
|
||||
}
|
||||
}
|
||||
@ -203,7 +203,7 @@ fn test_gl_timer_sleep_stress2() {
|
||||
|
||||
};
|
||||
|
||||
for iter::repeat(repeat) {
|
||||
for old_iter::repeat(repeat) {
|
||||
|
||||
let ch = ch.clone();
|
||||
for spec.each |spec| {
|
||||
@ -213,7 +213,7 @@ fn test_gl_timer_sleep_stress2() {
|
||||
do task::spawn {
|
||||
use core::rand::*;
|
||||
let rng = rng();
|
||||
for iter::repeat(times) {
|
||||
for old_iter::repeat(times) {
|
||||
sleep(&hl_loop_clone, rng.next() as uint % maxms);
|
||||
}
|
||||
ch.send(());
|
||||
@ -221,7 +221,7 @@ fn test_gl_timer_sleep_stress2() {
|
||||
}
|
||||
}
|
||||
|
||||
for iter::repeat(repeat * spec.len()) {
|
||||
for old_iter::repeat(repeat * spec.len()) {
|
||||
po.recv()
|
||||
}
|
||||
}
|
||||
@ -239,7 +239,7 @@ fn test_gl_timer_recv_timeout_before_time_passes() {
|
||||
let mut failures = 0;
|
||||
let hl_loop = uv::global_loop::get();
|
||||
|
||||
for iter::repeat(times as uint) {
|
||||
for old_iter::repeat(times as uint) {
|
||||
task::yield();
|
||||
|
||||
let expected = rand::rng().gen_str(16u);
|
||||
@ -268,7 +268,7 @@ fn test_gl_timer_recv_timeout_after_time_passes() {
|
||||
let mut failures = 0;
|
||||
let hl_loop = uv::global_loop::get();
|
||||
|
||||
for iter::repeat(times as uint) {
|
||||
for old_iter::repeat(times as uint) {
|
||||
let expected = rand::rng().gen_str(16u);
|
||||
let (test_po, test_ch) = stream::<~str>();
|
||||
let hl_loop_clone = hl_loop.clone();
|
||||
|
@ -119,7 +119,7 @@ mod test {
|
||||
use uv::ll;
|
||||
use uv_iotask::IoTask;
|
||||
|
||||
use core::iter;
|
||||
use core::old_iter;
|
||||
use core::libc;
|
||||
use core::ptr;
|
||||
use core::task;
|
||||
@ -210,7 +210,7 @@ fn test_stress_gl_uv_global_loop_high_level_global_timer() {
|
||||
let (exit_po, exit_ch) = stream::<()>();
|
||||
let exit_ch = SharedChan::new(exit_ch);
|
||||
let cycles = 5000u;
|
||||
for iter::repeat(cycles) {
|
||||
for old_iter::repeat(cycles) {
|
||||
let exit_ch_clone = exit_ch.clone();
|
||||
task::spawn_sched(task::ManualThreads(1u), || {
|
||||
let hl_loop = &get_gl();
|
||||
@ -218,7 +218,7 @@ fn test_stress_gl_uv_global_loop_high_level_global_timer() {
|
||||
exit_ch_clone.send(());
|
||||
});
|
||||
};
|
||||
for iter::repeat(cycles) {
|
||||
for old_iter::repeat(cycles) {
|
||||
exit_po.recv();
|
||||
};
|
||||
debug!(~"test_stress_gl_uv_global_loop_high_level_global_timer"+
|
||||
|
@ -285,7 +285,7 @@ fn test_uv_iotask_async() {
|
||||
// impl_uv_hl_async() runs have been called, at least.
|
||||
let (work_exit_po, work_exit_ch) = stream::<()>();
|
||||
let work_exit_ch = SharedChan::new(work_exit_ch);
|
||||
for iter::repeat(7u) {
|
||||
for old_iter::repeat(7u) {
|
||||
let iotask_clone = iotask.clone();
|
||||
let work_exit_ch_clone = work_exit_ch.clone();
|
||||
do task::spawn_sched(task::ManualThreads(1u)) {
|
||||
@ -295,7 +295,7 @@ fn test_uv_iotask_async() {
|
||||
work_exit_ch_clone.send(());
|
||||
};
|
||||
};
|
||||
for iter::repeat(7u) {
|
||||
for old_iter::repeat(7u) {
|
||||
debug!("waiting");
|
||||
work_exit_po.recv();
|
||||
};
|
||||
|
@ -16,8 +16,9 @@
|
||||
* other useful things like `push()` and `len()`.
|
||||
*/
|
||||
|
||||
use core::iter;
|
||||
use core::iter::BaseIter;
|
||||
use core::prelude::*;
|
||||
use core::old_iter;
|
||||
use core::old_iter::BaseIter;
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
@ -116,7 +117,7 @@ fn push_all<I: BaseIter<T>>(&mut self, from: &I) {
|
||||
#[inline(always)]
|
||||
fn mapi_to_vec<B>(&self, op: &fn(uint, &T) -> B) -> ~[B] {
|
||||
let mut index = 0;
|
||||
iter::map_to_vec(self, |a| {
|
||||
old_iter::map_to_vec(self, |a| {
|
||||
let i = index;
|
||||
index += 1;
|
||||
op(i, a)
|
||||
@ -154,62 +155,62 @@ fn size_hint(&self) -> Option<uint> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> iter::ExtendedIter<A> for OptVec<A> {
|
||||
impl<A> old_iter::ExtendedIter<A> for OptVec<A> {
|
||||
#[inline(always)]
|
||||
fn eachi(&self, blk: &fn(v: uint, v: &A) -> bool) {
|
||||
iter::eachi(self, blk)
|
||||
old_iter::eachi(self, blk)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn all(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::all(self, blk)
|
||||
old_iter::all(self, blk)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn any(&self, blk: &fn(&A) -> bool) -> bool {
|
||||
iter::any(self, blk)
|
||||
old_iter::any(self, blk)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
|
||||
iter::foldl(self, b0, blk)
|
||||
old_iter::foldl(self, b0, blk)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
|
||||
iter::position(self, f)
|
||||
old_iter::position(self, f)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
|
||||
iter::map_to_vec(self, op)
|
||||
old_iter::map_to_vec(self, op)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
|
||||
-> ~[B] {
|
||||
iter::flat_map_to_vec(self, op)
|
||||
old_iter::flat_map_to_vec(self, op)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<A: Eq> iter::EqIter<A> for OptVec<A> {
|
||||
impl<A: Eq> old_iter::EqIter<A> for OptVec<A> {
|
||||
#[inline(always)]
|
||||
fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
|
||||
fn contains(&self, x: &A) -> bool { old_iter::contains(self, x) }
|
||||
#[inline(always)]
|
||||
fn count(&self, x: &A) -> uint { iter::count(self, x) }
|
||||
fn count(&self, x: &A) -> uint { old_iter::count(self, x) }
|
||||
}
|
||||
|
||||
impl<A: Copy> iter::CopyableIter<A> for OptVec<A> {
|
||||
impl<A: Copy> old_iter::CopyableIter<A> for OptVec<A> {
|
||||
#[inline(always)]
|
||||
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
|
||||
iter::filter_to_vec(self, pred)
|
||||
old_iter::filter_to_vec(self, pred)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
|
||||
fn to_vec(&self) -> ~[A] { old_iter::to_vec(self) }
|
||||
#[inline(always)]
|
||||
fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
|
||||
iter::find(self, f)
|
||||
old_iter::find(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Copy+Ord> iter::CopyableOrderedIter<A> for OptVec<A> {
|
||||
impl<A: Copy+Ord> old_iter::CopyableOrderedIter<A> for OptVec<A> {
|
||||
#[inline(always)]
|
||||
fn min(&self) -> A { iter::min(self) }
|
||||
fn min(&self) -> A { old_iter::min(self) }
|
||||
#[inline(always)]
|
||||
fn max(&self) -> A { iter::max(self) }
|
||||
fn max(&self) -> A { old_iter::max(self) }
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn run(repeat: int, depth: int) {
|
||||
for iter::repeat(repeat as uint) {
|
||||
for old_iter::repeat(repeat as uint) {
|
||||
debug!("starting %.4f", precise_time_s());
|
||||
do task::try {
|
||||
recurse_or_fail(depth, None)
|
||||
|
@ -12,6 +12,8 @@
|
||||
// Testing that runtime failure doesn't cause callbacks to abort abnormally.
|
||||
// Instead the failure will be delivered after the callbacks return.
|
||||
|
||||
use core::old_iter;
|
||||
|
||||
mod rustrt {
|
||||
pub extern {
|
||||
pub fn rust_dbg_call(cb: *u8, data: libc::uintptr_t)
|
||||
@ -35,7 +37,7 @@ fn count(n: uint) -> uint {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for iter::repeat(10u) {
|
||||
for old_iter::repeat(10u) {
|
||||
do task::spawn {
|
||||
let result = count(5u);
|
||||
debug!("result = %?", result);
|
||||
|
@ -21,5 +21,5 @@ fn bitv_test() -> bool {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
do iter::repeat(10000) || {bitv_test()};
|
||||
do old_iter::repeat(10000) || {bitv_test()};
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
// xfail-fast
|
||||
|
||||
use core::container::{Container, Mutable, Map};
|
||||
use core::iter::BaseIter;
|
||||
use core::old_iter::BaseIter;
|
||||
|
||||
enum cat_type { tuxedo, tabby, tortoiseshell }
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
use std::oldmap::{map, hashmap, int_hash};
|
||||
|
||||
class keys<K:Copy,V:Copy,M:Copy + map<K,V>>
|
||||
: iter::base_iter<K> {
|
||||
: old_iter::base_iter<K> {
|
||||
|
||||
let map: M;
|
||||
|
||||
@ -24,12 +24,12 @@
|
||||
|
||||
fn each(blk: &fn(K) -> bool) { self.map.each(|k, _v| blk(k) ) }
|
||||
fn size_hint() -> Option<uint> { Some(self.map.size()) }
|
||||
fn eachi(blk: &fn(uint, K) -> bool) { iter::eachi(self, blk) }
|
||||
fn eachi(blk: &fn(uint, K) -> bool) { old_iter::eachi(self, blk) }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let m = int_hash();
|
||||
m.insert(1, 2);
|
||||
m.insert(3, 4);
|
||||
assert!(iter::to_vec(keys(m)) == ~[1, 3]);
|
||||
assert!(old_iter::to_vec(keys(m)) == ~[1, 3]);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ struct A { a: int }
|
||||
|
||||
pub fn main() {
|
||||
|
||||
for iter::eachi(&(Some(A {a: 0}))) |i, a| {
|
||||
for old_iter::eachi(&(Some(A {a: 0}))) |i, a| {
|
||||
debug!("%u %d", i, a.a);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ fn count(n: uint) -> uint {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
for iter::repeat(100u) {
|
||||
for old_iter::repeat(100u) {
|
||||
do task::spawn {
|
||||
assert!(count(5u) == 16u);
|
||||
};
|
||||
|
@ -31,7 +31,7 @@ fn count(n: uint) -> uint {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
for iter::repeat(10u) {
|
||||
for old_iter::repeat(10u) {
|
||||
do task::spawn {
|
||||
let result = count(5u);
|
||||
debug!("result = %?", result);
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use core::iter::BaseIter;
|
||||
use core::old_iter::BaseIter;
|
||||
|
||||
trait FlatMapToVec<A> {
|
||||
fn flat_map_to_vec<B, IB:BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B];
|
||||
@ -16,7 +16,7 @@ trait FlatMapToVec<A> {
|
||||
|
||||
impl<A:Copy> FlatMapToVec<A> for ~[A] {
|
||||
fn flat_map_to_vec<B, IB:BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B] {
|
||||
iter::flat_map_to_vec(self, op)
|
||||
old_iter::flat_map_to_vec(self, op)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ pub fn main() {
|
||||
assert!([2u, 4u].all(is_even));
|
||||
assert!([].all(is_even));
|
||||
|
||||
assert!(!iter::all(&Some(1u), is_even));
|
||||
assert!(iter::all(&Some(2u), is_even));
|
||||
assert!(iter::all(&None::<uint>, is_even));
|
||||
assert!(!old_iter::all(&Some(1u), is_even));
|
||||
assert!(old_iter::all(&Some(2u), is_even));
|
||||
assert!(old_iter::all(&None::<uint>, is_even));
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ pub fn main() {
|
||||
assert!([1u, 2u].any(is_even));
|
||||
assert!(![].any(is_even));
|
||||
|
||||
assert!(!iter::any(&Some(1u), is_even));
|
||||
assert!(iter::any(&Some(2u), is_even));
|
||||
assert!(!iter::any(&None::<uint>, is_even));
|
||||
assert!(!old_iter::any(&Some(1u), is_even));
|
||||
assert!(old_iter::any(&Some(2u), is_even));
|
||||
assert!(!old_iter::any(&None::<uint>, is_even));
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ pub fn main() {
|
||||
assert!([22u, 1u, 3u].contains(&22u) == true);
|
||||
assert!([1u, 22u, 3u].contains(&22u) == true);
|
||||
assert!([1u, 3u, 22u].contains(&22u) == true);
|
||||
assert!(iter::contains(&None::<uint>, &22u) == false);
|
||||
assert!(iter::contains(&Some(1u), &22u) == false);
|
||||
assert!(iter::contains(&Some(22u), &22u) == true);
|
||||
assert!(old_iter::contains(&None::<uint>, &22u) == false);
|
||||
assert!(old_iter::contains(&Some(1u), &22u) == false);
|
||||
assert!(old_iter::contains(&Some(22u), &22u) == true);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ pub fn main() {
|
||||
assert!([1u, 3u].count(&22u) == 0u);
|
||||
assert!([22u, 1u, 3u].count(&22u) == 1u);
|
||||
assert!([22u, 1u, 22u].count(&22u) == 2u);
|
||||
assert!(iter::count(&None::<uint>, &22u) == 0u);
|
||||
assert!(iter::count(&Some(1u), &22u) == 0u);
|
||||
assert!(iter::count(&Some(22u), &22u) == 1u);
|
||||
assert!(old_iter::count(&None::<uint>, &22u) == 0u);
|
||||
assert!(old_iter::count(&Some(1u), &22u) == 0u);
|
||||
assert!(old_iter::count(&Some(22u), &22u) == 1u);
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ pub fn main() {
|
||||
}
|
||||
assert!(c == 5u);
|
||||
|
||||
for iter::eachi(&None::<uint>) |i, v| { fail!(); }
|
||||
for old_iter::eachi(&None::<uint>) |i, v| { fail!(); }
|
||||
|
||||
let mut c = 0u;
|
||||
for iter::eachi(&Some(1u)) |i, v| {
|
||||
for old_iter::eachi(&Some(1u)) |i, v| {
|
||||
assert!((i + 1u) == *v);
|
||||
c += 1u;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ fn is_even(x: &uint) -> bool { (*x % 2) == 0 }
|
||||
pub fn main() {
|
||||
assert!([1, 3].filter_to_vec(is_even) == ~[]);
|
||||
assert!([1, 2, 3].filter_to_vec(is_even) == ~[2]);
|
||||
assert!(iter::filter_to_vec(&None::<uint>, is_even) == ~[]);
|
||||
assert!(iter::filter_to_vec(&Some(1u), is_even) == ~[]);
|
||||
assert!(iter::filter_to_vec(&Some(2u), is_even) == ~[2]);
|
||||
assert!(old_iter::filter_to_vec(&None::<uint>, is_even) == ~[]);
|
||||
assert!(old_iter::filter_to_vec(&Some(1u), is_even) == ~[]);
|
||||
assert!(old_iter::filter_to_vec(&Some(2u), is_even) == ~[2]);
|
||||
}
|
||||
|
@ -17,13 +17,13 @@ fn incd_if_even(x: &uint) -> Option<uint> {
|
||||
pub fn main() {
|
||||
assert!((~[1u, 3u]).flat_map_to_vec(repeat) == ~[1u, 1u, 3u, 3u]);
|
||||
assert!((~[]).flat_map_to_vec(repeat) == ~[]);
|
||||
assert!(iter::flat_map_to_vec(&None::<uint>, repeat) == ~[]);
|
||||
assert!(iter::flat_map_to_vec(&Some(1u), repeat) == ~[1u, 1u]);
|
||||
assert!(iter::flat_map_to_vec(&Some(2u), repeat) == ~[2u, 2u]);
|
||||
assert!(old_iter::flat_map_to_vec(&None::<uint>, repeat) == ~[]);
|
||||
assert!(old_iter::flat_map_to_vec(&Some(1u), repeat) == ~[1u, 1u]);
|
||||
assert!(old_iter::flat_map_to_vec(&Some(2u), repeat) == ~[2u, 2u]);
|
||||
|
||||
assert!((~[1u, 2u, 5u]).flat_map_to_vec(incd_if_even) == ~[3u]);
|
||||
assert!((~[]).flat_map_to_vec(incd_if_even) == ~[]);
|
||||
assert!(iter::flat_map_to_vec(&None::<uint>, incd_if_even) == ~[]);
|
||||
assert!(iter::flat_map_to_vec(&Some(1u), incd_if_even) == ~[]);
|
||||
assert!(iter::flat_map_to_vec(&Some(2u), incd_if_even) == ~[3u]);
|
||||
assert!(old_iter::flat_map_to_vec(&None::<uint>, incd_if_even) == ~[]);
|
||||
assert!(old_iter::flat_map_to_vec(&Some(1u), incd_if_even) == ~[]);
|
||||
assert!(old_iter::flat_map_to_vec(&Some(2u), incd_if_even) == ~[3u]);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ fn add(x: &float, y: &uint) -> float { *x + ((*y) as float) }
|
||||
pub fn main() {
|
||||
assert!([1u, 3u].foldl(20f, add) == 24f);
|
||||
assert!([].foldl(20f, add) == 20f);
|
||||
assert!(iter::foldl(&None::<uint>, 20f, add) == 20f);
|
||||
assert!(iter::foldl(&Some(1u), 20f, add) == 21f);
|
||||
assert!(iter::foldl(&Some(2u), 20f, add) == 22f);
|
||||
assert!(old_iter::foldl(&None::<uint>, 20f, add) == 20f);
|
||||
assert!(old_iter::foldl(&Some(1u), 20f, add) == 21f);
|
||||
assert!(old_iter::foldl(&Some(2u), 20f, add) == 22f);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ fn inc(x: &uint) -> uint { *x + 1 }
|
||||
pub fn main() {
|
||||
assert!([1, 3].map_to_vec(inc) == ~[2, 4]);
|
||||
assert!([1, 2, 3].map_to_vec(inc) == ~[2, 3, 4]);
|
||||
assert!(iter::map_to_vec(&None::<uint>, inc) == ~[]);
|
||||
assert!(iter::map_to_vec(&Some(1u), inc) == ~[2]);
|
||||
assert!(iter::map_to_vec(&Some(2u), inc) == ~[3]);
|
||||
assert!(old_iter::map_to_vec(&None::<uint>, inc) == ~[]);
|
||||
assert!(old_iter::map_to_vec(&Some(1u), inc) == ~[2]);
|
||||
assert!(old_iter::map_to_vec(&Some(2u), inc) == ~[3]);
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ fn is_even(&&x: uint) -> bool { (x % 2u) == 0u }
|
||||
pub fn main() {
|
||||
assert!([1u, 3u].min() == 1u);
|
||||
assert!([3u, 1u].min() == 1u);
|
||||
assert!(iter::min(&Some(1u)) == 1u);
|
||||
assert!(old_iter::min(&Some(1u)) == 1u);
|
||||
|
||||
assert!([1u, 3u].max() == 3u);
|
||||
assert!([3u, 1u].max() == 3u);
|
||||
assert!(iter::max(&Some(3u)) == 3u);
|
||||
assert!(old_iter::max(&Some(3u)) == 3u);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ pub fn main() {
|
||||
assert!([1u, 3u].to_vec() == ~[1u, 3u]);
|
||||
let e: ~[uint] = ~[];
|
||||
assert!(e.to_vec() == ~[]);
|
||||
assert!(iter::to_vec(&None::<uint>) == ~[]);
|
||||
assert!(iter::to_vec(&Some(1u)) == ~[1u]);
|
||||
assert!(iter::to_vec(&Some(2u)) == ~[2u]);
|
||||
assert!(old_iter::to_vec(&None::<uint>) == ~[]);
|
||||
assert!(old_iter::to_vec(&Some(1u)) == ~[1u]);
|
||||
assert!(old_iter::to_vec(&Some(2u)) == ~[2u]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user