Skip to content

Commit 808b523

Browse files
artagnonemberian
authored andcommitted
treemap: remove .each in favor of .iter().advance
Both extra::treemap::TreeMap and extra::treemap::TreeSet have corresponding iterators TreeMapIterator and TreeSetIterator. Unfortunately, the tests and extra::serialize use the older .each. Update all the dependent code, and remove .each. Signed-off-by: Ramkumar Ramachandra <[email protected]>
1 parent 82fa5b6 commit 808b523

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/libextra/serialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl<
832832
fn encode(&self, e: &mut E) {
833833
do e.emit_map(self.len()) |e| {
834834
let mut i = 0;
835-
for self.each |key, val| {
835+
for self.iter().advance |(key, val)| {
836836
e.emit_map_elt_key(i, |e| key.encode(e));
837837
e.emit_map_elt_val(i, |e| val.encode(e));
838838
i += 1;
@@ -866,7 +866,7 @@ impl<
866866
fn encode(&self, s: &mut S) {
867867
do s.emit_seq(self.len()) |s| {
868868
let mut i = 0;
869-
for self.each |e| {
869+
for self.iter().advance |e| {
870870
s.emit_seq_elt(i, |s| e.encode(s));
871871
i += 1;
872872
}

src/libextra/treemap.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,14 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
164164
/// Create an empty TreeMap
165165
pub fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
166166

167-
/// Visit all key-value pairs in order
168-
pub fn each<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
169-
each(&self.root, f)
170-
}
171-
172167
/// Visit all keys in order
173168
pub fn each_key(&self, f: &fn(&K) -> bool) -> bool {
174-
self.each(|k, _| f(k))
169+
self.iter().advance(|(k, _)| f(k))
175170
}
176171

177172
/// Visit all values in order
178173
pub fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool {
179-
self.each(|_, v| f(v))
174+
self.iter().advance(|(_, v)| f(v))
180175
}
181176

182177
/// Iterate over the map and mutate the contained values
@@ -484,10 +479,6 @@ impl<T: TotalOrd> TreeSet<T> {
484479
TreeSetIterator{iter: self.map.iter()}
485480
}
486481

487-
/// Visit all values in order
488-
#[inline]
489-
pub fn each(&self, f: &fn(&T) -> bool) -> bool { self.map.each_key(f) }
490-
491482
/// Visit all values in reverse order
492483
#[inline]
493484
pub fn each_reverse(&self, f: &fn(&T) -> bool) -> bool {
@@ -779,7 +770,7 @@ mod test_treemap {
779770
let &(k, v) = x;
780771
assert!(map.find(&k).unwrap() == &v)
781772
}
782-
for map.each |map_k, map_v| {
773+
for map.iter().advance |(map_k, map_v)| {
783774
let mut found = false;
784775
for ctrl.iter().advance |x| {
785776
let &(ctrl_k, ctrl_v) = x;
@@ -885,7 +876,7 @@ mod test_treemap {
885876
}
886877

887878
#[test]
888-
fn test_each() {
879+
fn test_iterator() {
889880
let mut m = TreeMap::new();
890881

891882
assert!(m.insert(3, 6));
@@ -895,7 +886,7 @@ mod test_treemap {
895886
assert!(m.insert(1, 2));
896887

897888
let mut n = 0;
898-
for m.each |k, v| {
889+
for m.iter().advance |(k, v)| {
899890
assert_eq!(*k, n);
900891
assert_eq!(*v, n * 2);
901892
n += 1;
@@ -1090,7 +1081,7 @@ mod test_set {
10901081
}
10911082

10921083
#[test]
1093-
fn test_each() {
1084+
fn test_iterator() {
10941085
let mut m = TreeSet::new();
10951086

10961087
assert!(m.insert(3));
@@ -1100,7 +1091,7 @@ mod test_set {
11001091
assert!(m.insert(1));
11011092

11021093
let mut n = 0;
1103-
for m.each |x| {
1094+
for m.iter().advance |x| {
11041095
println(fmt!("%?", x));
11051096
assert_eq!(*x, n);
11061097
n += 1

0 commit comments

Comments
 (0)