]> git.lizzy.rs Git - rust.git/commitdiff
std::trie: remove some obsolete internal iterators.
authorHuon Wilson <dbau.pp+github@gmail.com>
Mon, 6 Jan 2014 13:17:38 +0000 (00:17 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Tue, 7 Jan 2014 13:31:24 +0000 (00:31 +1100)
src/libextra/serialize.rs
src/libstd/trie.rs

index e7ccb91fb752b0ec376ac404cb879a95d1c8481c..59f7f2a2ffcb1d8d3564b8dd8a2c1d0628722719 100644 (file)
@@ -768,14 +768,11 @@ impl<
 > Encodable<E> for TrieMap<V> {
     fn encode(&self, e: &mut E) {
         e.emit_map(self.len(), |e| {
-            let mut i = 0;
-            self.each(|key, val| {
-                e.emit_map_elt_key(i, |e| key.encode(e));
-                e.emit_map_elt_val(i, |e| val.encode(e));
-                i += 1;
-                true
+                for (i, (key, val)) in self.iter().enumerate() {
+                    e.emit_map_elt_key(i, |e| key.encode(e));
+                    e.emit_map_elt_val(i, |e| val.encode(e));
+                }
             });
-        })
     }
 }
 
@@ -799,13 +796,10 @@ fn decode(d: &mut D) -> TrieMap<V> {
 impl<S: Encoder> Encodable<S> for TrieSet {
     fn encode(&self, s: &mut S) {
         s.emit_seq(self.len(), |s| {
-            let mut i = 0;
-            self.each(|e| {
-                s.emit_seq_elt(i, |s| e.encode(s));
-                i += 1;
-                true
-            });
-        })
+                for (i, e) in self.iter().enumerate() {
+                    s.emit_seq_elt(i, |s| e.encode(s));
+                }
+            })
     }
 }
 
index b66472c72cb7d6338ff6b96a112841b3057f5449..08805c88c7bf54155b669b44a17396966faa174a 100644 (file)
@@ -111,30 +111,6 @@ pub fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
         self.root.each_reverse(f)
     }
 
-    /// Visit all key-value pairs in order
-    #[inline]
-    pub fn each<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
-        self.root.each(f)
-    }
-
-    /// Visit all keys in order
-    #[inline]
-    pub fn each_key(&self, f: |&uint| -> bool) -> bool {
-        self.each(|k, _| f(k))
-    }
-
-    /// Visit all values in order
-    #[inline]
-    pub fn each_value<'a>(&'a self, f: |&'a T| -> bool) -> bool {
-        self.each(|_, v| f(v))
-    }
-
-    /// Iterate over the map and mutate the contained values
-    #[inline]
-    pub fn mutate_values(&mut self, f: |&uint, &mut T| -> bool) -> bool {
-        self.root.mutate_values(f)
-    }
-
     /// Visit all keys in reverse order
     #[inline]
     pub fn each_key_reverse(&self, f: |&uint| -> bool) -> bool {
@@ -331,10 +307,6 @@ pub fn remove(&mut self, value: &uint) -> bool {
         self.map.remove(value)
     }
 
-    /// Visit all values in order
-    #[inline]
-    pub fn each(&self, f: |&uint| -> bool) -> bool { self.map.each_key(f) }
-
     /// Visit all values in reverse order
     #[inline]
     pub fn each_reverse(&self, f: |&uint| -> bool) -> bool {
@@ -395,17 +367,6 @@ fn new() -> TrieNode<T> {
 }
 
 impl<T> TrieNode<T> {
-    fn each<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
-        for elt in self.children.iter() {
-            match *elt {
-                Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false },
-                External(k, ref v) => if !f(&k, v) { return false },
-                Nothing => ()
-            }
-        }
-        true
-    }
-
     fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
         for elt in self.children.rev_iter() {
             match *elt {
@@ -416,19 +377,6 @@ fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
         }
         true
     }
-
-    fn mutate_values<'a>(&'a mut self, f: |&uint, &mut T| -> bool) -> bool {
-        for child in self.children.mut_iter() {
-            match *child {
-                Internal(ref mut x) => if !x.mutate_values(|i,t| f(i,t)) {
-                    return false
-                },
-                External(k, ref mut v) => if !f(&k, v) { return false },
-                Nothing => ()
-            }
-        }
-        true
-    }
 }
 
 // if this was done via a trait, the key could be generic
@@ -691,46 +639,6 @@ fn test_step() {
         }
     }
 
-    #[test]
-    fn test_each() {
-        let mut m = TrieMap::new();
-
-        assert!(m.insert(3, 6));
-        assert!(m.insert(0, 0));
-        assert!(m.insert(4, 8));
-        assert!(m.insert(2, 4));
-        assert!(m.insert(1, 2));
-
-        let mut n = 0;
-        m.each(|k, v| {
-            assert_eq!(*k, n);
-            assert_eq!(*v, n * 2);
-            n += 1;
-            true
-        });
-    }
-
-    #[test]
-    fn test_each_break() {
-        let mut m = TrieMap::new();
-
-        for x in range(uint::max_value - 10000, uint::max_value).invert() {
-            m.insert(x, x / 2);
-        }
-
-        let mut n = uint::max_value - 10000;
-        m.each(|k, v| {
-            if n == uint::max_value - 5000 { false } else {
-                assert!(n < uint::max_value - 5000);
-
-                assert_eq!(*k, n);
-                assert_eq!(*v, n / 2);
-                n += 1;
-                true
-            }
-        });
-    }
-
     #[test]
     fn test_each_reverse() {
         let mut m = TrieMap::new();
@@ -943,13 +851,9 @@ fn test_sane_chunk() {
 
         let expected = [x, y];
 
-        let mut i = 0;
-
-        trie.each(|x| {
-            assert_eq!(expected[i], *x);
-            i += 1;
-            true
-        });
+        for (i, x) in trie.iter().enumerate() {
+            assert_eq!(expected[i], x);
+        }
     }
 
     #[test]