|
14 | 14 |
|
15 | 15 | use core::container::{Container, Mutable, Map, Set};
|
16 | 16 | use core::cmp::{Eq, Ord};
|
| 17 | +use core::iter::{BaseIter, ReverseIter}; |
17 | 18 | use core::option::{Option, Some, None};
|
18 | 19 | use core::prelude::*;
|
19 | 20 |
|
@@ -103,14 +104,21 @@ impl <K: Ord, V> TreeMap<K, V>: Ord {
|
103 | 104 | }
|
104 | 105 | }
|
105 | 106 |
|
106 |
| -impl <K: Ord, V> TreeMap<K, V>: iter::BaseIter<(&K, &V)> { |
| 107 | +impl <K: Ord, V> TreeMap<K, V>: BaseIter<(&K, &V)> { |
107 | 108 | /// Visit all key-value pairs in order
|
108 | 109 | pure fn each(&self, f: fn(&(&self/K, &self/V)) -> bool) {
|
109 | 110 | each(&self.root, f)
|
110 | 111 | }
|
111 | 112 | pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
112 | 113 | }
|
113 | 114 |
|
| 115 | +impl <K: Ord, V> TreeMap<K, V>: ReverseIter<(&K, &V)> { |
| 116 | + /// Visit all key-value pairs in reverse order |
| 117 | + pure fn each_reverse(&self, f: fn(&(&self/K, &self/V)) -> bool) { |
| 118 | + each_reverse(&self.root, f); |
| 119 | + } |
| 120 | +} |
| 121 | + |
114 | 122 | impl <K: Ord, V> TreeMap<K, V>: Container {
|
115 | 123 | /// Return the number of elements in the map
|
116 | 124 | pure fn len(&self) -> uint { self.length }
|
@@ -180,11 +188,6 @@ impl <K: Ord, V> TreeMap<K, V> {
|
180 | 188 | /// Create an empty TreeMap
|
181 | 189 | static pure fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
|
182 | 190 |
|
183 |
| - /// Visit all key-value pairs in reverse order |
184 |
| - pure fn each_reverse(&self, f: fn(&(&self/K, &self/V)) -> bool) { |
185 |
| - each_reverse(&self.root, f); |
186 |
| - } |
187 |
| - |
188 | 191 | /// Visit all keys in reverse order
|
189 | 192 | pure fn each_key_reverse(&self, f: fn(&K) -> bool) {
|
190 | 193 | self.each_reverse(|&(k, _)| f(k))
|
@@ -243,12 +246,19 @@ pub struct TreeSet<T> {
|
243 | 246 | priv map: TreeMap<T, ()>
|
244 | 247 | }
|
245 | 248 |
|
246 |
| -impl <T: Ord> TreeSet<T>: iter::BaseIter<T> { |
| 249 | +impl <T: Ord> TreeSet<T>: BaseIter<T> { |
247 | 250 | /// Visit all values in order
|
248 | 251 | pure fn each(&self, f: fn(&T) -> bool) { self.map.each_key(f) }
|
249 | 252 | pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
250 | 253 | }
|
251 | 254 |
|
| 255 | +impl <T: Ord> TreeSet<T>: ReverseIter<T> { |
| 256 | + /// Visit all values in reverse order |
| 257 | + pure fn each_reverse(&self, f: fn(&T) -> bool) { |
| 258 | + self.map.each_key_reverse(f) |
| 259 | + } |
| 260 | +} |
| 261 | + |
252 | 262 | impl <T: Eq Ord> TreeSet<T>: Eq {
|
253 | 263 | pure fn eq(&self, other: &TreeSet<T>) -> bool { self.map == other.map }
|
254 | 264 | pure fn ne(&self, other: &TreeSet<T>) -> bool { self.map != other.map }
|
@@ -504,11 +514,6 @@ impl <T: Ord> TreeSet<T> {
|
504 | 514 | /// Create an empty TreeSet
|
505 | 515 | static pure fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} }
|
506 | 516 |
|
507 |
| - /// Visit all values in reverse order |
508 |
| - pure fn each_reverse(&self, f: fn(&T) -> bool) { |
509 |
| - self.map.each_key_reverse(f) |
510 |
| - } |
511 |
| - |
512 | 517 | /// Get a lazy iterator over the values in the set.
|
513 | 518 | /// Requires that it be frozen (immutable).
|
514 | 519 | pure fn iter(&self) -> TreeSetIterator/&self<T> {
|
|
0 commit comments