diff options
Diffstat (limited to 'src/libextra')
| -rw-r--r-- | src/libextra/bitv.rs | 28 | ||||
| -rw-r--r-- | src/libextra/dlist.rs | 46 | ||||
| -rw-r--r-- | src/libextra/enum_set.rs | 14 | ||||
| -rw-r--r-- | src/libextra/glob.rs | 14 | ||||
| -rw-r--r-- | src/libextra/priority_queue.rs | 10 | ||||
| -rw-r--r-- | src/libextra/ringbuf.rs | 32 | ||||
| -rw-r--r-- | src/libextra/smallintmap.rs | 35 | ||||
| -rw-r--r-- | src/libextra/treemap.rs | 142 |
8 files changed, 160 insertions, 161 deletions
diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 9f40507826f..5fd1bb9d599 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -414,12 +414,12 @@ impl Bitv { } #[inline] - pub fn iter<'a>(&'a self) -> BitvIterator<'a> { - BitvIterator {bitv: self, next_idx: 0, end_idx: self.nbits} + pub fn iter<'a>(&'a self) -> Bits<'a> { + Bits {bitv: self, next_idx: 0, end_idx: self.nbits} } #[inline] - pub fn rev_iter<'a>(&'a self) -> Invert<BitvIterator<'a>> { + pub fn rev_iter<'a>(&'a self) -> Invert<Bits<'a>> { self.iter().invert() } @@ -578,13 +578,13 @@ fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool { } /// An iterator for `Bitv`. -pub struct BitvIterator<'a> { +pub struct Bits<'a> { priv bitv: &'a Bitv, priv next_idx: uint, priv end_idx: uint, } -impl<'a> Iterator<bool> for BitvIterator<'a> { +impl<'a> Iterator<bool> for Bits<'a> { #[inline] fn next(&mut self) -> Option<bool> { if self.next_idx != self.end_idx { @@ -602,7 +602,7 @@ impl<'a> Iterator<bool> for BitvIterator<'a> { } } -impl<'a> DoubleEndedIterator<bool> for BitvIterator<'a> { +impl<'a> DoubleEndedIterator<bool> for Bits<'a> { #[inline] fn next_back(&mut self) -> Option<bool> { if self.next_idx != self.end_idx { @@ -614,9 +614,9 @@ impl<'a> DoubleEndedIterator<bool> for BitvIterator<'a> { } } -impl<'a> ExactSize<bool> for BitvIterator<'a> {} +impl<'a> ExactSize<bool> for Bits<'a> {} -impl<'a> RandomAccessIterator<bool> for BitvIterator<'a> { +impl<'a> RandomAccessIterator<bool> for Bits<'a> { #[inline] fn indexable(&self) -> uint { self.end_idx - self.next_idx @@ -724,8 +724,8 @@ impl BitvSet { self.other_op(other, |w1, w2| w1 ^ w2); } - pub fn iter<'a>(&'a self) -> BitvSetIterator<'a> { - BitvSetIterator {set: self, next_idx: 0} + pub fn iter<'a>(&'a self) -> BitPositions<'a> { + BitPositions {set: self, next_idx: 0} } pub fn difference(&self, other: &BitvSet, f: |&uint| -> bool) -> bool { @@ -871,7 +871,7 @@ impl BitvSet { /// and w1/w2 are the words coming from the two vectors self, other. fn commons<'a>(&'a self, other: &'a BitvSet) -> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint), - Zip<Enumerate<vec::VecIterator<'a, uint>>, Repeat<&'a ~[uint]>>> { + Zip<Enumerate<vec::Items<'a, uint>>, Repeat<&'a ~[uint]>>> { let min = num::min(self.bitv.storage.len(), other.bitv.storage.len()); self.bitv.storage.slice(0, min).iter().enumerate() .zip(Repeat::new(&other.bitv.storage)) @@ -887,7 +887,7 @@ impl BitvSet { /// `other`. fn outliers<'a>(&'a self, other: &'a BitvSet) -> Map<'static, ((uint, &'a uint), uint), (bool, uint, uint), - Zip<Enumerate<vec::VecIterator<'a, uint>>, Repeat<uint>>> { + Zip<Enumerate<vec::Items<'a, uint>>, Repeat<uint>>> { let slen = self.bitv.storage.len(); let olen = other.bitv.storage.len(); @@ -903,12 +903,12 @@ impl BitvSet { } } -pub struct BitvSetIterator<'a> { +pub struct BitPositions<'a> { priv set: &'a BitvSet, priv next_idx: uint } -impl<'a> Iterator<uint> for BitvSetIterator<'a> { +impl<'a> Iterator<uint> for BitPositions<'a> { #[inline] fn next(&mut self) -> Option<uint> { while self.next_idx < self.set.capacity() { diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 85def62dc3b..28a6c69ba1b 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -48,14 +48,14 @@ struct Node<T> { /// Double-ended DList iterator #[deriving(Clone)] -pub struct DListIterator<'a, T> { +pub struct Items<'a, T> { priv head: &'a Link<T>, priv tail: Rawlink<Node<T>>, priv nelem: uint, } /// Double-ended mutable DList iterator -pub struct MutDListIterator<'a, T> { +pub struct MutItems<'a, T> { priv list: &'a mut DList<T>, priv head: Rawlink<Node<T>>, priv tail: Rawlink<Node<T>>, @@ -64,7 +64,7 @@ pub struct MutDListIterator<'a, T> { /// DList consuming iterator #[deriving(Clone)] -pub struct MoveIterator<T> { +pub struct MoveItems<T> { priv list: DList<T> } @@ -362,24 +362,24 @@ impl<T> DList<T> { /// Provide a forward iterator #[inline] - pub fn iter<'a>(&'a self) -> DListIterator<'a, T> { - DListIterator{nelem: self.len(), head: &self.list_head, tail: self.list_tail} + pub fn iter<'a>(&'a self) -> Items<'a, T> { + Items{nelem: self.len(), head: &self.list_head, tail: self.list_tail} } /// Provide a reverse iterator #[inline] - pub fn rev_iter<'a>(&'a self) -> Invert<DListIterator<'a, T>> { + pub fn rev_iter<'a>(&'a self) -> Invert<Items<'a, T>> { self.iter().invert() } /// Provide a forward iterator with mutable references #[inline] - pub fn mut_iter<'a>(&'a mut self) -> MutDListIterator<'a, T> { + pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> { let head_raw = match self.list_head { Some(ref mut h) => Rawlink::some(*h), None => Rawlink::none(), }; - MutDListIterator{ + MutItems{ nelem: self.len(), head: head_raw, tail: self.list_tail, @@ -388,20 +388,20 @@ impl<T> DList<T> { } /// Provide a reverse iterator with mutable references #[inline] - pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutDListIterator<'a, T>> { + pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutItems<'a, T>> { self.mut_iter().invert() } /// Consume the list into an iterator yielding elements by value #[inline] - pub fn move_iter(self) -> MoveIterator<T> { - MoveIterator{list: self} + pub fn move_iter(self) -> MoveItems<T> { + MoveItems{list: self} } /// Consume the list into an iterator yielding elements by value, in reverse #[inline] - pub fn move_rev_iter(self) -> Invert<MoveIterator<T>> { + pub fn move_rev_iter(self) -> Invert<MoveItems<T>> { self.move_iter().invert() } } @@ -439,7 +439,7 @@ impl<T> Drop for DList<T> { } -impl<'a, A> Iterator<&'a A> for DListIterator<'a, A> { +impl<'a, A> Iterator<&'a A> for Items<'a, A> { #[inline] fn next(&mut self) -> Option<&'a A> { if self.nelem == 0 { @@ -458,7 +458,7 @@ impl<'a, A> Iterator<&'a A> for DListIterator<'a, A> { } } -impl<'a, A> DoubleEndedIterator<&'a A> for DListIterator<'a, A> { +impl<'a, A> DoubleEndedIterator<&'a A> for Items<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a A> { if self.nelem == 0 { @@ -473,9 +473,9 @@ impl<'a, A> DoubleEndedIterator<&'a A> for DListIterator<'a, A> { } } -impl<'a, A> ExactSize<&'a A> for DListIterator<'a, A> {} +impl<'a, A> ExactSize<&'a A> for Items<'a, A> {} -impl<'a, A> Iterator<&'a mut A> for MutDListIterator<'a, A> { +impl<'a, A> Iterator<&'a mut A> for MutItems<'a, A> { #[inline] fn next(&mut self) -> Option<&'a mut A> { if self.nelem == 0 { @@ -497,7 +497,7 @@ impl<'a, A> Iterator<&'a mut A> for MutDListIterator<'a, A> { } } -impl<'a, A> DoubleEndedIterator<&'a mut A> for MutDListIterator<'a, A> { +impl<'a, A> DoubleEndedIterator<&'a mut A> for MutItems<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a mut A> { if self.nelem == 0 { @@ -511,7 +511,7 @@ impl<'a, A> DoubleEndedIterator<&'a mut A> for MutDListIterator<'a, A> { } } -impl<'a, A> ExactSize<&'a mut A> for MutDListIterator<'a, A> {} +impl<'a, A> ExactSize<&'a mut A> for MutItems<'a, A> {} /// Allow mutating the DList while iterating pub trait ListInsertion<A> { @@ -524,8 +524,8 @@ pub trait ListInsertion<A> { fn peek_next<'a>(&'a mut self) -> Option<&'a mut A>; } -// private methods for MutDListIterator -impl<'a, A> MutDListIterator<'a, A> { +// private methods for MutItems +impl<'a, A> MutItems<'a, A> { fn insert_next_node(&mut self, mut ins_node: ~Node<A>) { // Insert before `self.head` so that it is between the // previously yielded element and self.head. @@ -547,7 +547,7 @@ impl<'a, A> MutDListIterator<'a, A> { } } -impl<'a, A> ListInsertion<A> for MutDListIterator<'a, A> { +impl<'a, A> ListInsertion<A> for MutItems<'a, A> { #[inline] fn insert_next(&mut self, elt: A) { self.insert_next_node(~Node::new(elt)) @@ -562,7 +562,7 @@ impl<'a, A> ListInsertion<A> for MutDListIterator<'a, A> { } } -impl<A> Iterator<A> for MoveIterator<A> { +impl<A> Iterator<A> for MoveItems<A> { #[inline] fn next(&mut self) -> Option<A> { self.list.pop_front() } @@ -572,7 +572,7 @@ impl<A> Iterator<A> for MoveIterator<A> { } } -impl<A> DoubleEndedIterator<A> for MoveIterator<A> { +impl<A> DoubleEndedIterator<A> for MoveItems<A> { #[inline] fn next_back(&mut self) -> Option<A> { self.list.pop_back() } } diff --git a/src/libextra/enum_set.rs b/src/libextra/enum_set.rs index e0461778075..f12da3080aa 100644 --- a/src/libextra/enum_set.rs +++ b/src/libextra/enum_set.rs @@ -77,8 +77,8 @@ impl<E:CLike> EnumSet<E> { } /// Returns an iterator over an EnumSet - pub fn iter(&self) -> EnumSetIterator<E> { - EnumSetIterator::new(self.bits) + pub fn iter(&self) -> Items<E> { + Items::new(self.bits) } } @@ -101,18 +101,18 @@ impl<E:CLike> BitAnd<EnumSet<E>, EnumSet<E>> for EnumSet<E> { } /// An iterator over an EnumSet -pub struct EnumSetIterator<E> { +pub struct Items<E> { priv index: uint, priv bits: uint, } -impl<E:CLike> EnumSetIterator<E> { - fn new(bits: uint) -> EnumSetIterator<E> { - EnumSetIterator { index: 0, bits: bits } +impl<E:CLike> Items<E> { + fn new(bits: uint) -> Items<E> { + Items { index: 0, bits: bits } } } -impl<E:CLike> Iterator<E> for EnumSetIterator<E> { +impl<E:CLike> Iterator<E> for Items<E> { fn next(&mut self) -> Option<E> { if (self.bits == 0) { return None; diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs index d54ff7e2914..d4d0a7b89f0 100644 --- a/src/libextra/glob.rs +++ b/src/libextra/glob.rs @@ -11,7 +11,7 @@ /*! * Support for matching file paths against Unix shell style patterns. * - * The `glob` and `glob_with` functions, in concert with the `GlobIterator` + * The `glob` and `glob_with` functions, in concert with the `Paths` * type, allow querying the filesystem for all files that match a particular * pattern - just like the libc `glob` function (for an example see the `glob` * documentation). The methods on the `Pattern` type provide functionality @@ -32,7 +32,7 @@ use std::path::is_sep; * An iterator that yields Paths from the filesystem that match a particular * pattern - see the `glob` function for more details. */ -pub struct GlobIterator { +pub struct Paths { priv root: Path, priv dir_patterns: ~[Pattern], priv options: MatchOptions, @@ -67,7 +67,7 @@ pub struct GlobIterator { /// /media/pictures/puppies.jpg /// ``` /// -pub fn glob(pattern: &str) -> GlobIterator { +pub fn glob(pattern: &str) -> Paths { glob_with(pattern, MatchOptions::new()) } @@ -82,7 +82,7 @@ pub fn glob(pattern: &str) -> GlobIterator { * * Paths are yielded in alphabetical order, as absolute paths. */ -pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator { +pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths { #[cfg(windows)] fn check_windows_verbatim(p: &Path) -> bool { path::windows::is_verbatim(p) } #[cfg(not(windows))] @@ -95,7 +95,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator { if check_windows_verbatim(pat_root.get_ref()) { // XXX: How do we want to handle verbatim paths? I'm inclined to return nothing, // since we can't very well find all UNC shares with a 1-letter server name. - return GlobIterator { root: root, dir_patterns: ~[], options: options, todo: ~[] }; + return Paths { root: root, dir_patterns: ~[], options: options, todo: ~[] }; } root.push(pat_root.get_ref()); } @@ -106,7 +106,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator { let todo = list_dir_sorted(&root).move_iter().map(|x|(x,0u)).to_owned_vec(); - GlobIterator { + Paths { root: root, dir_patterns: dir_patterns, options: options, @@ -114,7 +114,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator { } } -impl Iterator<Path> for GlobIterator { +impl Iterator<Path> for Paths { fn next(&mut self) -> Option<Path> { loop { diff --git a/src/libextra/priority_queue.rs b/src/libextra/priority_queue.rs index bba7d767732..cf3c265e3fb 100644 --- a/src/libextra/priority_queue.rs +++ b/src/libextra/priority_queue.rs @@ -36,8 +36,8 @@ impl<T:Ord> Mutable for PriorityQueue<T> { impl<T:Ord> PriorityQueue<T> { /// An iterator visiting all values in underlying vector, in /// arbitrary order. - pub fn iter<'a>(&'a self) -> PriorityQueueIterator<'a, T> { - PriorityQueueIterator { iter: self.data.iter() } + pub fn iter<'a>(&'a self) -> Items<'a, T> { + Items { iter: self.data.iter() } } /// Returns the greatest item in the queue - fails if empty @@ -177,11 +177,11 @@ impl<T:Ord> PriorityQueue<T> { } /// PriorityQueue iterator -pub struct PriorityQueueIterator <'a, T> { - priv iter: vec::VecIterator<'a, T>, +pub struct Items <'a, T> { + priv iter: vec::Items<'a, T>, } -impl<'a, T> Iterator<&'a T> for PriorityQueueIterator<'a, T> { +impl<'a, T> Iterator<&'a T> for Items<'a, T> { #[inline] fn next(&mut self) -> Option<(&'a T)> { self.iter.next() } diff --git a/src/libextra/ringbuf.rs b/src/libextra/ringbuf.rs index da49f2372f4..c5c8f69dc65 100644 --- a/src/libextra/ringbuf.rs +++ b/src/libextra/ringbuf.rs @@ -187,17 +187,17 @@ impl<T> RingBuf<T> { } /// Front-to-back iterator. - pub fn iter<'a>(&'a self) -> RingBufIterator<'a, T> { - RingBufIterator{index: 0, rindex: self.nelts, lo: self.lo, elts: self.elts} + pub fn iter<'a>(&'a self) -> Items<'a, T> { + Items{index: 0, rindex: self.nelts, lo: self.lo, elts: self.elts} } /// Back-to-front iterator. - pub fn rev_iter<'a>(&'a self) -> Invert<RingBufIterator<'a, T>> { + pub fn rev_iter<'a>(&'a self) -> Invert<Items<'a, T>> { self.iter().invert() } /// Front-to-back iterator which returns mutable values. - pub fn mut_iter<'a>(&'a mut self) -> RingBufMutIterator<'a, T> { + pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> { let start_index = raw_index(self.lo, self.elts.len(), 0); let end_index = raw_index(self.lo, self.elts.len(), self.nelts); @@ -209,34 +209,34 @@ impl<T> RingBuf<T> { // 0 to end_index let (temp, remaining1) = self.elts.mut_split_at(start_index); let (remaining2, _) = temp.mut_split_at(end_index); - RingBufMutIterator { remaining1: remaining1, + MutItems { remaining1: remaining1, remaining2: remaining2, nelts: self.nelts } } else { // Items to iterate goes from start_index to end_index: let (empty, elts) = self.elts.mut_split_at(0); let remaining1 = elts.mut_slice(start_index, end_index); - RingBufMutIterator { remaining1: remaining1, + MutItems { remaining1: remaining1, remaining2: empty, nelts: self.nelts } } } /// Back-to-front iterator which returns mutable values. - pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<RingBufMutIterator<'a, T>> { + pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutItems<'a, T>> { self.mut_iter().invert() } } /// RingBuf iterator -pub struct RingBufIterator<'a, T> { +pub struct Items<'a, T> { priv lo: uint, priv index: uint, priv rindex: uint, priv elts: &'a [Option<T>], } -impl<'a, T> Iterator<&'a T> for RingBufIterator<'a, T> { +impl<'a, T> Iterator<&'a T> for Items<'a, T> { #[inline] fn next(&mut self) -> Option<&'a T> { if self.index == self.rindex { @@ -254,7 +254,7 @@ impl<'a, T> Iterator<&'a T> for RingBufIterator<'a, T> { } } -impl<'a, T> DoubleEndedIterator<&'a T> for RingBufIterator<'a, T> { +impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { if self.index == self.rindex { @@ -266,9 +266,9 @@ impl<'a, T> DoubleEndedIterator<&'a T> for RingBufIterator<'a, T> { } } -impl<'a, T> ExactSize<&'a T> for RingBufIterator<'a, T> {} +impl<'a, T> ExactSize<&'a T> for Items<'a, T> {} -impl<'a, T> RandomAccessIterator<&'a T> for RingBufIterator<'a, T> { +impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> { #[inline] fn indexable(&self) -> uint { self.rindex - self.index } @@ -284,13 +284,13 @@ impl<'a, T> RandomAccessIterator<&'a T> for RingBufIterator<'a, T> { } /// RingBuf mutable iterator -pub struct RingBufMutIterator<'a, T> { +pub struct MutItems<'a, T> { priv remaining1: &'a mut [Option<T>], priv remaining2: &'a mut [Option<T>], priv nelts: uint, } -impl<'a, T> Iterator<&'a mut T> for RingBufMutIterator<'a, T> { +impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut T> { if self.nelts == 0 { @@ -312,7 +312,7 @@ impl<'a, T> Iterator<&'a mut T> for RingBufMutIterator<'a, T> { } } -impl<'a, T> DoubleEndedIterator<&'a mut T> for RingBufMutIterator<'a, T> { +impl<'a, T> DoubleEndedIterator<&'a mut T> for MutItems<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut T> { if self.nelts == 0 { @@ -329,7 +329,7 @@ impl<'a, T> DoubleEndedIterator<&'a mut T> for RingBufMutIterator<'a, T> { } } -impl<'a, T> ExactSize<&'a mut T> for RingBufMutIterator<'a, T> {} +impl<'a, T> ExactSize<&'a mut T> for MutItems<'a, T> {} /// Grow is only called on full elts, so nelts is also len(elts), unlike /// elsewhere. diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index 649ed281f87..93d138a9d46 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -17,7 +17,6 @@ use std::iter::{Enumerate, FilterMap, Invert}; use std::util::replace; -use std::vec::{VecIterator, VecMutIterator}; use std::vec; #[allow(missing_doc)] @@ -119,8 +118,8 @@ impl<V> SmallIntMap<V> { /// An iterator visiting all key-value pairs in ascending order by the keys. /// Iterator element type is (uint, &'r V) - pub fn iter<'r>(&'r self) -> SmallIntMapIterator<'r, V> { - SmallIntMapIterator { + pub fn iter<'r>(&'r self) -> Entries<'r, V> { + Entries { front: 0, back: self.v.len(), iter: self.v.iter() @@ -130,8 +129,8 @@ impl<V> SmallIntMap<V> { /// An iterator visiting all key-value pairs in ascending order by the keys, /// with mutable references to the values /// Iterator element type is (uint, &'r mut V) - pub fn mut_iter<'r>(&'r mut self) -> SmallIntMapMutIterator<'r, V> { - SmallIntMapMutIterator { + pub fn mut_iter<'r>(&'r mut self) -> MutEntries<'r, V> { + MutEntries { front: 0, back: self.v.len(), iter: self.v.mut_iter() @@ -140,21 +139,21 @@ impl<V> SmallIntMap<V> { /// An iterator visiting all key-value pairs in descending order by the keys. /// Iterator element type is (uint, &'r V) - pub fn rev_iter<'r>(&'r self) -> SmallIntMapRevIterator<'r, V> { + pub fn rev_iter<'r>(&'r self) -> RevEntries<'r, V> { self.iter().invert() } /// An iterator visiting all key-value pairs in descending order by the keys, /// with mutable references to the values /// Iterator element type is (uint, &'r mut V) - pub fn mut_rev_iter<'r>(&'r mut self) -> SmallIntMapMutRevIterator <'r, V> { + pub fn mut_rev_iter<'r>(&'r mut self) -> RevMutEntries <'r, V> { self.mut_iter().invert() } /// Empties the hash map, moving all values into the specified closure pub fn move_iter(&mut self) -> FilterMap<(uint, Option<V>), (uint, V), - Enumerate<vec::MoveIterator<Option<V>>>> + Enumerate<vec::MoveItems<Option<V>>>> { let values = replace(&mut self.v, ~[]); values.move_iter().enumerate().filter_map(|(i, v)| { @@ -234,25 +233,25 @@ macro_rules! double_ended_iterator { } } -pub struct SmallIntMapIterator<'a, T> { +pub struct Entries<'a, T> { priv front: uint, priv back: uint, - priv iter: VecIterator<'a, Option<T>> + priv iter: vec::Items<'a, Option<T>> } -iterator!(impl SmallIntMapIterator -> (uint, &'a T), get_ref) -double_ended_iterator!(impl SmallIntMapIterator -> (uint, &'a T), get_ref) -pub type SmallIntMapRevIterator<'a, T> = Invert<SmallIntMapIterator<'a, T>>; +iterator!(impl Entries -> (uint, &'a T), get_ref) +double_ended_iterator!(impl Entries -> (uint, &'a T), get_ref) +pub type RevEntries<'a, T> = Invert<Entries<'a, T>>; -pub struct SmallIntMapMutIterator<'a, T> { +pub struct MutEntries<'a, T> { priv front: uint, priv back: uint, - priv iter: VecMutIterator<'a, Option<T>> + priv iter: vec::MutItems<'a, Option<T>> } -iterator!(impl SmallIntMapMutIterator -> (uint, &'a mut T), get_mut_ref) -double_ended_iterator!(impl SmallIntMapMutIterator -> (uint, &'a mut T), get_mut_ref) -pub type SmallIntMapMutRevIterator<'a, T> = Invert<SmallIntMapMutIterator<'a, T>>; +iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref) +double_ended_iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref) +pub type RevMutEntries<'a, T> = Invert<MutEntries<'a, T>>; #[cfg(test)] mod test_map { diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 8f1bd3a9df1..7b8258ec5ae 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -137,8 +137,8 @@ impl<K: TotalOrd, V> TreeMap<K, V> { /// Get a lazy iterator over the key-value pairs in the map. /// Requires that it be frozen (immutable). - pub fn iter<'a>(&'a self) -> TreeMapIterator<'a, K, V> { - TreeMapIterator { + pub fn iter<'a>(&'a self) -> Entries<'a, K, V> { + Entries { stack: ~[], node: deref(&self.root), remaining_min: self.length, @@ -148,14 +148,14 @@ impl<K: TotalOrd, V> TreeMap<K, V> { /// Get a lazy reverse iterator over the key-value pairs in the map. /// Requires that it be frozen (immutable). - pub fn rev_iter<'a>(&'a self) -> TreeMapRevIterator<'a, K, V> { - TreeMapRevIterator{iter: self.iter()} + pub fn rev_iter<'a>(&'a self) -> RevEntries<'a, K, V> { + RevEntries{iter: self.iter()} } /// Get a lazy forward iterator over the key-value pairs in the /// map, with the values being mutable. - pub fn mut_iter<'a>(&'a mut self) -> TreeMapMutIterator<'a, K, V> { - TreeMapMutIterator { + pub fn mut_iter<'a>(&'a mut self) -> MutEntries<'a, K, V> { + MutEntries { stack: ~[], node: mut_deref(&mut self.root), remaining_min: self.length, @@ -164,19 +164,19 @@ impl<K: TotalOrd, V> TreeMap<K, V> { } /// Get a lazy reverse iterator over the key-value pairs in the /// map, with the values being mutable. - pub fn mut_rev_iter<'a>(&'a mut self) -> TreeMapMutRevIterator<'a, K, V> { - TreeMapMutRevIterator{iter: self.mut_iter()} + pub fn mut_rev_iter<'a>(&'a mut self) -> RevMutEntries<'a, K, V> { + RevMutEntries{iter: self.mut_iter()} } /// Get a lazy iterator that consumes the treemap. - pub fn move_iter(self) -> TreeMapMoveIterator<K, V> { + pub fn move_iter(self) -> MoveEntries<K, V> { let TreeMap { root: root, length: length } = self; let stk = match root { None => ~[], Some(~tn) => ~[tn] }; - TreeMapMoveIterator { + MoveEntries { stack: stk, remaining: length } @@ -220,8 +220,8 @@ macro_rules! bound_setup { impl<K: TotalOrd, V> TreeMap<K, V> { /// Get a lazy iterator that should be initialized using /// `traverse_left`/`traverse_right`/`traverse_complete`. - fn iter_for_traversal<'a>(&'a self) -> TreeMapIterator<'a, K, V> { - TreeMapIterator { + fn iter_for_traversal<'a>(&'a self) -> Entries<'a, K, V> { + Entries { stack: ~[], node: deref(&self.root), remaining_min: 0, @@ -231,20 +231,20 @@ impl<K: TotalOrd, V> TreeMap<K, V> { /// Return a lazy iterator to the first key-value pair whose key is not less than `k` /// If all keys in map are less than `k` an empty iterator is returned. - pub fn lower_bound<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> { + pub fn lower_bound<'a>(&'a self, k: &K) -> Entries<'a, K, V> { bound_setup!(self.iter_for_traversal(), true) } /// Return a lazy iterator to the first key-value pair whose key is greater than `k` /// If all keys in map are not greater than `k` an empty iterator is returned. - pub fn upper_bound<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> { + pub fn upper_bound<'a>(&'a self, k: &K) -> Entries<'a, K, V> { bound_setup!(self.iter_for_traversal(), false) } /// Get a lazy iterator that should be initialized using /// `traverse_left`/`traverse_right`/`traverse_complete`. - fn mut_iter_for_traversal<'a>(&'a mut self) -> TreeMapMutIterator<'a, K, V> { - TreeMapMutIterator { + fn mut_iter_for_traversal<'a>(&'a mut self) -> MutEntries<'a, K, V> { + MutEntries { stack: ~[], node: mut_deref(&mut self.root), remaining_min: 0, @@ -257,7 +257,7 @@ impl<K: TotalOrd, V> TreeMap<K, V> { /// /// If all keys in map are less than `k` an empty iterator is /// returned. - pub fn mut_lower_bound<'a>(&'a mut self, k: &K) -> TreeMapMutIterator<'a, K, V> { + pub fn mut_lower_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> { bound_setup!(self.mut_iter_for_traversal(), true) } @@ -266,15 +266,15 @@ impl<K: TotalOrd, V> TreeMap<K, V> { /// /// If all keys in map are not greater than `k` an empty iterator /// is returned. - pub fn mut_upper_bound<'a>(&'a mut self, k: &K) -> TreeMapMutIterator<'a, K, V> { + pub fn mut_upper_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> { bound_setup!(self.mut_iter_for_traversal(), false) } } /// Lazy forward iterator over a map -pub struct TreeMapIterator<'a, K, V> { +pub struct Entries<'a, K, V> { priv stack: ~[&'a TreeNode<K, V>], - // See the comment on TreeMapMutIterator; this is just to allow + // See the comment on MutEntries; this is just to allow // code-sharing (for this immutable-values iterator it *could* very // well be Option<&'a TreeNode<K,V>>). priv node: *TreeNode<K, V>, @@ -283,13 +283,13 @@ pub struct TreeMapIterator<'a, K, V> { } /// Lazy backward iterator over a map -pub struct TreeMapRevIterator<'a, K, V> { - priv iter: TreeMapIterator<'a, K, V>, +pub struct RevEntries<'a, K, V> { + priv iter: Entries<'a, K, V>, } /// Lazy forward iterator over a map that allows for the mutation of /// the values. -pub struct TreeMapMutIterator<'a, K, V> { +pub struct MutEntries<'a, K, V> { priv stack: ~[&'a mut TreeNode<K, V>], // Unfortunately, we require some unsafe-ness to get around the // fact that we would be storing a reference *into* one of the @@ -316,8 +316,8 @@ pub struct TreeMapMutIterator<'a, K, V> { } /// Lazy backward iterator over a map -pub struct TreeMapMutRevIterator<'a, K, V> { - priv iter: TreeMapMutIterator<'a, K, V>, +pub struct RevMutEntries<'a, K, V> { + priv iter: MutEntries<'a, K, V>, } @@ -377,13 +377,13 @@ macro_rules! define_iterator { } /// traverse_left, traverse_right and traverse_complete are - /// used to initialize TreeMapIterator/TreeMapMutIterator + /// used to initialize Entries/MutEntries /// pointing to element inside tree structure. /// /// They should be used in following manner: /// - create iterator using TreeMap::[mut_]iter_for_traversal /// - find required node using `traverse_left`/`traverse_right` - /// (current node is `TreeMapIterator::node` field) + /// (current node is `Entries::node` field) /// - complete initialization with `traverse_complete` /// /// After this, iteration will start from `self.node`. If @@ -443,16 +443,16 @@ macro_rules! define_iterator { } // end of define_iterator define_iterator! { - TreeMapIterator, - TreeMapRevIterator, + Entries, + RevEntries, deref = deref, // immutable, so no mut addr_mut = } define_iterator! { - TreeMapMutIterator, - TreeMapMutRevIterator, + MutEntries, + RevMutEntries, deref = mut_deref, addr_mut = mut @@ -481,12 +481,12 @@ fn mut_deref<K, V>(x: &mut Option<~TreeNode<K, V>>) -> *mut TreeNode<K, V> { /// Lazy forward iterator over a map that consumes the map while iterating -pub struct TreeMapMoveIterator<K, V> { +pub struct MoveEntries<K, V> { priv stack: ~[TreeNode<K, V>], priv remaining: uint } -impl<K, V> Iterator<(K, V)> for TreeMapMoveIterator<K,V> { +impl<K, V> Iterator<(K, V)> for MoveEntries<K,V> { #[inline] fn next(&mut self) -> Option<(K, V)> { while !self.stack.is_empty() { @@ -530,7 +530,7 @@ impl<K, V> Iterator<(K, V)> for TreeMapMoveIterator<K,V> { } -impl<'a, T> Iterator<&'a T> for TreeSetIterator<'a, T> { +impl<'a, T> Iterator<&'a T> for SetItems<'a, T> { /// Advance the iterator to the next node (in order). If there are no more nodes, return `None`. #[inline] fn next(&mut self) -> Option<&'a T> { @@ -538,7 +538,7 @@ impl<'a, T> Iterator<&'a T> for TreeSetIterator<'a, T> { } } -impl<'a, T> Iterator<&'a T> for TreeSetRevIterator<'a, T> { +impl<'a, T> Iterator<&'a T> for RevSetItems<'a, T> { /// Advance the iterator to the next node (in order). If there are no more nodes, return `None`. #[inline] fn next(&mut self) -> Option<&'a T> { @@ -653,86 +653,86 @@ impl<T: TotalOrd> TreeSet<T> { /// Get a lazy iterator over the values in the set. /// Requires that it be frozen (immutable). #[inline] - pub fn iter<'a>(&'a self) -> TreeSetIterator<'a, T> { - TreeSetIterator{iter: self.map.iter()} + pub fn iter<'a>(&'a self) -> SetItems<'a, T> { + SetItems{iter: self.map.iter()} } /// Get a lazy iterator over the values in the set. /// Requires that it be frozen (immutable). #[inline] - pub fn rev_iter<'a>(&'a self) -> TreeSetRevIterator<'a, T> { - TreeSetRevIterator{iter: self.map.rev_iter()} + pub fn rev_iter<'a>(&'a self) -> RevSetItems<'a, T> { + RevSetItems{iter: self.map.rev_iter()} } /// Get a lazy iterator pointing to the first value not less than `v` (greater or equal). /// If all elements in the set are less than `v` empty iterator is returned. #[inline] - pub fn lower_bound<'a>(&'a self, v: &T) -> TreeSetIterator<'a, T> { - TreeSetIterator{iter: self.map.lower_bound(v)} + pub fn lower_bound<'a>(&'a self, v: &T) -> SetItems<'a, T> { + SetItems{iter: self.map.lower_bound(v)} } /// Get a lazy iterator pointing to the first value greater than `v`. /// If all elements in the set are not greater than `v` empty iterator is returned. #[inline] - pub fn upper_bound<'a>(&'a self, v: &T) -> TreeSetIterator<'a, T> { - TreeSetIterator{iter: self.map.upper_bound(v)} + pub fn upper_bound<'a>(&'a self, v: &T) -> SetItems<'a, T> { + SetItems{iter: self.map.upper_bound(v)} } /// Visit the values (in-order) representing the difference - pub fn difference<'a>(&'a self, other: &'a TreeSet<T>) -> Difference<'a, T> { - Difference{a: self.iter().peekable(), b: other.iter().peekable()} + pub fn difference<'a>(&'a self, other: &'a TreeSet<T>) -> DifferenceItems<'a, T> { + DifferenceItems{a: self.iter().peekable(), b: other.iter().peekable()} } /// Visit the values (in-order) representing the symmetric difference pub fn symmetric_difference<'a>(&'a self, other: &'a TreeSet<T>) - -> SymDifference<'a, T> { - SymDifference{a: self.iter().peekable(), b: other.iter().peekable()} + -> SymDifferenceItems<'a, T> { + SymDifferenceItems{a: self.iter().peekable(), b: other.iter().peekable()} } /// Visit the values (in-order) representing the intersection pub fn intersection<'a>(&'a self, other: &'a TreeSet<T>) - -> Intersection<'a, T> { - Intersection{a: self.iter().peekable(), b: other.iter().peekable()} + -> IntersectionItems<'a, T> { + IntersectionItems{a: self.iter().peekable(), b: other.iter().peekable()} } /// Visit the values (in-order) representing the union - pub fn union<'a>(&'a self, other: &'a TreeSet<T>) -> Union<'a, T> { - Union{a: self.iter().peekable(), b: other.iter().peekable()} + pub fn union<'a>(&'a self, other: &'a TreeSet<T>) -> UnionItems<'a, T> { + UnionItems{a: self.iter().peekable(), b: other.iter().peekable()} } } /// Lazy forward iterator over a set -pub struct TreeSetIterator<'a, T> { - priv iter: TreeMapIterator<'a, T, ()> +pub struct SetItems<'a, T> { + priv iter: Entries<'a, T, ()> } /// Lazy backward iterator over a set -pub struct TreeSetRevIterator<'a, T> { - priv iter: TreeMapRevIterator<'a, T, ()> +pub struct RevSetItems<'a, T> { + priv iter: RevEntries<'a, T, ()> } /// Lazy iterator producing elements in the set difference (in-order) -pub struct Difference<'a, T> { - priv a: Peekable<&'a T, TreeSetIterator<'a, T>>, - priv b: Peekable<&'a T, TreeSetIterator<'a, T>>, +pub struct DifferenceItems<'a, T> { + priv a: Peekable<&'a T, SetItems<'a, T>>, + priv b: Peekable<&'a T, SetItems<'a, T>>, } /// Lazy iterator producing elements in the set symmetric difference (in-order) -pub struct SymDifference<'a, T> { - priv a: Peekable<&'a T, TreeSetIterator<'a, T>>, - priv b: Peekable<&'a T, TreeSetIterator<'a, T>>, +pub struct SymDifferenceItems<'a, T> { + priv a: Peekable<&'a T, SetItems<'a, T>>, + priv b: Peekable<&'a T, SetItems<'a, T>>, } /// Lazy iterator producing elements in the set intersection (in-order) -pub struct Intersection<'a, T> { - priv a: Peekable<&'a T, TreeSetIterator<'a, T>>, - priv b: Peekable<&'a T, TreeSetIterator<'a, T>>, +pub struct IntersectionItems<'a, T> { + priv a: Peekable<&'a T, SetItems<'a, T>>, + priv b: Peekable<&'a T, SetItems<'a, T>>, } /// Lazy iterator producing elements in the set intersection (in-order) -pub struct Union<'a, T> { - priv a: Peekable<&'a T, TreeSetIterator<'a, T>>, - priv b: Peekable<&'a T, TreeSetIterator<'a, T>>, +pub struct UnionItems<'a, T> { + priv a: Peekable<&'a T, SetItems<'a, T>>, + priv b: Peekable<&'a T, SetItems<'a, T>>, } /// Compare `x` and `y`, but return `short` if x is None and `long` if y is None @@ -745,7 +745,7 @@ fn cmp_opt<T: TotalOrd>(x: Option<&T>, y: Option<&T>, } } -impl<'a, T: TotalOrd> Iterator<&'a T> for Difference<'a, T> { +impl<'a, T: TotalOrd> Iterator<&'a T> for DifferenceItems<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { match cmp_opt(self.a.peek(), self.b.peek(), Less, Less) { @@ -757,7 +757,7 @@ impl<'a, T: TotalOrd> Iterator<&'a T> for Difference<'a, T> { } } -impl<'a, T: TotalOrd> Iterator<&'a T> for SymDifference<'a, T> { +impl<'a, T: TotalOrd> Iterator<&'a T> for SymDifferenceItems<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { match cmp_opt(self.a.peek(), self.b.peek(), Greater, Less) { @@ -769,7 +769,7 @@ impl<'a, T: TotalOrd> Iterator<&'a T> for SymDifference<'a, T> { } } -impl<'a, T: TotalOrd> Iterator<&'a T> for Intersection<'a, T> { +impl<'a, T: TotalOrd> Iterator<&'a T> for IntersectionItems<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { let o_cmp = match (self.a.peek(), self.b.peek()) { @@ -787,7 +787,7 @@ impl<'a, T: TotalOrd> Iterator<&'a T> for Intersection<'a, T> { } } -impl<'a, T: TotalOrd> Iterator<&'a T> for Union<'a, T> { +impl<'a, T: TotalOrd> Iterator<&'a T> for UnionItems<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { match cmp_opt(self.a.peek(), self.b.peek(), Greater, Less) { |
