Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Fix edge case in compact posting list erase.

Kishore Nallan79986fd0a12f
diff --git a/src/posting.cpp b/src/posting.cpp
index 05b5b061..4e9cee64 100644
--- a/src/posting.cpp
+++ b/src/posting.cpp
@@ -125,13 +125,12 @@ void compact_posting_list_t::erase(const uint32_t id) {
}
length -= shift_offset;
+ ids_length--;
break;
}
i += num_existing_offsets + 2;
}
-
- ids_length--;
}
compact_posting_list_t* compact_posting_list_t::create(uint32_t num_ids, const uint32_t* ids, const uint32_t* offset_index,
diff --git a/test/posting_list_test.cpp b/test/posting_list_test.cpp
index 16e510aa..4be2b50c 100644
--- a/test/posting_list_test.cpp
+++ b/test/posting_list_test.cpp
@@ -1204,7 +1204,14 @@ TEST_F(PostingListTest, CompactPostingListErase) {
compact_posting_list_t* list = compact_posting_list_t::create(3, ids, offset_index, 9, offsets);
- list->erase(3); // erase non-existing ID
+ list->erase(3); // erase non-existing small ID
+
+ ASSERT_EQ(15, list->length);
+ ASSERT_EQ(15, list->capacity);
+ ASSERT_EQ(1002, list->last_id());
+ ASSERT_EQ(3, list->num_ids());
+
+ list->erase(3000); // erase non-existing large ID
ASSERT_EQ(15, list->length);
ASSERT_EQ(15, list->capacity);