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

Keep the hashset bounded by deleting the element to be replaced in heap from the set.

Kishore Nallance471c9bb1e1
diff --git a/include/topster.h b/include/topster.h
index b541667a..a15fcc3c 100644
--- a/include/topster.h
+++ b/include/topster.h
@@ -33,18 +33,20 @@ struct Topster {
}
void add(const uint64_t &key, const uint64_t &match_score, const int64_t &primary_attr, const int64_t &secondary_attr){
- if(dedup_keys.count(key) != 0) {
- return ;
- }
-
- dedup_keys.insert(key);
-
if (size >= MAX_SIZE) {
if(!is_greater(data[0], match_score, primary_attr, secondary_attr)) {
// when incoming value is less than the smallest in the heap, ignore
return;
}
+ if(dedup_keys.count(key) != 0) {
+ // when the key already exists, ignore
+ return ;
+ }
+
+ dedup_keys.erase(data[0].key);
+ dedup_keys.insert(key);
+
data[0].key = key;
data[0].match_score = match_score;
data[0].primary_attr = primary_attr;
@@ -67,6 +69,13 @@ struct Topster {
i = next;
}
} else {
+ if(dedup_keys.count(key) != 0) {
+ // when the key already exists, ignore
+ return ;
+ }
+
+ dedup_keys.insert(key);
+
data[size].key = key;
data[size].match_score = match_score;
data[size].primary_attr = primary_attr;
diff --git a/src/collection.cpp b/src/collection.cpp
index 8f4d5274..69b94549 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -537,9 +537,9 @@ void Collection::remove(std::string id) {
}
std::string Collection::get_seq_id_key(uint32_t seq_id) {
- return collection_id + "_" + SEQ_ID_PREFIX + std::to_string(seq_id);
+ return std::to_string(collection_id) + "_" + SEQ_ID_PREFIX + std::to_string(seq_id);
}
std::string Collection::get_doc_id_key(std::string doc_id) {
- return collection_id + "_" + DOC_ID_PREFIX + doc_id;
+ return std::to_string(collection_id) + "_" + DOC_ID_PREFIX + doc_id;
}
\ No newline at end of file