about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-06-24 17:45:00 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-06-25 16:26:23 -0400
commit64ee9668a2e3d4d75b859fd3bca1466a97fae2d8 (patch)
treed07261f531cff9b87d3418919267d0fa4a8b5ea0
parent5242e8d2bad01beec7c841d20952cb230bc9fd84 (diff)
downloadrust-64ee9668a2e3d4d75b859fd3bca1466a97fae2d8.tar.gz
rust-64ee9668a2e3d4d75b859fd3bca1466a97fae2d8.zip
container: remove internal iterators from Map
the maps are being migrated to external iterators
-rw-r--r--src/libextra/smallintmap.rs64
-rw-r--r--src/libextra/treemap.rs40
-rw-r--r--src/libstd/container.rs12
-rw-r--r--src/libstd/hashmap.rs56
-rw-r--r--src/libstd/trie.rs48
-rw-r--r--src/test/run-pass/class-impl-very-parameterized-trait.rs21
6 files changed, 104 insertions, 137 deletions
diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs
index 17126f0d32b..1d163922955 100644
--- a/src/libextra/smallintmap.rs
+++ b/src/libextra/smallintmap.rs
@@ -56,38 +56,6 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
         self.find(key).is_some()
     }
 
-    /// Visit all key-value pairs in order
-    fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) -> bool {
-        for uint::range(0, self.v.len()) |i| {
-            match self.v[i] {
-              Some(ref elt) => if !it(&i, elt) { return false; },
-              None => ()
-            }
-        }
-        return true;
-    }
-
-    /// Visit all keys in order
-    fn each_key(&self, blk: &fn(key: &uint) -> bool) -> bool {
-        self.each(|k, _| blk(k))
-    }
-
-    /// Visit all values in order
-    fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) -> bool {
-        self.each(|_, v| blk(v))
-    }
-
-    /// Iterate over the map and mutate the contained values
-    fn mutate_values(&mut self, it: &fn(&uint, &mut V) -> bool) -> bool {
-        for uint::range(0, self.v.len()) |i| {
-            match self.v[i] {
-              Some(ref mut elt) => if !it(&i, elt) { return false; },
-              None => ()
-            }
-        }
-        return true;
-    }
-
     /// Return a reference to the value corresponding to the key
     fn find<'a>(&'a self, key: &uint) -> Option<&'a V> {
         if *key < self.v.len() {
@@ -156,6 +124,38 @@ impl<V> SmallIntMap<V> {
     /// Create an empty SmallIntMap
     pub fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
 
+    /// Visit all key-value pairs in order
+    pub fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) -> bool {
+        for uint::range(0, self.v.len()) |i| {
+            match self.v[i] {
+              Some(ref elt) => if !it(&i, elt) { return false; },
+              None => ()
+            }
+        }
+        return true;
+    }
+
+    /// Visit all keys in order
+    pub fn each_key(&self, blk: &fn(key: &uint) -> bool) -> bool {
+        self.each(|k, _| blk(k))
+    }
+
+    /// Visit all values in order
+    pub fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) -> bool {
+        self.each(|_, v| blk(v))
+    }
+
+    /// Iterate over the map and mutate the contained values
+    pub fn mutate_values(&mut self, it: &fn(&uint, &mut V) -> bool) -> bool {
+        for uint::range(0, self.v.len()) |i| {
+            match self.v[i] {
+              Some(ref mut elt) => if !it(&i, elt) { return false; },
+              None => ()
+            }
+        }
+        return true;
+    }
+
     /// Visit all key-value pairs in reverse order
     pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
         for uint::range_rev(self.v.len(), 0) |i| {
diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs
index 4929dea9045..fd83fd19916 100644
--- a/src/libextra/treemap.rs
+++ b/src/libextra/treemap.rs
@@ -107,26 +107,6 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
         self.find(key).is_some()
     }
 
-    /// Visit all key-value pairs in order
-    fn each<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
-        each(&self.root, f)
-    }
-
-    /// Visit all keys in order
-    fn each_key(&self, f: &fn(&K) -> bool) -> bool {
-        self.each(|k, _| f(k))
-    }
-
-    /// Visit all values in order
-    fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool {
-        self.each(|_, v| f(v))
-    }
-
-    /// Iterate over the map and mutate the contained values
-    fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool {
-        mutate_values(&mut self.root, f)
-    }
-
     /// Return a reference to the value corresponding to the key
     fn find<'a>(&'a self, key: &K) -> Option<&'a V> {
         let mut current: &'a Option<~TreeNode<K, V>> = &self.root;
@@ -184,6 +164,26 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
     /// Create an empty TreeMap
     pub fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
 
+    /// Visit all key-value pairs in order
+    pub fn each<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
+        each(&self.root, f)
+    }
+
+    /// Visit all keys in order
+    pub fn each_key(&self, f: &fn(&K) -> bool) -> bool {
+        self.each(|k, _| f(k))
+    }
+
+    /// Visit all values in order
+    pub fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool {
+        self.each(|_, v| f(v))
+    }
+
+    /// Iterate over the map and mutate the contained values
+    pub fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool {
+        mutate_values(&mut self.root, f)
+    }
+
     /// Visit all key-value pairs in reverse order
     pub fn each_reverse<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
         each_reverse(&self.root, f)
diff --git a/src/libstd/container.rs b/src/libstd/container.rs
index c1b656f1cd9..d6f4c26715a 100644
--- a/src/libstd/container.rs
+++ b/src/libstd/container.rs
@@ -34,18 +34,6 @@ pub trait Map<K, V>: Mutable {
     /// Return true if the map contains a value for the specified key
     fn contains_key(&self, key: &K) -> bool;
 
-    /// Visits all keys and values
-    fn each<'a>(&'a self, f: &fn(&K, &'a V) -> bool) -> bool;
-
-    /// Visit all keys
-    fn each_key(&self, f: &fn(&K) -> bool) -> bool;
-
-    /// Visit all values
-    fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool;
-
-    /// Iterate over the map and mutate the contained values
-    fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool;
-
     /// Return a reference to the value corresponding to the key
     fn find<'a>(&'a self, key: &K) -> Option<&'a V>;
 
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index 7d55947e818..962025915d2 100644
--- a/src/libstd/hashmap.rs
+++ b/src/libstd/hashmap.rs
@@ -307,34 +307,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
         }
     }
 
-    /// Visit all key-value pairs
-    fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool {
-        self.iter().advance(|(k, v)| blk(k, v))
-    }
-
-    /// Visit all keys
-    fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
-        self.iter().advance(|(k, _)| blk(k))
-    }
-
-    /// Visit all values
-    fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
-        self.iter().advance(|(_, v)| blk(v))
-    }
-
-    /// Iterate over the map and mutate the contained values
-    fn mutate_values(&mut self, blk: &fn(&K, &mut V) -> bool) -> bool {
-        for uint::range(0, self.buckets.len()) |i| {
-            match self.buckets[i] {
-              Some(Bucket{key: ref key, value: ref mut value, _}) => {
-                if !blk(key, value) { return false; }
-              }
-              None => ()
-            }
-        }
-        return true;
-    }
-
     /// Return a reference to the value corresponding to the key
     fn find<'a>(&'a self, k: &K) -> Option<&'a V> {
         match self.bucket_for_key(k) {
@@ -516,6 +488,34 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
         }
     }
 
+    /// Visit all key-value pairs
+    pub fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool {
+        self.iter().advance(|(k, v)| blk(k, v))
+    }
+
+    /// Visit all keys
+    pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
+        self.iter().advance(|(k, _)| blk(k))
+    }
+
+    /// Visit all values
+    pub fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
+        self.iter().advance(|(_, v)| blk(v))
+    }
+
+    /// Iterate over the map and mutate the contained values
+    pub fn mutate_values(&mut self, blk: &fn(&K, &mut V) -> bool) -> bool {
+        for uint::range(0, self.buckets.len()) |i| {
+            match self.buckets[i] {
+              Some(Bucket{key: ref key, value: ref mut value, _}) => {
+                if !blk(key, value) { return false; }
+              }
+              None => ()
+            }
+        }
+        return true;
+    }
+
     /// An iterator visiting all key-value pairs in arbitrary order.
     /// Iterator element type is (&'a K, &'a V).
     pub fn iter<'a>(&'a self) -> HashMapIterator<'a, K, V> {
diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs
index e6449ef4922..8f70c75439a 100644
--- a/src/libstd/trie.rs
+++ b/src/libstd/trie.rs
@@ -58,30 +58,6 @@ impl<T> Map<uint, T> for TrieMap<T> {
         self.find(key).is_some()
     }
 
-    /// Visit all key-value pairs in order
-    #[inline]
-    fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
-        self.root.each(f)
-    }
-
-    /// Visit all keys in order
-    #[inline]
-    fn each_key(&self, f: &fn(&uint) -> bool) -> bool {
-        self.each(|k, _| f(k))
-    }
-
-    /// Visit all values in order
-    #[inline]
-    fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool {
-        self.each(|_, v| f(v))
-    }
-
-    /// Iterate over the map and mutate the contained values
-    #[inline]
-    fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
-        self.root.mutate_values(f)
-    }
-
     /// Return a reference to the value corresponding to the key
     #[inline]
     fn find<'a>(&'a self, key: &uint) -> Option<&'a T> {
@@ -158,6 +134,30 @@ impl<T> TrieMap<T> {
         self.root.each_reverse(f)
     }
 
+    /// Visit all key-value pairs in order
+    #[inline]
+    pub fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
+        self.root.each(f)
+    }
+
+    /// Visit all keys in order
+    #[inline]
+    pub fn each_key(&self, f: &fn(&uint) -> bool) -> bool {
+        self.each(|k, _| f(k))
+    }
+
+    /// Visit all values in order
+    #[inline]
+    pub fn each_value<'a>(&'a self, f: &fn(&'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: &fn(&uint, &mut T) -> bool) -> bool {
+        self.root.mutate_values(f)
+    }
+
     /// Visit all keys in reverse order
     #[inline]
     pub fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool {
diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs
index c54b8db46c8..2805fec6fce 100644
--- a/src/test/run-pass/class-impl-very-parameterized-trait.rs
+++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs
@@ -61,29 +61,8 @@ impl<T> Mutable for cat<T> {
 }
 
 impl<T> Map<int, T> for cat<T> {
-    fn each<'a>(&'a self, f: &fn(&int, &'a T) -> bool) -> bool {
-        let mut n = int::abs(self.meows);
-        while n > 0 {
-            if !f(&n, &self.name) { return false; }
-            n -= 1;
-        }
-        return true;
-    }
-
     fn contains_key(&self, k: &int) -> bool { *k <= self.meows }
 
-    fn each_key(&self, f: &fn(v: &int) -> bool) -> bool {
-        self.each(|k, _| f(k))
-    }
-
-    fn each_value<'a>(&'a self, f: &fn(v: &'a T) -> bool) -> bool {
-        self.each(|_, v| f(v))
-    }
-
-    fn mutate_values(&mut self, _f: &fn(&int, &mut T) -> bool) -> bool {
-        fail!("nope")
-    }
-
     fn insert(&mut self, k: int, _: T) -> bool {
         self.meows += k;
         true