summary refs log tree commit diff
path: root/src/libstd/smallintmap.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-04-06 11:22:36 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-04-10 07:51:48 -0700
commit5606fc0c90461db40faeca16d7bffd9e61c2be73 (patch)
tree771bcf433e2c582d97ae276d6927aea08f7ed755 /src/libstd/smallintmap.rs
parent72228012343db793ff453b7cf038d973ccac61a7 (diff)
downloadrust-5606fc0c90461db40faeca16d7bffd9e61c2be73.tar.gz
rust-5606fc0c90461db40faeca16d7bffd9e61c2be73.zip
Revert map.each to something which takes two parameters
rather than a tuple.  The current setup iterates over
`BaseIter<(&'self K, &'self V)>` where 'self is a lifetime declared
*in the each method*.  You can't place such a type in
the impl declaration.  The compiler currently allows it,
but this will not be legal under #5656 and I'm pretty sure
it's not sound now.
Diffstat (limited to 'src/libstd/smallintmap.rs')
-rw-r--r--src/libstd/smallintmap.rs52
1 files changed, 23 insertions, 29 deletions
diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs
index b6c5ec03068..811cd710a62 100644
--- a/src/libstd/smallintmap.rs
+++ b/src/libstd/smallintmap.rs
@@ -14,7 +14,7 @@
  */
 
 use core::container::{Container, Mutable, Map, Set};
-use core::iter::{BaseIter, ReverseIter};
+use core::iter::{BaseIter};
 use core::option::{Some, None};
 use core::prelude::*;
 
@@ -22,32 +22,6 @@ pub struct SmallIntMap<T> {
     priv v: ~[Option<T>],
 }
 
-impl<'self, V> BaseIter<(uint, &'self V)> for SmallIntMap<V> {
-    /// Visit all key-value pairs in order
-    fn each(&self, it: &fn(&(uint, &'self V)) -> bool) {
-        for uint::range(0, self.v.len()) |i| {
-            match self.v[i] {
-              Some(ref elt) => if !it(&(i, elt)) { break },
-              None => ()
-            }
-        }
-    }
-
-    fn size_hint(&self) -> Option<uint> { Some(self.len()) }
-}
-
-impl<'self, V> ReverseIter<(uint, &'self V)> for SmallIntMap<V> {
-    /// Visit all key-value pairs in reverse order
-    fn each_reverse(&self, it: &fn(&(uint, &'self V)) -> bool) {
-        for uint::range_rev(self.v.len(), 0) |i| {
-            match self.v[i - 1] {
-              Some(ref elt) => if !it(&(i - 1, elt)) { break },
-              None => ()
-            }
-        }
-    }
-}
-
 impl<V> Container for SmallIntMap<V> {
     /// Return the number of elements in the map
     fn len(&const self) -> uint {
@@ -76,14 +50,24 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
         self.find(key).is_some()
     }
 
+    /// Visit all key-value pairs in order
+    fn each(&self, it: &fn(&uint, &'self 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 in order
     fn each_key(&self, blk: &fn(key: &uint) -> bool) {
-        self.each(|&(k, _)| blk(&k))
+        self.each(|k, _| blk(k))
     }
 
     /// Visit all values in order
     fn each_value(&self, blk: &fn(value: &V) -> bool) {
-        self.each(|&(_, v)| blk(v))
+        self.each(|_, v| blk(v))
     }
 
     /// Iterate over the map and mutate the contained values
@@ -149,6 +133,16 @@ pub impl<V> SmallIntMap<V> {
     /// Create an empty SmallIntMap
     fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
 
+    /// Visit all key-value pairs in reverse order
+    fn each_reverse(&self, it: &fn(uint, &'self V) -> bool) {
+        for uint::range_rev(self.v.len(), 0) |i| {
+            match self.v[i - 1] {
+              Some(ref elt) => if !it(i - 1, elt) { break },
+              None => ()
+            }
+        }
+    }
+
     fn get(&self, key: &uint) -> &'self V {
         self.find(key).expect("key not present")
     }