Skip to content

Commit fa5fe5c

Browse files
authored
Maintain MutableBuffer::best_unvisited_ invariant in sort() (#221)
If DynamicVamana index contains vectors which are "marked-as-deleted", dynamic search buffer `cleanup()` call invalidates the `best_unvisited_` invariant which prevents proper usage in `BatchIterator`. This PR restores the invariant inside the `sort()` call.
1 parent d43a8a0 commit fa5fe5c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/svs/index/vamana/dynamic_search_buffer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,16 @@ template <typename Idx, typename Cmp = std::less<>> class MutableBuffer {
498498
}
499499
}
500500

501+
// TODO: Switch over to using iterators for the return values to avoid this.
502+
// Maintain best_unvisited_ invariant
503+
// cleanup() and std::sort() may invalidate best_unvisited_.
504+
// so, have to lookup the next unvisited from scratch.
505+
for (best_unvisited_ = 0; best_unvisited_ < roi_end_; ++best_unvisited_) {
506+
if (!candidates_[best_unvisited_].visited()) {
507+
break;
508+
}
509+
}
510+
501511
// Check if invariant 6 is active.
502512
// If so, drop invalid elements off the end until a valid element is found.
503513
if (slack() == 0) {

0 commit comments

Comments
 (0)