Skip to content

Commit 9b8d9c9

Browse files
authored
Fix crash on data products with lower than 10 count (#14)
In this change, we check whether the number of features is not lower than the count. If it is lower, we got out of bounds errors since it wanted to take a slice of the feature that it didn't have. Therefore we now set the count equal to the amount of features if the count is higher.
1 parent a1df635 commit 9b8d9c9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/indexer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ impl PointQuery {
202202
}
203203
}
204204

205-
pub fn search(p: &Point, num: usize, hnsw: &HnswIndex) -> Result<Vec<PointQuery>, SearchError> {
205+
pub fn search(p: &Point, mut num: usize, hnsw: &HnswIndex) -> Result<Vec<PointQuery>, SearchError> {
206+
// We need to set the number correctly
207+
// to make sure we don't go out of bounds
208+
let layer_len = hnsw.layer_len(0);
209+
if layer_len < num {
210+
num = layer_len;
211+
}
206212
let mut output: Vec<_> = iter::repeat(Neighbor {
207213
index: !0,
208214
distance: !0,

0 commit comments

Comments
 (0)