From 013def5142e515696e1f41b36c42486dfa4a1a38 Mon Sep 17 00:00:00 2001 From: Taras Tsugrii Date: Sun, 18 Jun 2023 20:49:26 -0500 Subject: [PATCH] [bruteforce] Fix bruteforce removePoint. --- hnswlib/bruteforce.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hnswlib/bruteforce.h b/hnswlib/bruteforce.h index 30b33ae9..15d10c98 100644 --- a/hnswlib/bruteforce.h +++ b/hnswlib/bruteforce.h @@ -84,10 +84,16 @@ class BruteforceSearch : public AlgorithmInterface { void removePoint(labeltype cur_external) { - size_t cur_c = dict_external_to_internal[cur_external]; + std::unique_lock lock(index_lock); - dict_external_to_internal.erase(cur_external); + auto found = dict_external_to_internal.find(cur_external); + if (found == dict_external_to_internal.end()) { + return; + } + + dict_external_to_internal.erase(found); + size_t cur_c = found->second; labeltype label = *((labeltype*)(data_ + size_per_element_ * (cur_element_count-1) + data_size_)); dict_external_to_internal[label] = cur_c; memcpy(data_ + size_per_element_ * cur_c,