Skip to content

Commit

Permalink
[hive] Fix a bug I introduced in 6040207
Browse files Browse the repository at this point in the history
  • Loading branch information
Quuxplusone committed Feb 17, 2023
1 parent 56aec97 commit a3e1232
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/sg14/plf_hive.h
Original file line number Diff line number Diff line change
Expand Up @@ -1912,13 +1912,16 @@ class hive {
GroupPtr g = groups_with_erasures_;
assert(g->free_list_head != std::numeric_limits<skipfield_type>::max());
skipfield_type skipblock_length = g->skipfield(g->free_list_head);
if (skipblock_length >= n) {
if (skipblock_length > n) {
callback_fill_skipblock<false>(n, cb, g);
assert_invariants();
return;
} else {
callback_fill_skipblock<true>(skipblock_length, cb, g);
n -= skipblock_length;
if (n == 0) {
return;
}
}
}
assert_invariants();
Expand Down
15 changes: 15 additions & 0 deletions test/hive_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2811,4 +2811,19 @@ TEST(hive, PmrCorrectAllocAwareCtors)
}
#endif // __cpp_lib_memory_resource >= 201603

TEST(hive, RangeInsertRegressionTest)
{
auto h = plf::hive<int>(100, 42);
h.erase(std::next(h.begin()));
h.erase(std::next(h.begin()));
EXPECT_EQ(h.size(), 98);
h.insert(2, 42); // 42 copies of "42"
EXPECT_EQ(h.size(), 100);
int sum = 0;
for (int i : h) {
sum += i;
}
EXPECT_EQ(sum, 4200);
}

#endif // __cplusplus >= 201703

0 comments on commit a3e1232

Please sign in to comment.