Skip to content

Commit 64ee966

Browse files
committed
container: remove internal iterators from Map
the maps are being migrated to external iterators
1 parent 5242e8d commit 64ee966

File tree

6 files changed

+104
-137
lines changed

6 files changed

+104
-137
lines changed

src/libextra/smallintmap.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,38 +56,6 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
5656
self.find(key).is_some()
5757
}
5858

59-
/// Visit all key-value pairs in order
60-
fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) -> bool {
61-
for uint::range(0, self.v.len()) |i| {
62-
match self.v[i] {
63-
Some(ref elt) => if !it(&i, elt) { return false; },
64-
None => ()
65-
}
66-
}
67-
return true;
68-
}
69-
70-
/// Visit all keys in order
71-
fn each_key(&self, blk: &fn(key: &uint) -> bool) -> bool {
72-
self.each(|k, _| blk(k))
73-
}
74-
75-
/// Visit all values in order
76-
fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) -> bool {
77-
self.each(|_, v| blk(v))
78-
}
79-
80-
/// Iterate over the map and mutate the contained values
81-
fn mutate_values(&mut self, it: &fn(&uint, &mut V) -> bool) -> bool {
82-
for uint::range(0, self.v.len()) |i| {
83-
match self.v[i] {
84-
Some(ref mut elt) => if !it(&i, elt) { return false; },
85-
None => ()
86-
}
87-
}
88-
return true;
89-
}
90-
9159
/// Return a reference to the value corresponding to the key
9260
fn find<'a>(&'a self, key: &uint) -> Option<&'a V> {
9361
if *key < self.v.len() {
@@ -156,6 +124,38 @@ impl<V> SmallIntMap<V> {
156124
/// Create an empty SmallIntMap
157125
pub fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
158126

127+
/// Visit all key-value pairs in order
128+
pub fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) -> bool {
129+
for uint::range(0, self.v.len()) |i| {
130+
match self.v[i] {
131+
Some(ref elt) => if !it(&i, elt) { return false; },
132+
None => ()
133+
}
134+
}
135+
return true;
136+
}
137+
138+
/// Visit all keys in order
139+
pub fn each_key(&self, blk: &fn(key: &uint) -> bool) -> bool {
140+
self.each(|k, _| blk(k))
141+
}
142+
143+
/// Visit all values in order
144+
pub fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) -> bool {
145+
self.each(|_, v| blk(v))
146+
}
147+
148+
/// Iterate over the map and mutate the contained values
149+
pub fn mutate_values(&mut self, it: &fn(&uint, &mut V) -> bool) -> bool {
150+
for uint::range(0, self.v.len()) |i| {
151+
match self.v[i] {
152+
Some(ref mut elt) => if !it(&i, elt) { return false; },
153+
None => ()
154+
}
155+
}
156+
return true;
157+
}
158+
159159
/// Visit all key-value pairs in reverse order
160160
pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
161161
for uint::range_rev(self.v.len(), 0) |i| {

src/libextra/treemap.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,6 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
107107
self.find(key).is_some()
108108
}
109109

110-
/// Visit all key-value pairs in order
111-
fn each<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
112-
each(&self.root, f)
113-
}
114-
115-
/// Visit all keys in order
116-
fn each_key(&self, f: &fn(&K) -> bool) -> bool {
117-
self.each(|k, _| f(k))
118-
}
119-
120-
/// Visit all values in order
121-
fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool {
122-
self.each(|_, v| f(v))
123-
}
124-
125-
/// Iterate over the map and mutate the contained values
126-
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool {
127-
mutate_values(&mut self.root, f)
128-
}
129-
130110
/// Return a reference to the value corresponding to the key
131111
fn find<'a>(&'a self, key: &K) -> Option<&'a V> {
132112
let mut current: &'a Option<~TreeNode<K, V>> = &self.root;
@@ -184,6 +164,26 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
184164
/// Create an empty TreeMap
185165
pub fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
186166

167+
/// Visit all key-value pairs in order
168+
pub fn each<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
169+
each(&self.root, f)
170+
}
171+
172+
/// Visit all keys in order
173+
pub fn each_key(&self, f: &fn(&K) -> bool) -> bool {
174+
self.each(|k, _| f(k))
175+
}
176+
177+
/// Visit all values in order
178+
pub fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool {
179+
self.each(|_, v| f(v))
180+
}
181+
182+
/// Iterate over the map and mutate the contained values
183+
pub fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool {
184+
mutate_values(&mut self.root, f)
185+
}
186+
187187
/// Visit all key-value pairs in reverse order
188188
pub fn each_reverse<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
189189
each_reverse(&self.root, f)

src/libstd/container.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ pub trait Map<K, V>: Mutable {
3434
/// Return true if the map contains a value for the specified key
3535
fn contains_key(&self, key: &K) -> bool;
3636

37-
/// Visits all keys and values
38-
fn each<'a>(&'a self, f: &fn(&K, &'a V) -> bool) -> bool;
39-
40-
/// Visit all keys
41-
fn each_key(&self, f: &fn(&K) -> bool) -> bool;
42-
43-
/// Visit all values
44-
fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool;
45-
46-
/// Iterate over the map and mutate the contained values
47-
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool;
48-
4937
/// Return a reference to the value corresponding to the key
5038
fn find<'a>(&'a self, key: &K) -> Option<&'a V>;
5139

src/libstd/hashmap.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -307,34 +307,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
307307
}
308308
}
309309

310-
/// Visit all key-value pairs
311-
fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool {
312-
self.iter().advance(|(k, v)| blk(k, v))
313-
}
314-
315-
/// Visit all keys
316-
fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
317-
self.iter().advance(|(k, _)| blk(k))
318-
}
319-
320-
/// Visit all values
321-
fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
322-
self.iter().advance(|(_, v)| blk(v))
323-
}
324-
325-
/// Iterate over the map and mutate the contained values
326-
fn mutate_values(&mut self, blk: &fn(&K, &mut V) -> bool) -> bool {
327-
for uint::range(0, self.buckets.len()) |i| {
328-
match self.buckets[i] {
329-
Some(Bucket{key: ref key, value: ref mut value, _}) => {
330-
if !blk(key, value) { return false; }
331-
}
332-
None => ()
333-
}
334-
}
335-
return true;
336-
}
337-
338310
/// Return a reference to the value corresponding to the key
339311
fn find<'a>(&'a self, k: &K) -> Option<&'a V> {
340312
match self.bucket_for_key(k) {
@@ -516,6 +488,34 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
516488
}
517489
}
518490

491+
/// Visit all key-value pairs
492+
pub fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool {
493+
self.iter().advance(|(k, v)| blk(k, v))
494+
}
495+
496+
/// Visit all keys
497+
pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
498+
self.iter().advance(|(k, _)| blk(k))
499+
}
500+
501+
/// Visit all values
502+
pub fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
503+
self.iter().advance(|(_, v)| blk(v))
504+
}
505+
506+
/// Iterate over the map and mutate the contained values
507+
pub fn mutate_values(&mut self, blk: &fn(&K, &mut V) -> bool) -> bool {
508+
for uint::range(0, self.buckets.len()) |i| {
509+
match self.buckets[i] {
510+
Some(Bucket{key: ref key, value: ref mut value, _}) => {
511+
if !blk(key, value) { return false; }
512+
}
513+
None => ()
514+
}
515+
}
516+
return true;
517+
}
518+
519519
/// An iterator visiting all key-value pairs in arbitrary order.
520520
/// Iterator element type is (&'a K, &'a V).
521521
pub fn iter<'a>(&'a self) -> HashMapIterator<'a, K, V> {

src/libstd/trie.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,6 @@ impl<T> Map<uint, T> for TrieMap<T> {
5858
self.find(key).is_some()
5959
}
6060

61-
/// Visit all key-value pairs in order
62-
#[inline]
63-
fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
64-
self.root.each(f)
65-
}
66-
67-
/// Visit all keys in order
68-
#[inline]
69-
fn each_key(&self, f: &fn(&uint) -> bool) -> bool {
70-
self.each(|k, _| f(k))
71-
}
72-
73-
/// Visit all values in order
74-
#[inline]
75-
fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool {
76-
self.each(|_, v| f(v))
77-
}
78-
79-
/// Iterate over the map and mutate the contained values
80-
#[inline]
81-
fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
82-
self.root.mutate_values(f)
83-
}
84-
8561
/// Return a reference to the value corresponding to the key
8662
#[inline]
8763
fn find<'a>(&'a self, key: &uint) -> Option<&'a T> {
@@ -158,6 +134,30 @@ impl<T> TrieMap<T> {
158134
self.root.each_reverse(f)
159135
}
160136

137+
/// Visit all key-value pairs in order
138+
#[inline]
139+
pub fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
140+
self.root.each(f)
141+
}
142+
143+
/// Visit all keys in order
144+
#[inline]
145+
pub fn each_key(&self, f: &fn(&uint) -> bool) -> bool {
146+
self.each(|k, _| f(k))
147+
}
148+
149+
/// Visit all values in order
150+
#[inline]
151+
pub fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool {
152+
self.each(|_, v| f(v))
153+
}
154+
155+
/// Iterate over the map and mutate the contained values
156+
#[inline]
157+
pub fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
158+
self.root.mutate_values(f)
159+
}
160+
161161
/// Visit all keys in reverse order
162162
#[inline]
163163
pub fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool {

src/test/run-pass/class-impl-very-parameterized-trait.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,8 @@ impl<T> Mutable for cat<T> {
6161
}
6262

6363
impl<T> Map<int, T> for cat<T> {
64-
fn each<'a>(&'a self, f: &fn(&int, &'a T) -> bool) -> bool {
65-
let mut n = int::abs(self.meows);
66-
while n > 0 {
67-
if !f(&n, &self.name) { return false; }
68-
n -= 1;
69-
}
70-
return true;
71-
}
72-
7364
fn contains_key(&self, k: &int) -> bool { *k <= self.meows }
7465

75-
fn each_key(&self, f: &fn(v: &int) -> bool) -> bool {
76-
self.each(|k, _| f(k))
77-
}
78-
79-
fn each_value<'a>(&'a self, f: &fn(v: &'a T) -> bool) -> bool {
80-
self.each(|_, v| f(v))
81-
}
82-
83-
fn mutate_values(&mut self, _f: &fn(&int, &mut T) -> bool) -> bool {
84-
fail!("nope")
85-
}
86-
8766
fn insert(&mut self, k: int, _: T) -> bool {
8867
self.meows += k;
8968
true

0 commit comments

Comments
 (0)