about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBen Blum <bblum@andrew.cmu.edu>2012-07-31 17:00:17 -0400
committerBen Blum <bblum@andrew.cmu.edu>2012-07-31 17:02:44 -0400
commit8e7fb8e8f5c7175bb18e38c266de3ccce16189bb (patch)
tree7f7ebadb08d70028b852edec65d9a01c0bd6d0f7 /src
parentf35abae89281cd54073c7caefd1e7d55123e8b6d (diff)
downloadrust-8e7fb8e8f5c7175bb18e38c266de3ccce16189bb.tar.gz
rust-8e7fb8e8f5c7175bb18e38c266de3ccce16189bb.zip
Add send_map::each{,_key,_value}
Diffstat (limited to 'src')
-rw-r--r--src/libcore/send_map.rs26
1 files 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<K,V> for &linear_map<K,V> {
+        /*
+        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
+}