Fix sorted_vector_set::erase
authorQinfan Wu <wqfish@fb.com>
Thu, 8 Dec 2016 16:38:14 +0000 (08:38 -0800)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Fri, 9 Dec 2016 18:03:50 +0000 (10:03 -0800)
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
folly/test/sorted_vector_test.cpp

index 6809dde7793fb1fa24f323eb67ff8b970681d78a..c08fedae1ab92d6383a387f3a38b7a370429d0eb 100644 (file)
@@ -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;
     }
index 5d0dbb150b115ca50c0a1010fefe83cdd2460437..2c7160ea4e426ec049319779dd74cac9fd3815c6 100644 (file)
@@ -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<int> s1;
+  s1.insert(1);
+  sorted_vector_set<int> s2(s1);
+  EXPECT_EQ(0, s1.erase(0));
+  EXPECT_EQ(s2, s1);
+}