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

Address valgrind warning.

kishorenc1a65ad509b77
diff --git a/include/auth_manager.h b/include/auth_manager.h
index 83b1a375..79cd6825 100644
--- a/include/auth_manager.h
+++ b/include/auth_manager.h
@@ -17,8 +17,8 @@ struct api_key_t {
std::vector<std::string> collections;
uint64_t expires_at;
- static const size_t PREFIX_LEN = 4;
- static const uint64_t FAR_FUTURE_TIMESTAMP = 64723363199; // year 4020
+ static constexpr const size_t PREFIX_LEN = 4;
+ static constexpr const uint64_t FAR_FUTURE_TIMESTAMP = 64723363199; // year 4020
api_key_t() {
diff --git a/include/collection_manager.h b/include/collection_manager.h
index 0702519e..7e627368 100644
--- a/include/collection_manager.h
+++ b/include/collection_manager.h
@@ -89,7 +89,7 @@ private:
}
public:
- static const size_t DEFAULT_NUM_MEMORY_SHARDS = 4;
+ static constexpr const size_t DEFAULT_NUM_MEMORY_SHARDS = 4;
static constexpr const char* NEXT_COLLECTION_ID_KEY = "$CI";
static constexpr const char* SYMLINK_PREFIX = "$SL";
diff --git a/src/index.cpp b/src/index.cpp
index b2f2c3b1..98205b0e 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -107,9 +107,7 @@ Option<uint32_t> Index::index_in_memory(const nlohmann::json &document, uint32_t
points = get_points_from_doc(document, default_sorting_field);
}
- if(!is_update) {
- seq_ids.append(seq_id);
- }
+ seq_ids.append(seq_id);
std::unordered_map<std::string, size_t> facet_to_id;
size_t i_facet = 0;
@@ -2322,7 +2320,9 @@ Option<uint32_t> Index::remove(const uint32_t seq_id, const nlohmann::json & doc
}
}
- seq_ids.remove_value(seq_id);
+ if(seq_ids.contains(seq_id)) {
+ seq_ids.remove_value(seq_id);
+ }
return Option<uint32_t>(seq_id);
}
diff --git a/src/sorted_array.cpp b/src/sorted_array.cpp
index 43f37116..a4d5b371 100644
--- a/src/sorted_array.cpp
+++ b/src/sorted_array.cpp
@@ -89,6 +89,10 @@ uint32_t sorted_array::at(uint32_t index) {
}
bool sorted_array::contains(uint32_t value) {
+ if(length == 0) {
+ return false;
+ }
+
uint32_t actual;
for_lower_bound_search(in, length, value, &actual);
return actual == value;