about summary refs log tree commit diff
path: root/src/libstd
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 /src/libstd
parent5242e8d2bad01beec7c841d20952cb230bc9fd84 (diff)
downloadrust-64ee9668a2e3d4d75b859fd3bca1466a97fae2d8.tar.gz
rust-64ee9668a2e3d4d75b859fd3bca1466a97fae2d8.zip
container: remove internal iterators from Map
the maps are being migrated to external iterators
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/container.rs12
-rw-r--r--src/libstd/hashmap.rs56
-rw-r--r--src/libstd/trie.rs48
3 files changed, 52 insertions, 64 deletions
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 {