Skip to content

Commit

Permalink
[BUG] Fix an off-by-one.
Browse files Browse the repository at this point in the history
When changing from assertions to exceptions we introduced a change in
behavior.

```
    assert(data[j] > 0);
```

became

```
    if (data[j] < 0 || ...)
```

This matches the changes before Monday to check <= 0.
  • Loading branch information
rescrv committed Jan 2, 2025
1 parent e434afb commit 33486d7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion hnswlib/hnswalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ namespace hnswlib
std::unordered_set<tableint> s;
for (int j = 0; j < size; j++)
{
if (data[j] < 0 || data[j] >= cur_element_count || data[j] == i)
if (data[j] <= 0 || data[j] >= cur_element_count || data[j] == i)
throw std::runtime_error("HNSW Integrity failure: invalid neighbor index");
inbound_connections_num[data[j]]++;
s.insert(data[j]);
Expand Down

0 comments on commit 33486d7

Please sign in to comment.