From eab8d3c3fc175fceb470eb5bfcc735bed05dd48d Mon Sep 17 00:00:00 2001 From: Qinfan Wu Date: Thu, 8 Dec 2016 08:38:14 -0800 Subject: [PATCH] Fix sorted_vector_set::erase Summary: It deletes things even when input isn't in the container. Reviewed By: luciang Differential Revision: D4298340 fbshipit-source-id: 3e8fc04c2c21eb231dcaf82239ac5f6d25e49e2c --- folly/sorted_vector_types.h | 2 +- folly/test/sorted_vector_test.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/folly/sorted_vector_types.h b/folly/sorted_vector_types.h index 6809dde7..c08fedae 100644 --- a/folly/sorted_vector_types.h +++ b/folly/sorted_vector_types.h @@ -281,7 +281,7 @@ public: } size_type erase(const key_type& key) { - iterator it = lower_bound(key); + iterator it = find(key); if (it == end()) { return 0; } diff --git a/folly/test/sorted_vector_test.cpp b/folly/test/sorted_vector_test.cpp index 5d0dbb15..2c7160ea 100644 --- a/folly/test/sorted_vector_test.cpp +++ b/folly/test/sorted_vector_test.cpp @@ -339,3 +339,11 @@ TEST(SortedVectorTest, ShrinkTest) { // vector::shrink_to_fit respects the caller. EXPECT_EQ(s.capacity(), s.size()); } + +TEST(SortedVectorTypes, EraseTest) { + sorted_vector_set s1; + s1.insert(1); + sorted_vector_set s2(s1); + EXPECT_EQ(0, s1.erase(0)); + EXPECT_EQ(s2, s1); +} -- 2.34.1