Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Yashunin committed Nov 14, 2022
1 parent 34fe7f1 commit 7023e13
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions hnswlib/hnswalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,11 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {


/**
* Remove the deleted mark of the node, does NOT really change the current graph.
*/
* Remove the deleted mark of the node, does NOT really change the current graph.
*
* Note: the method is not safe to use when replacement of deleted elements is enabled
* bacause elements marked as deleted can be completely removed from the index
*/
void unmarkDelete(labeltype label) {
std::unique_lock <std::mutex> lock_table(label_lookup_lock);
auto search = label_lookup_.find(label);
Expand All @@ -791,11 +794,8 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {


/**
* Remove the deleted mark of the node.
*
* Note: the method is not safe to use when replacement of deleted elements is enabled
* bacause elements marked as deleted can be completely removed from the index
*/
* Remove the deleted mark of the node.
*/
void unmarkDeletedInternal(tableint internalId) {
assert(internalId < cur_element_count);
if (isMarkedDeleted(internalId)) {
Expand Down Expand Up @@ -860,18 +860,16 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
addPoint(data_point, label);
return label;
} else {
// wait for element addition or update
std::unique_lock <std::mutex> lock_el_update(link_list_update_locks_[(internal_id_replaced & (max_update_element_locks - 1))]);
// no need to protect element from additions and updates as
// we assume that there are no concurrent operations on deleted element
labeltype label_replaced = getExternalLabel(internal_id_replaced);
setExternalLabel(internal_id_replaced, label);
lock_el_update.unlock();

std::unique_lock <std::mutex> lock_table(label_lookup_lock);
label_lookup_.erase(label_replaced);
label_lookup_[label] = internal_id_replaced;
lock_table.unlock();

lock_el_update.lock();
unmarkDeletedInternal(internal_id_replaced);
updatePoint(data_point, internal_id_replaced, 1.0);

Expand Down

0 comments on commit 7023e13

Please sign in to comment.