Skip to content

Commit 07b803c

Browse files
committed
chore(deps): bump hnswlib from 0.7.0 to 0.8.0
1 parent 44931c3 commit 07b803c

File tree

6 files changed

+515
-45
lines changed

6 files changed

+515
-45
lines changed

ext/hnswlib/src/bruteforce.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class BruteforceSearch : public AlgorithmInterface<dist_t> {
2121

2222
std::unordered_map<labeltype, size_t > dict_external_to_internal;
2323

24-
BruteforceSearch() : data_(nullptr) { }
2524

2625
BruteforceSearch(SpaceInterface <dist_t> *s)
2726
: data_(nullptr),
@@ -85,10 +84,16 @@ class BruteforceSearch : public AlgorithmInterface<dist_t> {
8584

8685

8786
void removePoint(labeltype cur_external) {
88-
size_t cur_c = dict_external_to_internal[cur_external];
87+
std::unique_lock<std::mutex> lock(index_lock);
8988

90-
dict_external_to_internal.erase(cur_external);
89+
auto found = dict_external_to_internal.find(cur_external);
90+
if (found == dict_external_to_internal.end()) {
91+
return;
92+
}
93+
94+
dict_external_to_internal.erase(found);
9195

96+
size_t cur_c = found->second;
9297
labeltype label = *((labeltype*)(data_ + size_per_element_ * (cur_element_count-1) + data_size_));
9398
dict_external_to_internal[label] = cur_c;
9499
memcpy(data_ + size_per_element_ * cur_c,
@@ -107,7 +112,7 @@ class BruteforceSearch : public AlgorithmInterface<dist_t> {
107112
dist_t dist = fstdistfunc_(query_data, data_ + size_per_element_ * i, dist_func_param_);
108113
labeltype label = *((labeltype*) (data_ + size_per_element_ * i + data_size_));
109114
if ((!isIdAllowed) || (*isIdAllowed)(label)) {
110-
topResults.push(std::pair<dist_t, labeltype>(dist, label));
115+
topResults.emplace(dist, label);
111116
}
112117
}
113118
dist_t lastdist = topResults.empty() ? std::numeric_limits<dist_t>::max() : topResults.top().first;
@@ -116,7 +121,7 @@ class BruteforceSearch : public AlgorithmInterface<dist_t> {
116121
if (dist <= lastdist) {
117122
labeltype label = *((labeltype *) (data_ + size_per_element_ * i + data_size_));
118123
if ((!isIdAllowed) || (*isIdAllowed)(label)) {
119-
topResults.push(std::pair<dist_t, labeltype>(dist, label));
124+
topResults.emplace(dist, label);
120125
}
121126
if (topResults.size() > k)
122127
topResults.pop();

0 commit comments

Comments
 (0)