remove old_iter

the `test/run-pass/class-trait-bounded-param.rs` test was xfailed and
written in an ancient dialect of Rust so I've just removed it

this also removes `to_vec` from DList because it's provided by
`std::iter::to_vec`

an Iterator implementation is added for OptVec but some transitional
internal iterator methods are still left
This commit is contained in:
Daniel Micay 2013-06-23 17:57:39 -04:00
parent ac4211ef52
commit e2e39234cc
22 changed files with 122 additions and 551 deletions

View File

@ -666,12 +666,8 @@ impl BitvSet {
pub fn symmetric_difference_with(&mut self, other: &BitvSet) {
self.other_op(other, |w1, w2| w1 ^ w2);
}
}
impl BaseIter<uint> for BitvSet {
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn each(&self, blk: &fn(v: &uint) -> bool) -> bool {
pub fn each(&self, blk: &fn(v: &uint) -> bool) -> bool {
for self.bitv.storage.iter().enumerate().advance |(i, &w)| {
if !iterate_bits(i * uint::bits, w, |b| blk(&b)) {
return false;

View File

@ -21,8 +21,6 @@ Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate.
use core::prelude::*;
use core::managed;
use core::old_iter;
use core::vec;
pub type DListLink<T> = Option<@mut DListNode<T>>;
@ -213,6 +211,42 @@ impl<T> DList<T> {
}
impl<T> DList<T> {
/**
* Iterates through the current contents.
*
* Attempts to access this dlist during iteration are allowed (to
* allow for e.g. breadth-first search with in-place enqueues), but
* removing the current node is forbidden.
*/
pub fn each(@mut self, f: &fn(v: &T) -> bool) -> bool {
let mut link = self.peek_n();
while link.is_some() {
let nobe = link.get();
assert!(nobe.linked);
{
let frozen_nobe = &*nobe;
if !f(&frozen_nobe.data) { return false; }
}
// Check (weakly) that the user didn't do a remove.
if self.size == 0 {
fail!("The dlist became empty during iteration??")
}
if !nobe.linked ||
(!((nobe.prev.is_some()
|| managed::mut_ptr_eq(self.hd.expect("headless dlist?"),
nobe))
&& (nobe.next.is_some()
|| managed::mut_ptr_eq(self.tl.expect("tailless dlist?"),
nobe)))) {
fail!("Removing a dlist node during iteration is forbidden!")
}
link = nobe.next_link();
}
return true;
}
/// Get the size of the list. O(1).
pub fn len(@mut self) -> uint { self.size }
/// Returns true if the list is empty. O(1).
@ -484,56 +518,6 @@ impl<T:Copy> DList<T> {
/// Get data at the list's tail, failing if empty. O(1).
pub fn tail(@mut self) -> T { copy self.tail_n().data }
/// Get the elements of the list as a vector. O(n).
pub fn to_vec(@mut self) -> ~[T] {
let mut v = vec::with_capacity(self.size);
for old_iter::eachi(&self) |index,data| {
v[index] = copy *data;
}
v
}
}
impl<T> BaseIter<T> for @mut DList<T> {
/**
* Iterates through the current contents.
*
* Attempts to access this dlist during iteration are allowed (to
* allow for e.g. breadth-first search with in-place enqueues), but
* removing the current node is forbidden.
*/
fn each(&self, f: &fn(v: &T) -> bool) -> bool {
let mut link = self.peek_n();
while link.is_some() {
let nobe = link.get();
assert!(nobe.linked);
{
let frozen_nobe = &*nobe;
if !f(&frozen_nobe.data) { return false; }
}
// Check (weakly) that the user didn't do a remove.
if self.size == 0 {
fail!("The dlist became empty during iteration??")
}
if !nobe.linked ||
(!((nobe.prev.is_some()
|| managed::mut_ptr_eq(self.hd.expect("headless dlist?"),
nobe))
&& (nobe.next.is_some()
|| managed::mut_ptr_eq(self.tl.expect("tailless dlist?"),
nobe)))) {
fail!("Removing a dlist node during iteration is forbidden!")
}
link = nobe.next_link();
}
return true;
}
#[inline]
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
#[cfg(test)]
@ -542,7 +526,6 @@ mod tests {
use super::*;
use core::old_iter;
use core::vec;
#[test]
@ -759,11 +742,6 @@ mod tests {
assert_eq!(l.len(), 3);
}
#[test]
fn test_dlist_foldl() {
let l = from_vec(vec::from_fn(101, |x|x));
assert_eq!(old_iter::foldl(&l, 0, |accum,elem| *accum+*elem), 5050);
}
#[test]
fn test_dlist_break_early() {
let l = from_vec([1,2,3,4,5]);
let mut x = 0;

View File

@ -14,25 +14,15 @@
use core::prelude::*;
use core::old_iter::BaseIter;
use core::unstable::intrinsics::{move_val_init, init};
use core::util::{replace, swap};
use core::vec;
#[allow(missing_doc)]
/// A priority queue implemented with a binary heap
pub struct PriorityQueue<T> {
priv data: ~[T],
}
impl<T:Ord> BaseIter<T> for PriorityQueue<T> {
/// Visit all values in the underlying vector.
///
/// The values are **not** visited in order.
fn each(&self, f: &fn(&T) -> bool) -> bool { self.data.iter().advance(f) }
fn size_hint(&self) -> Option<uint> { Some(self.data.len()) }
}
impl<T:Ord> Container for PriorityQueue<T> {
/// Returns the length of the queue
fn len(&self) -> uint { self.data.len() }
@ -47,6 +37,11 @@ impl<T:Ord> Mutable for PriorityQueue<T> {
}
impl<T:Ord> PriorityQueue<T> {
/// Visit all values in the underlying vector.
///
/// The values are **not** visited in order.
pub fn each(&self, f: &fn(&T) -> bool) -> bool { self.data.iter().advance(f) }
/// Returns the greatest item in the queue - fails if empty
pub fn top<'a>(&'a self) -> &'a T { &self.data[0] }

View File

@ -19,8 +19,6 @@ use core::prelude::*;
use core::cmp;
use core::container::{Container, Mutable, Map, Set};
use core::old_iter::BaseIter;
use core::old_iter;
use core::uint;
use core::util::replace;
use core::vec;
@ -212,12 +210,6 @@ impl Mutable for SmallIntSet {
fn clear(&mut self) { self.map.clear() }
}
impl BaseIter<uint> for SmallIntSet {
/// Visit all values in order
fn each(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key(f) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl Set<uint> for SmallIntSet {
/// Return true if the set contains a value
fn contains(&self, value: &uint) -> bool { self.map.contains_key(value) }
@ -233,12 +225,14 @@ impl Set<uint> for SmallIntSet {
/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty uintersection.
fn is_disjoint(&self, other: &SmallIntSet) -> bool {
old_iter::all(self, |v| !other.contains(v))
for self.each |v| { if other.contains(v) { return false } }
true
}
/// Return true if the set is a subset of another
fn is_subset(&self, other: &SmallIntSet) -> bool {
old_iter::all(self, |v| other.contains(v))
for self.each |v| { if !other.contains(v) { return false } }
true
}
/// Return true if the set is a superset of another
@ -286,6 +280,9 @@ impl Set<uint> for SmallIntSet {
impl SmallIntSet {
/// Create an empty SmallIntSet
pub fn new() -> SmallIntSet { SmallIntSet{map: SmallIntMap::new()} }
/// Visit all values in order
pub fn each(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key(f) }
}
#[cfg(test)]

View File

@ -249,22 +249,6 @@ pub struct TreeSet<T> {
priv map: TreeMap<T, ()>
}
impl<T: TotalOrd> BaseIter<T> for TreeSet<T> {
/// Visit all values in order
#[inline]
fn each(&self, f: &fn(&T) -> bool) -> bool { self.map.each_key(f) }
#[inline]
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<T: TotalOrd> ReverseIter<T> for TreeSet<T> {
/// Visit all values in reverse order
#[inline]
fn each_reverse(&self, f: &fn(&T) -> bool) -> bool {
self.map.each_key_reverse(f)
}
}
impl<T: Eq + TotalOrd> Eq for TreeSet<T> {
#[inline]
fn eq(&self, other: &TreeSet<T>) -> bool { self.map == other.map }
@ -499,6 +483,16 @@ impl<T: TotalOrd> TreeSet<T> {
pub fn iter<'a>(&'a self) -> TreeSetIterator<'a, T> {
TreeSetIterator{iter: self.map.iter()}
}
/// Visit all values in order
#[inline]
pub fn each(&self, f: &fn(&T) -> bool) -> bool { self.map.each_key(f) }
/// Visit all values in reverse order
#[inline]
pub fn each_reverse(&self, f: &fn(&T) -> bool) -> bool {
self.map.each_key_reverse(f)
}
}
/// Lazy forward iterator over a set

View File

@ -731,8 +731,8 @@ fn encode_info_for_method(ecx: &EncodeContext,
}
let mut combined_ty_params = opt_vec::Empty;
combined_ty_params.push_all(&owner_generics.ty_params);
combined_ty_params.push_all(&method_generics.ty_params);
for owner_generics.ty_params.each |x| { combined_ty_params.push(copy *x) }
for method_generics.ty_params.each |x| { combined_ty_params.push(copy *x) }
let len = combined_ty_params.len();
encode_type_param_bounds(ebml_w, ecx, &combined_ty_params);

View File

@ -507,7 +507,7 @@ impl FlowedMoveData {
for self.dfcx_moves.each_bit_on_entry_frozen(id) |index| {
let move = &self.move_data.moves[index];
let moved_path = move.path;
if base_indices.contains(&moved_path) {
if base_indices.iter().any_(|x| x == &moved_path) {
// Scenario 1 or 2: `loan_path` or some base path of
// `loan_path` was moved.
if !f(move, self.move_data.path(moved_path).loan_path) {
@ -536,7 +536,7 @@ impl FlowedMoveData {
-> bool {
//! True if `id` is the id of the LHS of an assignment
self.move_data.assignee_ids.contains(&id)
self.move_data.assignee_ids.iter().any_(|x| x == &id)
}
pub fn each_assignment_of(&self,

View File

@ -3710,7 +3710,7 @@ impl Resolver {
let function_type_rib = @Rib(rib_kind);
self.type_ribs.push(function_type_rib);
for generics.ty_params.eachi |index, type_parameter| {
for generics.ty_params.iter().enumerate().advance |(index, type_parameter)| {
let name = type_parameter.ident;
debug!("with_type_parameter_rib: %d %d", node_id,
type_parameter.id);

View File

@ -14,7 +14,6 @@ use cast::transmute;
use container::Container;
use iterator::IteratorUtil;
use kinds::Copy;
use old_iter;
use option::Option;
use sys;
use uint;
@ -129,7 +128,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: old_iter::InitOp<T>) -> @[T] {
pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> @[T] {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(op(i)); i += 1u; }

View File

@ -138,7 +138,6 @@ 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;

View File

@ -1,296 +0,0 @@
// 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.
*/
#[allow(missing_doc)];
use cmp::Eq;
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) -> bool;
fn size_hint(&self) -> Option<uint>;
}
pub trait ReverseIter<A>: BaseIter<A> {
fn each_reverse(&self, blk: &fn(&A) -> bool) -> bool;
}
pub trait ExtendedIter<A> {
fn eachi(&self, blk: &fn(uint, v: &A) -> bool) -> 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 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>;
}
// 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]
pub fn _eachi<A,IA:BaseIter<A>>(this: &IA, blk: &fn(uint, &A) -> bool) -> bool {
let mut i = 0;
for this.each |a| {
if !blk(i, a) {
return false;
}
i += 1;
}
return true;
}
pub fn eachi<A,IA:BaseIter<A>>(this: &IA, blk: &fn(uint, &A) -> bool) -> bool {
_eachi(this, blk)
}
#[inline]
pub fn all<A,IA:BaseIter<A>>(this: &IA, blk: &fn(&A) -> bool) -> bool {
for this.each |a| {
if !blk(a) {
return false;
}
}
return true;
}
#[inline]
pub fn any<A,IA:BaseIter<A>>(this: &IA, blk: &fn(&A) -> bool) -> bool {
for this.each |a| {
if blk(a) {
return true;
}
}
return false;
}
#[inline]
pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(this: &IA,
prd: &fn(&A) -> bool)
-> ~[A] {
do vec::build_sized_opt(this.size_hint()) |push| {
for this.each |a| {
if prd(a) { push(copy *a); }
}
}
}
#[inline]
pub fn map_to_vec<A,B,IA:BaseIter<A>>(this: &IA, op: &fn(&A) -> B) -> ~[B] {
do vec::build_sized_opt(this.size_hint()) |push| {
for this.each |a| {
push(op(a));
}
}
}
#[inline]
pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(this: &IA,
op: &fn(&A) -> IB)
-> ~[B] {
do vec::build |push| {
for this.each |a| {
for op(a).each |&b| {
push(b);
}
}
}
}
#[inline]
pub fn foldl<A,B,IA:BaseIter<A>>(this: &IA, b0: B, blk: &fn(&B, &A) -> B)
-> B {
let mut b = b0;
for this.each |a| {
b = blk(&b, a);
}
b
}
#[inline]
pub fn to_vec<A:Copy,IA:BaseIter<A>>(this: &IA) -> ~[A] {
map_to_vec(this, |&x| x)
}
#[inline]
pub fn contains<A:Eq,IA:BaseIter<A>>(this: &IA, x: &A) -> bool {
for this.each |a| {
if *a == *x { return true; }
}
return false;
}
#[inline]
pub fn count<A:Eq,IA:BaseIter<A>>(this: &IA, x: &A) -> uint {
do foldl(this, 0) |count, value| {
if *value == *x {
*count + 1
} else {
*count
}
}
}
#[inline]
pub fn position<A,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
-> Option<uint> {
let mut i = 0;
for this.each |a| {
if f(a) { return Some(i); }
i += 1;
}
return None;
}
#[inline]
pub fn find<A:Copy,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
-> Option<A> {
for this.each |i| {
if f(i) { return Some(copy *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]
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]
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]
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]
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]
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(copy t); i += 1; }
}
}
/// Appends two generic sequences.
#[inline]
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(copy *x); }
for rhs.each |x| { push(copy *x); }
}
}
/// Copies a generic sequence, possibly converting it to a different
/// type of sequence.
#[inline]
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(copy *x); }
}
}

View File

@ -46,8 +46,6 @@ pub use cmp::{Eq, ApproxEq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Great
pub use char::Char;
pub use container::{Container, Mutable, Map, Set};
pub use hash::Hash;
pub use old_iter::{BaseIter, ReverseIter, ExtendedIter, EqIter};
pub use old_iter::CopyableIter;
pub use iter::{Times, FromIter};
pub use iterator::{Iterator, IteratorUtil, OrdIterator};
pub use num::{Num, NumCast};

View File

@ -15,7 +15,6 @@ use super::io::net::ip::IpAddr;
use super::uv::*;
use super::rtio::*;
use ops::Drop;
use old_iter::CopyableIter;
use cell::Cell;
use cast::transmute;
use super::sched::{Scheduler, local_sched};

View File

@ -29,7 +29,6 @@ use iterator::{Iterator, IteratorUtil, FilterIterator, AdditiveIterator, MapIter
use libc;
use num::Zero;
use option::{None, Option, Some};
use old_iter::EqIter;
use ptr;
use ptr::RawPtr;
use to_str::ToStr;
@ -2225,7 +2224,6 @@ mod tests {
use option::Some;
use libc::c_char;
use libc;
use old_iter::BaseIter;
use ptr;
use str::*;
use vec;

View File

@ -21,7 +21,6 @@ use iterator::IteratorUtil;
use container::Map;
use hash::Hash;
use cmp::Eq;
use old_iter::BaseIter;
use vec::ImmutableVector;
use iterator::IteratorUtil;

View File

@ -176,22 +176,6 @@ pub struct TrieSet {
priv map: TrieMap<()>
}
impl BaseIter<uint> for TrieSet {
/// Visit all values in order
#[inline]
fn each(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key(f) }
#[inline]
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl ReverseIter<uint> for TrieSet {
/// Visit all values in reverse order
#[inline]
fn each_reverse(&self, f: &fn(&uint) -> bool) -> bool {
self.map.each_key_reverse(f)
}
}
impl Container for TrieSet {
/// Return the number of elements in the set
#[inline]
@ -234,6 +218,16 @@ impl TrieSet {
pub fn remove(&mut self, value: &uint) -> bool {
self.map.remove(value)
}
/// Visit all values in order
#[inline]
pub fn each(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key(f) }
/// Visit all values in reverse order
#[inline]
pub fn each_reverse(&self, f: &fn(&uint) -> bool) -> bool {
self.map.each_key_reverse(f)
}
}
struct TrieNode<T> {

View File

@ -17,7 +17,6 @@ use cast;
use container::{Container, Mutable};
use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
use clone::Clone;
use old_iter;
use iterator::{FromIterator, Iterator, IteratorUtil};
use iter::FromIter;
use kinds::Copy;
@ -124,7 +123,7 @@ pub fn capacity<T>(v: &const ~[T]) -> uint {
* Creates an owned 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: old_iter::InitOp<T>) -> ~[T] {
pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T] {
unsafe {
let mut v = with_capacity(n_elts);
do as_mut_buf(v) |p, _len| {
@ -815,7 +814,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: old_iter::InitOp<T>) {
pub fn grow_fn<T>(v: &mut ~[T], n: uint, op: &fn(uint) -> T) {
let new_len = v.len() + n;
reserve_at_least(&mut *v, new_len);
let mut i: uint = 0u;
@ -1985,7 +1984,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: old_iter::InitOp<T>);
fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T);
}
impl<T> OwnedVector<T> for ~[T] {
@ -2064,7 +2063,7 @@ impl<T> OwnedVector<T> for ~[T] {
}
#[inline]
fn grow_fn(&mut self, n: uint, op: old_iter::InitOp<T>) {
fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T) {
grow_fn(self, n, op);
}
}

View File

@ -375,7 +375,7 @@ impl gen_init for protocol {
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
for (copy self.states).iter().advance |s| {
for s.generics.ty_params.each |tp| {
match params.find(|tpp| tp.ident == tpp.ident) {
match params.iter().find_(|tpp| tp.ident == tpp.ident) {
None => params.push(*tp),
_ => ()
}
@ -393,7 +393,7 @@ impl gen_init for protocol {
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
let fields = do (copy self.states).iter().transform |s| {
for s.generics.ty_params.each |tp| {
match params.find(|tpp| tp.ident == tpp.ident) {
match params.iter().find_(|tpp| tp.ident == tpp.ident) {
None => params.push(*tp),
_ => ()
}

View File

@ -17,9 +17,7 @@
*/
use core::prelude::*;
use core::old_iter;
use core::old_iter::BaseIter;
use core::vec::VecIterator;
#[deriving(Encodable, Decodable)]
pub enum OptVec<T> {
@ -40,6 +38,13 @@ pub fn from<T>(t: ~[T]) -> OptVec<T> {
}
impl<T> OptVec<T> {
fn each(&self, blk: &fn(v: &T) -> bool) -> bool {
match *self {
Empty => true,
Vec(ref v) => v.iter().advance(blk)
}
}
fn push(&mut self, t: T) {
match *self {
Vec(ref mut v) => {
@ -78,6 +83,28 @@ impl<T> OptVec<T> {
Vec(ref v) => v.len()
}
}
#[inline]
fn iter<'r>(&'r self) -> OptVecIterator<'r, T> {
match *self {
Empty => OptVecIterator{iter: None},
Vec(ref v) => OptVecIterator{iter: Some(v.iter())}
}
}
#[inline]
fn map_to_vec<B>(&self, op: &fn(&T) -> B) -> ~[B] {
self.iter().transform(op).collect()
}
fn mapi_to_vec<B>(&self, op: &fn(uint, &T) -> B) -> ~[B] {
let mut index = 0;
self.map_to_vec(|a| {
let i = index;
index += 1;
op(i, a)
})
}
}
pub fn take_vec<T>(v: OptVec<T>) -> ~[T] {
@ -96,22 +123,6 @@ impl<T:Copy> OptVec<T> {
}
return Vec(v0);
}
fn push_all<I: BaseIter<T>>(&mut self, from: &I) {
for from.each |e| {
self.push(copy *e);
}
}
#[inline]
fn mapi_to_vec<B>(&self, op: &fn(uint, &T) -> B) -> ~[B] {
let mut index = 0;
old_iter::map_to_vec(self, |a| {
let i = index;
index += 1;
op(i, a)
})
}
}
impl<A:Eq> Eq for OptVec<A> {
@ -131,68 +142,16 @@ impl<A:Eq> Eq for OptVec<A> {
}
}
impl<A> BaseIter<A> for OptVec<A> {
fn each(&self, blk: &fn(v: &A) -> bool) -> bool {
match *self {
Empty => true,
Vec(ref v) => v.iter().advance(blk)
pub struct OptVecIterator<'self, T> {
priv iter: Option<VecIterator<'self, T>>
}
impl<'self, T> Iterator<&'self T> for OptVecIterator<'self, T> {
#[inline]
fn next(&mut self) -> Option<&'self T> {
match self.iter {
Some(ref mut x) => x.next(),
None => None
}
}
fn size_hint(&self) -> Option<uint> {
Some(self.len())
}
}
impl<A> old_iter::ExtendedIter<A> for OptVec<A> {
#[inline]
fn eachi(&self, blk: &fn(v: uint, v: &A) -> bool) -> bool {
old_iter::eachi(self, blk)
}
#[inline]
fn all(&self, blk: &fn(&A) -> bool) -> bool {
old_iter::all(self, blk)
}
#[inline]
fn any(&self, blk: &fn(&A) -> bool) -> bool {
old_iter::any(self, blk)
}
#[inline]
fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
old_iter::foldl(self, b0, blk)
}
#[inline]
fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
old_iter::position(self, f)
}
#[inline]
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
old_iter::map_to_vec(self, op)
}
#[inline]
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B] {
old_iter::flat_map_to_vec(self, op)
}
}
impl<A: Eq> old_iter::EqIter<A> for OptVec<A> {
#[inline]
fn contains(&self, x: &A) -> bool { old_iter::contains(self, x) }
#[inline]
fn count(&self, x: &A) -> uint { old_iter::count(self, x) }
}
impl<A: Copy> old_iter::CopyableIter<A> for OptVec<A> {
#[inline]
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
old_iter::filter_to_vec(self, pred)
}
#[inline]
fn to_vec(&self) -> ~[A] { old_iter::to_vec(self) }
#[inline]
fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
old_iter::find(self, f)
}
}

View File

@ -13,7 +13,6 @@
// Instead the failure will be delivered after the callbacks return.
use std::libc;
use std::old_iter;
use std::task;
mod rustrt {

View File

@ -13,7 +13,6 @@
use std::cmp;
use std::container::{Container, Mutable, Map};
use std::int;
use std::old_iter::BaseIter;
use std::uint;
enum cat_type { tuxedo, tabby, tortoiseshell }

View File

@ -1,35 +0,0 @@
// Copyright 2012 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.
// xfail-test
extern mod extra;
use extra::oldmap::{map, hashmap, int_hash};
class keys<K:Copy,V:Copy,M:Copy + map<K,V>>
: old_iter::base_iter<K> {
let map: M;
new(map: M) {
self.map = map;
}
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) { old_iter::eachi(self, blk) }
}
pub fn main() {
let m = int_hash();
m.insert(1, 2);
m.insert(3, 4);
assert_eq!(old_iter::to_vec(keys(m)), ~[1, 3]);
}