send_map - fix size bug; add is_empty and test case for same

This commit is contained in:
Ben Blum 2012-08-01 18:52:13 -04:00
parent 0c3158b3a5
commit 6fdd1ef9b1

View file

@ -229,6 +229,7 @@ mod linear {
self.insert_bucket(bucket);
idx = self.next_bucket(idx, len_buckets);
}
self.size -= 1;
ret true;
}
}
@ -240,10 +241,14 @@ mod linear {
}
impl public_methods<K,V> for &const linear_map<K,V> {
fn size() -> uint {
fn len() -> uint {
self.size
}
fn is_empty() -> bool {
self.len() == 0
}
fn contains_key(k: &K) -> bool {
alt self.bucket_for_key(self.buckets, k) {
found_entry(_) => {true}
@ -377,6 +382,15 @@ mod test {
assert m.get(&5) == 3;
}
#[test]
fn empty() {
let mut m = ~linear::linear_map_with_capacity(uint_hash, uint_eq, 4);
assert m.insert(1, 2);
assert !m.is_empty();
assert m.remove(&1);
assert m.is_empty();
}
#[test]
fn iterate() {
let mut m = linear::linear_map_with_capacity(uint_hash, uint_eq, 4);