From 5606fc0c90461db40faeca16d7bffd9e61c2be73 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 6 Apr 2013 11:22:36 -0400 Subject: 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. --- src/libstd/smallintmap.rs | 52 +++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'src/libstd/smallintmap.rs') 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 { priv v: ~[Option], } -impl<'self, V> BaseIter<(uint, &'self V)> for SmallIntMap { - /// 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 { Some(self.len()) } -} - -impl<'self, V> ReverseIter<(uint, &'self V)> for SmallIntMap { - /// 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 Container for SmallIntMap { /// Return the number of elements in the map fn len(&const self) -> uint { @@ -76,14 +50,24 @@ impl Map for SmallIntMap { 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 SmallIntMap { /// Create an empty SmallIntMap fn new() -> SmallIntMap { 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") } -- cgit 1.4.1-3-g733a5