@@ -21,7 +21,6 @@ class BruteforceSearch : public AlgorithmInterface<dist_t> {
21
21
22
22
std::unordered_map<labeltype, size_t > dict_external_to_internal;
23
23
24
- BruteforceSearch () : data_(nullptr ) { }
25
24
26
25
BruteforceSearch (SpaceInterface <dist_t > *s)
27
26
: data_(nullptr ),
@@ -85,10 +84,16 @@ class BruteforceSearch : public AlgorithmInterface<dist_t> {
85
84
86
85
87
86
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) ;
89
88
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);
91
95
96
+ size_t cur_c = found->second ;
92
97
labeltype label = *((labeltype*)(data_ + size_per_element_ * (cur_element_count-1 ) + data_size_));
93
98
dict_external_to_internal[label] = cur_c;
94
99
memcpy (data_ + size_per_element_ * cur_c,
@@ -107,7 +112,7 @@ class BruteforceSearch : public AlgorithmInterface<dist_t> {
107
112
dist_t dist = fstdistfunc_ (query_data, data_ + size_per_element_ * i, dist_func_param_);
108
113
labeltype label = *((labeltype*) (data_ + size_per_element_ * i + data_size_));
109
114
if ((!isIdAllowed) || (*isIdAllowed)(label)) {
110
- topResults.push (std::pair< dist_t , labeltype>( dist, label) );
115
+ topResults.emplace ( dist, label);
111
116
}
112
117
}
113
118
dist_t lastdist = topResults.empty () ? std::numeric_limits<dist_t >::max () : topResults.top ().first ;
@@ -116,7 +121,7 @@ class BruteforceSearch : public AlgorithmInterface<dist_t> {
116
121
if (dist <= lastdist) {
117
122
labeltype label = *((labeltype *) (data_ + size_per_element_ * i + data_size_));
118
123
if ((!isIdAllowed) || (*isIdAllowed)(label)) {
119
- topResults.push (std::pair< dist_t , labeltype>( dist, label) );
124
+ topResults.emplace ( dist, label);
120
125
}
121
126
if (topResults.size () > k)
122
127
topResults.pop ();
0 commit comments