Skip to content

Commit 8a568cb

Browse files
authored
Remove Redundant Operations - [MOD-13475] (#886)
remove redundant work
1 parent 32d0279 commit 8a568cb

File tree

1 file changed

+3
-11
lines changed
  • src/VecSim/algorithms/hnsw

1 file changed

+3
-11
lines changed

src/VecSim/algorithms/hnsw/hnsw.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class HNSWIndex : public VecSimIndexAbstract<DataType, DistType>,
171171
idType mutuallyConnectNewElement(idType new_node_id,
172172
candidatesMaxHeap<DistType> &top_candidates, size_t level);
173173
void mutuallyUpdateForRepairedNode(idType node_id, size_t level,
174-
vecsim_stl::vector<idType> &neighbors_to_remove,
175174
vecsim_stl::vector<idType> &nodes_to_update,
176175
vecsim_stl::vector<idType> &chosen_neighbors,
177176
size_t max_M_cur);
@@ -1351,11 +1350,8 @@ void HNSWIndex<DataType, DistType>::shrinkByBlock() {
13511350

13521351
template <typename DataType, typename DistType>
13531352
void HNSWIndex<DataType, DistType>::mutuallyUpdateForRepairedNode(
1354-
idType node_id, size_t level, vecsim_stl::vector<idType> &neighbors_to_remove,
1355-
vecsim_stl::vector<idType> &nodes_to_update, vecsim_stl::vector<idType> &chosen_neighbors,
1356-
size_t max_M_cur) {
1357-
// Sort the nodes to remove set for fast lookup.
1358-
std::sort(neighbors_to_remove.begin(), neighbors_to_remove.end());
1353+
idType node_id, size_t level, vecsim_stl::vector<idType> &nodes_to_update,
1354+
vecsim_stl::vector<idType> &chosen_neighbors, size_t max_M_cur) {
13591355

13601356
// Acquire the required locks for the updates, after sorting the nodes to update
13611357
// (to avoid deadlocks)
@@ -1474,12 +1470,10 @@ void HNSWIndex<DataType, DistType>::repairNodeConnections(idType node_id, size_t
14741470
// neighbors that are going to be removed.
14751471
vecsim_stl::vector<idType> nodes_to_update(this->allocator);
14761472
vecsim_stl::vector<idType> chosen_neighbors(this->allocator);
1477-
vecsim_stl::vector<idType> neighbors_to_remove(this->allocator);
14781473

14791474
// Go over the deleted nodes and collect their neighbors to the candidates set.
14801475
for (idType deleted_neighbor_id : deleted_neighbors) {
14811476
nodes_to_update.push_back(deleted_neighbor_id);
1482-
neighbors_to_remove.push_back(deleted_neighbor_id);
14831477

14841478
auto *neighbor = getGraphDataByInternalId(deleted_neighbor_id);
14851479
lockNodeLinks(neighbor);
@@ -1516,7 +1510,6 @@ void HNSWIndex<DataType, DistType>::repairNodeConnections(idType node_id, size_t
15161510

15171511
for (idType not_chosen_neighbor : not_chosen_neighbors) {
15181512
if (node_orig_neighbours_set[not_chosen_neighbor]) {
1519-
neighbors_to_remove.push_back(not_chosen_neighbor);
15201513
nodes_to_update.push_back(not_chosen_neighbor);
15211514
}
15221515
}
@@ -1535,8 +1528,7 @@ void HNSWIndex<DataType, DistType>::repairNodeConnections(idType node_id, size_t
15351528

15361529
// Perform the actual updates for the node and the impacted neighbors while holding the nodes'
15371530
// locks.
1538-
mutuallyUpdateForRepairedNode(node_id, level, neighbors_to_remove, nodes_to_update,
1539-
chosen_neighbors, max_M_cur);
1531+
mutuallyUpdateForRepairedNode(node_id, level, nodes_to_update, chosen_neighbors, max_M_cur);
15401532
}
15411533

15421534
template <typename DataType, typename DistType>

0 commit comments

Comments
 (0)