Skip to content

Commit 6fdd1ef

Browse files
committed
send_map - fix size bug; add is_empty and test case for same
1 parent 0c3158b commit 6fdd1ef

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/libcore/send_map.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ mod linear {
229229
self.insert_bucket(bucket);
230230
idx = self.next_bucket(idx, len_buckets);
231231
}
232+
self.size -= 1;
232233
ret true;
233234
}
234235
}
@@ -240,10 +241,14 @@ mod linear {
240241
}
241242

242243
impl public_methods<K,V> for &const linear_map<K,V> {
243-
fn size() -> uint {
244+
fn len() -> uint {
244245
self.size
245246
}
246247

248+
fn is_empty() -> bool {
249+
self.len() == 0
250+
}
251+
247252
fn contains_key(k: &K) -> bool {
248253
alt self.bucket_for_key(self.buckets, k) {
249254
found_entry(_) => {true}
@@ -377,6 +382,15 @@ mod test {
377382
assert m.get(&5) == 3;
378383
}
379384

385+
#[test]
386+
fn empty() {
387+
let mut m = ~linear::linear_map_with_capacity(uint_hash, uint_eq, 4);
388+
assert m.insert(1, 2);
389+
assert !m.is_empty();
390+
assert m.remove(&1);
391+
assert m.is_empty();
392+
}
393+
380394
#[test]
381395
fn iterate() {
382396
let mut m = linear::linear_map_with_capacity(uint_hash, uint_eq, 4);

0 commit comments

Comments
 (0)