From: Qinfan Wu Date: Thu, 8 Dec 2016 16:38:14 +0000 (-0800) Subject: Fix sorted_vector_set::erase X-Git-Tag: v2016.12.12.00~7 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=eab8d3c3fc175fceb470eb5bfcc735bed05dd48d;p=folly.git 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 --- 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); +}