diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-06-23 17:57:39 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-06-24 01:35:11 -0400 |
| commit | e2e39234cc5509fb461b8805eeb32c5ce538ee6e (patch) | |
| tree | 3d3e6047f22148cb76916b20c4ed274fc99a177d /src/libstd | |
| parent | ac4211ef52a3577f901ed4dc7f370b05ca4e638d (diff) | |
| download | rust-e2e39234cc5509fb461b8805eeb32c5ce538ee6e.tar.gz rust-e2e39234cc5509fb461b8805eeb32c5ce538ee6e.zip | |
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
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/at_vec.rs | 3 | ||||
| -rw-r--r-- | src/libstd/core.rc | 1 | ||||
| -rw-r--r-- | src/libstd/old_iter.rs | 296 | ||||
| -rw-r--r-- | src/libstd/prelude.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/uvio.rs | 1 | ||||
| -rw-r--r-- | src/libstd/str.rs | 2 | ||||
| -rw-r--r-- | src/libstd/to_str.rs | 1 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 26 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 9 |
9 files changed, 15 insertions, 326 deletions
diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 2b846c923c4..b871ed3d57a 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<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; } diff --git a/src/libstd/core.rc b/src/libstd/core.rc index 6911c00e55b..13c54799fac 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 9b87d76a309..00000000000 --- 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 <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); } - } -} diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 309df27e151..6d7cb2a28a8 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 070ccf7fb44..f4a79934e7e 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 45ba8528375..16c287c1da8 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 56078a69f28..9f812288621 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 39980ffa599..e6449ef4922 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -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> { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 17eb7e8e82b..aeb5b000747 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<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); } } |
