diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index cd7468b8b38..40eae90e96b 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -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 for &const linear_map { - 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);