Commit ae32b8a5 authored by Nick Jiang's avatar Nick Jiang Committed by Facebook Github Bot

fix sorted_vector_{set,map} bulk_insert deduplication

Summary: this fixes the case where bulk inserting a range where the smallest element is equal to the largest element of the current set/map fails to deduplicate that element.

Reviewed By: mlogan, yfeldblum

Differential Revision: D5593284

fbshipit-source-id: 487500ee7a5e33f27c24321ad4a3c07a669fc26c
parent eb8f3c3c
...@@ -167,7 +167,7 @@ namespace detail { ...@@ -167,7 +167,7 @@ namespace detail {
if (!std::is_sorted(middle, cont.end(), cmp)) { if (!std::is_sorted(middle, cont.end(), cmp)) {
std::sort(middle, cont.end(), cmp); std::sort(middle, cont.end(), cmp);
} }
if (middle != cont.begin() && cmp(*middle, *(middle - 1))) { if (middle != cont.begin() && !cmp(*(middle - 1), *middle)) {
std::inplace_merge(cont.begin(), middle, cont.end(), cmp); std::inplace_merge(cont.begin(), middle, cont.end(), cmp);
cont.erase( cont.erase(
std::unique( std::unique(
......
...@@ -403,6 +403,23 @@ TEST(SortedVectorTypes, TestSetBulkInsertionSortMerge) { ...@@ -403,6 +403,23 @@ TEST(SortedVectorTypes, TestSetBulkInsertionSortMerge) {
testing::ElementsAreArray({1, 2, 4, 5, 6, 7, 8, 10})); testing::ElementsAreArray({1, 2, 4, 5, 6, 7, 8, 10}));
} }
TEST(SortedVectorTypes, TestSetBulkInsertionMiddleValuesEqualDuplication) {
auto s = makeVectorOfWrappers<CountCopyCtor, int>({4, 6, 8});
sorted_vector_set<CountCopyCtor> vset(s.begin(), s.end());
check_invariant(vset);
s = makeVectorOfWrappers<CountCopyCtor, int>({8, 10, 12});
vset.insert(s.begin(), s.end());
check_invariant(vset);
EXPECT_EQ(vset.rbegin()->count_, 1);
EXPECT_THAT(
extractValues(vset),
testing::ElementsAreArray({4, 6, 8, 10, 12}));
}
TEST(SortedVectorTypes, TestSetBulkInsertionSortMergeDups) { TEST(SortedVectorTypes, TestSetBulkInsertionSortMergeDups) {
auto s = makeVectorOfWrappers<CountCopyCtor, int>({6, 4, 8, 2}); auto s = makeVectorOfWrappers<CountCopyCtor, int>({6, 4, 8, 2});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment