Add an overloaded [] function to the map interface. Closes #2730.
This commit is contained in:
parent
0c42a3ffee
commit
df9b43e27c
@ -45,6 +45,9 @@
|
||||
"]
|
||||
fn get(K) -> V;
|
||||
|
||||
#[doc = "Like get, but as an operator."]
|
||||
fn [](K) -> V;
|
||||
|
||||
#[doc = "
|
||||
Get the value for the specified key. If the key does not exist in
|
||||
the map then returns none.
|
||||
@ -232,6 +235,10 @@ fn get(k: K) -> V {
|
||||
option::get(self.find(k))
|
||||
}
|
||||
|
||||
fn [](k: K) -> V {
|
||||
option::get(self.find(k))
|
||||
}
|
||||
|
||||
fn remove(k: K) -> option<V> {
|
||||
alt self.search_tbl(k, self.hasher(k)) {
|
||||
not_found {none}
|
||||
|
@ -79,6 +79,7 @@ fn contains_key(&&key: uint) -> bool {
|
||||
contains_key(self, key)
|
||||
}
|
||||
fn get(&&key: uint) -> V { get(self, key) }
|
||||
fn [](&&key: uint) -> V { get(self, key) }
|
||||
fn find(&&key: uint) -> option<V> { find(self, key) }
|
||||
fn rehash() { fail }
|
||||
fn each(it: fn(&&uint, V) -> bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user