Skip to content

Commit

Permalink
Ensure carry always cleans up leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Jul 1, 2020
1 parent 8568ea0 commit ea96b20
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,14 @@ impl<T> RawTable<T> {
} else {
// The resize is finally fully complete.
let _ = self.leftovers.take();
break;
return;
}
}

if lo.table.len() == 0 {
// The resize is finally fully complete.
let _ = self.leftovers.take();
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions tests/regressions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
use griddle::hash_map::Entry;
use griddle::HashMap;

#[test]
fn reserve_shrink_add() {
// [Reserve(18303), ShrinkToFit, Add(-94, -96)]
let mut map = HashMap::new();
map.reserve(18303);
map.shrink_to_fit();
map.insert(-94i8, -96i8);
}

#[test]
fn carry_moves_exactly() {
// [AddEntry(-14, 67), Add(6, -14), AddEntry(29, 67), AddEntry(10, 82), Add(-33, -44), Add(37, 88), AddEntry(72, 73), Add(-90, 74), Reserve(45114), AddEntry(-75, -31), Remove(29), RemoveEntry(72), ShrinkToFit, AddEntry(42, -34)]
let mut map = HashMap::new();
map.entry(-14i8).or_insert(67);
map.insert(6, -14);
map.entry(29).or_insert(67);
map.entry(10).or_insert(82);
map.insert(-33, -44);
map.insert(37, 88);
map.entry(72).or_insert(73);
map.entry(-90).or_insert(74);
map.reserve(45114);
map.entry(-75).or_insert(-31);
map.remove(&29);
if let Entry::Occupied(e) = map.entry(72) {
e.remove_entry();
}
map.shrink_to_fit();
map.entry(42).or_insert(-34);
}

0 comments on commit ea96b20

Please sign in to comment.