about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-02-07 17:49:57 -0500
committerDaniel Micay <danielmicay@gmail.com>2013-02-07 22:04:35 -0500
commit83270d2d792fb519481f6df87f23d73c767ec5f9 (patch)
tree89b8242df68a8a249291c6a2b5354bc7de2f0bac /src
parentd903231f1e7d7efb35405bdfdcbc451385e429b2 (diff)
downloadrust-83270d2d792fb519481f6df87f23d73c767ec5f9.tar.gz
rust-83270d2d792fb519481f6df87f23d73c767ec5f9.zip
rm each method from the Map trait
the map types should implement BaseIter instead
Diffstat (limited to 'src')
-rw-r--r--src/libcore/container.rs3
-rw-r--r--src/libcore/hashmap.rs26
-rw-r--r--src/libstd/smallintmap.rs20
-rw-r--r--src/libstd/treemap.rs6
-rw-r--r--src/test/run-pass/class-impl-very-parameterized-trait.rs25
5 files changed, 41 insertions, 39 deletions
diff --git a/src/libcore/container.rs b/src/libcore/container.rs
index 2a5ca7d8dfa..36424d1bfaa 100644
--- a/src/libcore/container.rs
+++ b/src/libcore/container.rs
@@ -29,9 +29,6 @@ pub trait Map<K, V>: Mutable {
     /// Return true if the map contains a value for the specified key
     pure fn contains_key(&self, key: &K) -> bool;
 
-    /// Visit all key-value pairs
-    pure fn each(&self, f: fn(&K, &V) -> bool);
-
     /// Visit all keys
     pure fn each_key(&self, f: fn(&K) -> bool);
 
diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs
index be785863f71..6bc9e4f88cf 100644
--- a/src/libcore/hashmap.rs
+++ b/src/libcore/hashmap.rs
@@ -262,19 +262,6 @@ pub mod linear {
             }
         }
 
-        /// Visit all key-value pairs
-        pure fn each(&self, blk: fn(k: &K, v: &V) -> bool) {
-            for self.buckets.each |slot| {
-                let mut broke = false;
-                do slot.iter |bucket| {
-                    if !blk(&bucket.key, &bucket.value) {
-                        broke = true; // FIXME(#3064) just write "break;"
-                    }
-                }
-                if broke { break; }
-            }
-        }
-
         /// Visit all keys
         pure fn each_key(&self, blk: fn(k: &K) -> bool) {
             self.each(|k, _| blk(k))
@@ -335,6 +322,19 @@ pub mod linear {
             linear_map_with_capacity(INITIAL_CAPACITY)
         }
 
+        /// Visit all key-value pairs
+        pure fn each(&self, blk: fn(k: &K, v: &V) -> bool) {
+            for self.buckets.each |slot| {
+                let mut broke = false;
+                do slot.iter |bucket| {
+                    if !blk(&bucket.key, &bucket.value) {
+                        broke = true; // FIXME(#3064) just write "break;"
+                    }
+                }
+                if broke { break; }
+            }
+        }
+
         fn pop(&mut self, k: &K) -> Option<V> {
             let hash = k.hash_keyed(self.k0, self.k1) as uint;
             self.pop_internal(hash, k)
diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs
index 9af596eb1f5..218964695e2 100644
--- a/src/libstd/smallintmap.rs
+++ b/src/libstd/smallintmap.rs
@@ -48,16 +48,6 @@ impl<V> SmallIntMap<V>: Map<uint, V> {
         self.find(key).is_some()
     }
 
-    /// Visit all key-value pairs
-    pure fn each(&self, it: fn(key: &uint, value: &V) -> bool) {
-        for uint::range(0, self.v.len()) |i| {
-            match self.v[i] {
-              Some(ref elt) => if !it(&i, elt) { break },
-              None => ()
-            }
-        }
-    }
-
     /// Visit all keys
     pure fn each_key(&self, blk: fn(key: &uint) -> bool) {
         self.each(|k, _| blk(k))
@@ -109,6 +99,16 @@ pub impl<V> SmallIntMap<V> {
     /// Create an empty SmallIntMap
     static pure fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
 
+    /// Visit all key-value pairs
+    pure fn each(&self, it: fn(key: &uint, value: &V) -> bool) {
+        for uint::range(0, self.v.len()) |i| {
+            match self.v[i] {
+              Some(ref elt) => if !it(&i, elt) { break },
+              None => ()
+            }
+        }
+    }
+
     pure fn get(&self, key: &uint) -> &self/V {
         self.find(key).expect("key not present")
     }
diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs
index 1e90abcc03d..70226c7277d 100644
--- a/src/libstd/treemap.rs
+++ b/src/libstd/treemap.rs
@@ -125,9 +125,6 @@ impl <K: Ord, V> TreeMap<K, V>: Map<K, V> {
         self.find(key).is_some()
     }
 
-    /// Visit all key-value pairs in order
-    pure fn each(&self, f: fn(&K, &V) -> bool) { each(&self.root, f) }
-
     /// Visit all keys in order
     pure fn each_key(&self, f: fn(&K) -> bool) { self.each(|k, _| f(k)) }
 
@@ -175,6 +172,9 @@ impl <K: Ord, V> TreeMap<K, V> {
     /// Create an empty TreeMap
     static pure fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
 
+    /// Visit all key-value pairs in order
+    pure fn each(&self, f: fn(&K, &V) -> bool) { each(&self.root, f) }
+
     /// Visit all key-value pairs in reverse order
     pure fn each_reverse(&self, f: fn(&K, &V) -> bool) {
         each_reverse(&self.root, f);
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 b7c8322316f..a0230d02981 100644
--- a/src/test/run-pass/class-impl-very-parameterized-trait.rs
+++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs
@@ -11,6 +11,7 @@
 // xfail-fast
 
 use core::container::{Container, Mutable, Map};
+use core::iter::BaseIter;
 
 enum cat_type { tuxedo, tabby, tortoiseshell }
 
@@ -48,6 +49,18 @@ impl<T> cat<T> {
     }
 }
 
+impl<T> cat<T>: BaseIter<(int, &T)> {
+    pure fn each(&self, f: fn(&(int, &self/T)) -> bool) {
+        let mut n = int::abs(self.meows);
+        while n > 0 {
+            if !f(&(n, &self.name)) { break; }
+            n -= 1;
+        }
+    }
+
+    pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
+}
+
 impl<T> cat<T>: Container {
     pure fn len(&self) -> uint { self.meows as uint }
     pure fn is_empty(&self) -> bool { self.meows == 0 }
@@ -60,20 +73,12 @@ impl<T> cat<T>: Mutable {
 impl<T> cat<T>: Map<int, T> {
     pure fn contains_key(&self, k: &int) -> bool { *k <= self.meows }
 
-    pure fn each(&self, f: fn(v: &int, v: &T) -> bool) {
-        let mut n = int::abs(self.meows);
-        while n > 0 {
-            if !f(&n, &self.name) { break; }
-            n -= 1;
-        }
-    }
-
     pure fn each_key(&self, f: fn(v: &int) -> bool) {
-        for self.each |k, _| { if !f(k) { break; } loop;};
+        for self.each |&(k, _)| { if !f(&k) { break; } loop;};
     }
 
     pure fn each_value(&self, f: fn(v: &T) -> bool) {
-        for self.each |_, v| { if !f(v) { break; } loop;};
+        for self.each |&(_, v)| { if !f(v) { break; } loop;};
     }
 
     fn insert(&mut self, k: int, _: T) -> bool {