From 33486d71b1714986dd04dae4e7a222c401addb2e Mon Sep 17 00:00:00 2001 From: Robert Escriva Date: Thu, 2 Jan 2025 08:51:26 -0800 Subject: [PATCH] [BUG] Fix an off-by-one. 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. --- hnswlib/hnswalg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hnswlib/hnswalg.h b/hnswlib/hnswalg.h index e4e8150f..37efc905 100644 --- a/hnswlib/hnswalg.h +++ b/hnswlib/hnswalg.h @@ -1835,7 +1835,7 @@ namespace hnswlib std::unordered_set 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]);