From e2e39234cc5509fb461b8805eeb32c5ce538ee6e Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 23 Jun 2013 17:57:39 -0400 Subject: [PATCH] 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 --- src/libextra/bitv.rs | 6 +- src/libextra/dlist.rs | 94 +++--- src/libextra/priority_queue.rs | 17 +- src/libextra/smallintmap.rs | 17 +- src/libextra/treemap.rs | 26 +- src/librustc/metadata/encoder.rs | 4 +- src/librustc/middle/borrowck/move_data.rs | 4 +- src/librustc/middle/resolve.rs | 2 +- src/libstd/at_vec.rs | 3 +- src/libstd/core.rc | 1 - src/libstd/old_iter.rs | 296 ------------------ src/libstd/prelude.rs | 2 - src/libstd/rt/uvio.rs | 1 - src/libstd/str.rs | 2 - src/libstd/to_str.rs | 1 - src/libstd/trie.rs | 26 +- src/libstd/vec.rs | 9 +- src/libsyntax/ext/pipes/pipec.rs | 4 +- src/libsyntax/opt_vec.rs | 121 +++---- src/test/run-fail/extern-fail.rs | 1 - .../class-impl-very-parameterized-trait.rs | 1 - .../run-pass/class-trait-bounded-param.rs | 35 --- 22 files changed, 122 insertions(+), 551 deletions(-) delete mode 100644 src/libstd/old_iter.rs delete mode 100644 src/test/run-pass/class-trait-bounded-param.rs diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 940c89bb0c68..6e4507d4277a 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -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 for BitvSet { - fn size_hint(&self) -> Option { 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; diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 953803c6843f..1767aa8c3972 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -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 = Option<@mut DListNode>; @@ -213,6 +211,42 @@ impl DList { } impl DList { + /** + * 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 DList { /// 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 BaseIter for @mut DList { - /** - * 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 { 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; diff --git a/src/libextra/priority_queue.rs b/src/libextra/priority_queue.rs index 31c9acbbd54d..4e201a6538ba 100644 --- a/src/libextra/priority_queue.rs +++ b/src/libextra/priority_queue.rs @@ -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 { priv data: ~[T], } -impl BaseIter for PriorityQueue { - /// 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 { Some(self.data.len()) } -} - impl Container for PriorityQueue { /// Returns the length of the queue fn len(&self) -> uint { self.data.len() } @@ -47,6 +37,11 @@ impl Mutable for PriorityQueue { } impl PriorityQueue { + /// 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] } diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index aee087d3764d..17126f0d32b5 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -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 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 { Some(self.len()) } -} - impl Set 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 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 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)] diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 87932c25cda1..4929dea9045b 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -249,22 +249,6 @@ pub struct TreeSet { priv map: TreeMap } -impl BaseIter for TreeSet { - /// 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 { Some(self.len()) } -} - -impl ReverseIter for TreeSet { - /// Visit all values in reverse order - #[inline] - fn each_reverse(&self, f: &fn(&T) -> bool) -> bool { - self.map.each_key_reverse(f) - } -} - impl Eq for TreeSet { #[inline] fn eq(&self, other: &TreeSet) -> bool { self.map == other.map } @@ -499,6 +483,16 @@ impl TreeSet { 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 diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 94cad18ece2c..1f2ede670fa1 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -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); diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index 0b94eeecba87..7396dc1bd7bf 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -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, diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index eed0b12b9e12..562bbca69297 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -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); diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 2b846c923c48..b871ed3d57af 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -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(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(n_elts: uint, op: old_iter::InitOp) -> @[T] { +pub fn from_fn(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; } diff --git a/src/libstd/core.rc b/src/libstd/core.rc index 6911c00e55ba..13c54799fac4 100644 --- a/src/libstd/core.rc +++ b/src/libstd/core.rc @@ -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; diff --git a/src/libstd/old_iter.rs b/src/libstd/old_iter.rs deleted file mode 100644 index 9b87d76a309d..000000000000 --- a/src/libstd/old_iter.rs +++ /dev/null @@ -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 or the MIT license -// , 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 { - fn each(&self, blk: &fn(v: &A) -> bool) -> bool; - fn size_hint(&self) -> Option; -} - -pub trait ReverseIter: BaseIter { - fn each_reverse(&self, blk: &fn(&A) -> bool) -> bool; -} - -pub trait ExtendedIter { - 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(&self, b0: B, blk: &fn(&B, &A) -> B) -> B; - fn position(&self, f: &fn(&A) -> bool) -> Option; - fn map_to_vec(&self, op: &fn(&A) -> B) -> ~[B]; - fn flat_map_to_vec>(&self, op: &fn(&A) -> IB) -> ~[B]; -} - -pub trait EqIter { - fn contains(&self, x: &A) -> bool; - fn count(&self, x: &A) -> uint; -} - -pub trait CopyableIter { - fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A]; - fn to_vec(&self) -> ~[A]; - fn find(&self, p: &fn(&A) -> bool) -> Option; -} - -// A trait for sequences that can be built by imperatively pushing elements -// onto them. -pub trait Buildable { - /** - * 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>(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>(this: &IA, blk: &fn(uint, &A) -> bool) -> bool { - _eachi(this, blk) -} - -#[inline] -pub fn all>(this: &IA, blk: &fn(&A) -> bool) -> bool { - for this.each |a| { - if !blk(a) { - return false; - } - } - return true; -} - -#[inline] -pub fn any>(this: &IA, blk: &fn(&A) -> bool) -> bool { - for this.each |a| { - if blk(a) { - return true; - } - } - return false; -} - -#[inline] -pub fn filter_to_vec>(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>(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,IB:BaseIter>(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>(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>(this: &IA) -> ~[A] { - map_to_vec(this, |&x| x) -} - -#[inline] -pub fn contains>(this: &IA, x: &A) -> bool { - for this.each |a| { - if *a == *x { return true; } - } - return false; -} - -#[inline] -pub fn count>(this: &IA, x: &A) -> uint { - do foldl(this, 0) |count, value| { - if *value == *x { - *count + 1 - } else { - *count - } - } -} - -#[inline] -pub fn position>(this: &IA, f: &fn(&A) -> bool) - -> Option { - let mut i = 0; - for this.each |a| { - if f(a) { return Some(i); } - i += 1; - } - return None; -} - -#[inline] -pub fn find>(this: &IA, f: &fn(&A) -> bool) - -> Option { - 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>(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>(size: Option, - 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,U,BU: Buildable>(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>(n_elts: uint, op: InitOp) -> 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>(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,BT:Buildable>(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,BT:Buildable>(v: &IT) -> BT { - do build_sized_opt(v.size_hint()) |push| { - for v.each |x| { push(copy *x); } - } -} diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 309df27e151d..6d7cb2a28a88 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -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}; diff --git a/src/libstd/rt/uvio.rs b/src/libstd/rt/uvio.rs index 070ccf7fb446..f4a79934e7e4 100644 --- a/src/libstd/rt/uvio.rs +++ b/src/libstd/rt/uvio.rs @@ -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}; diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 45ba85283754..16c287c1da82 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -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; diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index 56078a69f28f..9f8122886213 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -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; diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 39980ffa5991..e6449ef49229 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -176,22 +176,6 @@ pub struct TrieSet { priv map: TrieMap<()> } -impl BaseIter 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 { Some(self.len()) } -} - -impl ReverseIter 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 { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 17eb7e8e82be..aeb5b000747f 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -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(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(n_elts: uint, op: old_iter::InitOp) -> ~[T] { +pub fn from_fn(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(v: &mut ~[T], n: uint, initval: &T) { * * init_op - A function to call to retreive each appended element's * value */ -pub fn grow_fn(v: &mut ~[T], n: uint, op: old_iter::InitOp) { +pub fn grow_fn(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 { 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); + fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T); } impl OwnedVector for ~[T] { @@ -2064,7 +2063,7 @@ impl OwnedVector for ~[T] { } #[inline] - fn grow_fn(&mut self, n: uint, op: old_iter::InitOp) { + fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T) { grow_fn(self, n, op); } } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index a20528082ab5..55ac9c5ec1c8 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -375,7 +375,7 @@ impl gen_init for protocol { let mut params: OptVec = 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 = 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), _ => () } diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs index c537a3e8eba3..8917b481dc72 100644 --- a/src/libsyntax/opt_vec.rs +++ b/src/libsyntax/opt_vec.rs @@ -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 { @@ -40,6 +38,13 @@ pub fn from(t: ~[T]) -> OptVec { } impl OptVec { + 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 OptVec { 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(&self, op: &fn(&T) -> B) -> ~[B] { + self.iter().transform(op).collect() + } + + fn mapi_to_vec(&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(v: OptVec) -> ~[T] { @@ -96,22 +123,6 @@ impl OptVec { } return Vec(v0); } - - fn push_all>(&mut self, from: &I) { - for from.each |e| { - self.push(copy *e); - } - } - - #[inline] - fn mapi_to_vec(&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 Eq for OptVec { @@ -131,68 +142,16 @@ impl Eq for OptVec { } } -impl BaseIter for OptVec { - 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> +} + +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 { - Some(self.len()) - } -} - -impl old_iter::ExtendedIter for OptVec { - #[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(&self, b0: B, blk: &fn(&B, &A) -> B) -> B { - old_iter::foldl(self, b0, blk) - } - #[inline] - fn position(&self, f: &fn(&A) -> bool) -> Option { - old_iter::position(self, f) - } - #[inline] - fn map_to_vec(&self, op: &fn(&A) -> B) -> ~[B] { - old_iter::map_to_vec(self, op) - } - #[inline] - fn flat_map_to_vec>(&self, op: &fn(&A) -> IB) - -> ~[B] { - old_iter::flat_map_to_vec(self, op) - } - -} - -impl old_iter::EqIter for OptVec { - #[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 old_iter::CopyableIter for OptVec { - #[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 { - old_iter::find(self, f) - } } diff --git a/src/test/run-fail/extern-fail.rs b/src/test/run-fail/extern-fail.rs index 2be41d3bed00..3d15ea16241f 100644 --- a/src/test/run-fail/extern-fail.rs +++ b/src/test/run-fail/extern-fail.rs @@ -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 { diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index 88686bcdbfa3..c54b8db46c88 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -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 } diff --git a/src/test/run-pass/class-trait-bounded-param.rs b/src/test/run-pass/class-trait-bounded-param.rs deleted file mode 100644 index 75c62abcb0d5..000000000000 --- a/src/test/run-pass/class-trait-bounded-param.rs +++ /dev/null @@ -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 or the MIT license -// , 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> - : old_iter::base_iter { - - 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 { 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]); -}