From 8e7fb8e8f5c7175bb18e38c266de3ccce16189bb Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Tue, 31 Jul 2012 17:00:17 -0400 Subject: [PATCH] Add send_map::each{,_key,_value} --- src/libcore/send_map.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index 24af1d0aedf..5c10dd18e3d 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -279,16 +279,34 @@ mod linear { } } - /* - FIXME --- #2979 must be fixed to typecheck this impl imm_methods for &linear_map { + /* + FIXME --- #2979 must be fixed to typecheck this fn find_ptr(k: K) -> option<&V> { //XXX this should not type check as written, but it should //be *possible* to typecheck it... self.with_ptr(k, |v| v) } + */ + + fn each(blk: fn(k: &K, v: &V) -> bool) { + for vec::each(self.buckets) |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 each_key(blk: fn(k: &K) -> bool) { + self.each(|k, _v| blk(k)) + } + fn each_value(blk: fn(v: &V) -> bool) { + self.each(|_k, v| blk(v)) + } } - */ } #[test] @@ -342,4 +360,4 @@ mod test { assert m.get(&9) == 4; assert m.get(&5) == 3; } -} \ No newline at end of file +}