libcore: add find_ref/get_ref to SendMap trait
This commit is contained in:
parent
10e317de54
commit
1834249e8d
1 changed files with 9 additions and 2 deletions
|
@ -22,8 +22,8 @@ trait SendMap<K:Eq Hash, V: Copy> {
|
|||
fn each_value_ref(&self, blk: fn(v: &V) -> bool);
|
||||
fn find(&const self, k: &K) -> Option<V>;
|
||||
fn get(&const self, k: &K) -> V;
|
||||
fn with_find_ref<T>(&const self, k: &K, blk: fn(Option<&V>) -> T) -> T;
|
||||
fn with_get_ref<T>(&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;
|
||||
|
|
Loading…
Add table
Reference in a new issue