revise map interface so that K need not be copyable
This commit is contained in:
parent
fc9eadf75b
commit
9105cb6d5d
@ -21,7 +21,7 @@ type set<K> = hashmap<K, ()>;
|
|||||||
|
|
||||||
type hashmap<K, V> = chained::t<K, V>;
|
type hashmap<K, V> = chained::t<K, V>;
|
||||||
|
|
||||||
iface map<K: copy, V: copy> {
|
iface map<K, V: copy> {
|
||||||
#[doc = "Return the number of elements in the map"]
|
#[doc = "Return the number of elements in the map"]
|
||||||
fn size() -> uint;
|
fn size() -> uint;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ iface map<K: copy, V: copy> {
|
|||||||
|
|
||||||
Returns true if the key did not already exist in the map
|
Returns true if the key did not already exist in the map
|
||||||
"]
|
"]
|
||||||
fn insert(K, V) -> bool;
|
fn insert(+K, +V) -> bool;
|
||||||
|
|
||||||
#[doc = "Returns true if the map contains a value for the specified key"]
|
#[doc = "Returns true if the map contains a value for the specified key"]
|
||||||
fn contains_key(K) -> bool;
|
fn contains_key(K) -> bool;
|
||||||
@ -96,7 +96,7 @@ mod chained {
|
|||||||
found_after(@entry<K,V>, @entry<K,V>)
|
found_after(@entry<K,V>, @entry<K,V>)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl private_methods<K: copy, V: copy> for t<K, V> {
|
impl private_methods<K, V: copy> for t<K, V> {
|
||||||
fn search_rem(k: K, h: uint, idx: uint,
|
fn search_rem(k: K, h: uint, idx: uint,
|
||||||
e_root: @entry<K,V>) -> search_result<K,V> {
|
e_root: @entry<K,V>) -> search_result<K,V> {
|
||||||
let mut e0 = e_root;
|
let mut e0 = e_root;
|
||||||
@ -174,7 +174,7 @@ mod chained {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl hashmap<K: copy, V: copy> of map<K, V> for t<K, V> {
|
impl hashmap<K, V: copy> of map<K, V> for t<K, V> {
|
||||||
fn size() -> uint { self.count }
|
fn size() -> uint { self.count }
|
||||||
|
|
||||||
fn contains_key(k: K) -> bool {
|
fn contains_key(k: K) -> bool {
|
||||||
@ -185,7 +185,7 @@ mod chained {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert(k: K, v: V) -> bool {
|
fn insert(+k: K, +v: V) -> bool {
|
||||||
let hash = self.hasher(k);
|
let hash = self.hasher(k);
|
||||||
alt self.search_tbl(k, hash) {
|
alt self.search_tbl(k, hash) {
|
||||||
not_found {
|
not_found {
|
||||||
@ -249,7 +249,7 @@ mod chained {
|
|||||||
|
|
||||||
fn each(blk: fn(K,V) -> bool) {
|
fn each(blk: fn(K,V) -> bool) {
|
||||||
for self.each_entry { |entry|
|
for self.each_entry { |entry|
|
||||||
if !blk(copy entry.key, copy entry.value) { break; }
|
if !blk(entry.key, copy entry.value) { break; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
|
|||||||
}
|
}
|
||||||
sz
|
sz
|
||||||
}
|
}
|
||||||
fn insert(&&key: uint, value: V) -> bool {
|
fn insert(+key: uint, +value: V) -> bool {
|
||||||
let exists = contains_key(self, key);
|
let exists = contains_key(self, key);
|
||||||
insert(self, key, value);
|
insert(self, key, value);
|
||||||
ret !exists;
|
ret !exists;
|
||||||
|
@ -36,7 +36,7 @@ class cat implements map<int, bool> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn size() -> uint { self.meows as uint }
|
fn size() -> uint { self.meows as uint }
|
||||||
fn insert(&&k: int, &&v: bool) -> bool {
|
fn insert(+k: int, +v: bool) -> bool {
|
||||||
if v { self.meows += k; } else { self.meows -= k; };
|
if v { self.meows += k; } else { self.meows -= k; };
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class cat<T: copy> implements map<int, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn size() -> uint { self.meows as uint }
|
fn size() -> uint { self.meows as uint }
|
||||||
fn insert(&&k: int, &&_v: T) -> bool {
|
fn insert(+k: int, +_v: T) -> bool {
|
||||||
self.meows += k;
|
self.meows += k;
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user