From 1834249e8dff3419f33ee8595a4bf347e50c3c62 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 14 Sep 2012 16:02:02 -0700 Subject: [PATCH] libcore: add find_ref/get_ref to SendMap trait --- src/libcore/send_map.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index 7523627ffe3..5e8147c55c7 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -22,8 +22,8 @@ trait SendMap { fn each_value_ref(&self, blk: fn(v: &V) -> bool); fn find(&const self, k: &K) -> Option; fn get(&const self, k: &K) -> V; - fn with_find_ref(&const self, k: &K, blk: fn(Option<&V>) -> T) -> T; - fn with_get_ref(&const self, k: &K, blk: fn(v: &V) -> T) -> T; + fn find_ref(&self, k: &K) -> Option<&self/V>; + fn get_ref(&self, k: &K) -> &self/V; } /// Open addressing with linear probing. @@ -304,6 +304,13 @@ mod linear { } } + fn get_ref(&self, k: &K) -> &self/V { + match self.find_ref(k) { + Some(v) => v, + None => fail fmt!("No entry found for key: %?", k), + } + } + fn each_ref(&self, blk: fn(k: &K, v: &V) -> bool) { for vec::each(self.buckets) |slot| { let mut broke = false;