Skip to content

Commit 6995246

Browse files
authored
Fix: Avoid duplicate neighbor slots in HNSW reverse links (#699)
* Fix: Avoid duplicate neighbor slots in HNSW reverse links * Improve: Use `std::find` instead of `std::all_of` for neighbor presence check in `index_gt::form_reverse_links_` * Fix: Use `std::find_if` for close_header neighbor check
1 parent 7fbf086 commit 6995246

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

include/usearch/index.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3901,7 +3901,10 @@ class index_gt {
39013901
// If `new_slot` is already present in the neighboring connections of `close_slot`
39023902
// then no need to modify any connections or run the heuristics.
39033903
if (close_header.size() < connectivity_max) {
3904-
close_header.push_back(new_slot);
3904+
if (std::find_if(close_header.begin(), close_header.end(),
3905+
[new_slot](compressed_slot_t slot) { return slot == new_slot; }) == close_header.end()) {
3906+
close_header.push_back(new_slot);
3907+
}
39053908
continue;
39063909
}
39073910

0 commit comments

Comments
 (0)