@@ -182,6 +182,7 @@ template <typename Index, typename QueryType> class BatchIterator {
182
182
iteration_ = 0 ;
183
183
yielded_.clear ();
184
184
results_.clear ();
185
+ is_exhausted_ = false ;
185
186
}
186
187
187
188
// / @brief Adapts an internal neighbor to an external neighbor.
@@ -217,12 +218,14 @@ template <typename Index, typename QueryType> class BatchIterator {
217
218
// / @brief Return the batch number corresponding to the current buffer.
218
219
size_t batch_number () const { return iteration_; }
219
220
220
- // / @brief Return whether the entire entries in the index have been yielded .
221
+ // / @brief Returns whether iterator can find more neighbors or not for the given query .
221
222
// /
222
- // / The transition from not done to done will be triggered by a call to ``next()``.
223
- // / The contents of ``batch_number()`` and ``parameters_for_current_iteration()`` will
224
- // / then remain unchanged by subsequent invocations of ``next()``.
225
- bool done () const { return yielded_.size () == parent_->size (); }
223
+ // / The iterator is considered done when all the available nodes have been yielded or
224
+ // / when the search can not find any more neighbors. The transition from not done to
225
+ // / done will be triggered by a call to ``next()``. The contents of ``batch_number()``
226
+ // / and ``parameters_for_current_iteration()`` will then remain unchanged by subsequent
227
+ // / invocations of ``next()``.
228
+ bool done () const { return (yielded_.size () == parent_->size () || is_exhausted_); }
226
229
227
230
// / @brief Forces the next iteration to restart the search from scratch.
228
231
void restart_next_search () { restart_search_ = true ; }
@@ -306,6 +309,11 @@ template <typename Index, typename QueryType> class BatchIterator {
306
309
++iteration_;
307
310
restart_search_ = false ;
308
311
copy_from_scratch (batch_size);
312
+ // If result is empty after calling next(), mark the iterator as exhausted.
313
+ // The iterator will not be able to find any more neighbors.
314
+ if (results_.size () == 0 && batch_size > 0 ) {
315
+ is_exhausted_ = true ;
316
+ }
309
317
}
310
318
311
319
private:
@@ -318,6 +326,7 @@ template <typename Index, typename QueryType> class BatchIterator {
318
326
bool restart_search_ = true ; // Whether the next search should restart from scratch.
319
327
size_t extra_search_buffer_capacity_ =
320
328
svs::UNSIGNED_INTEGER_PLACEHOLDER; // Extra buffer capacity for the next search.
329
+ bool is_exhausted_ = false ; // Whether the iterator is exhausted.
321
330
};
322
331
323
332
// Deduction Guides
0 commit comments