Skip to content

Commit 3bf7023

Browse files
rtjohnsoetwest
andauthored
Bidirectional Iterators (#588)
* tweak iterator api to make it easier to add bidirectionality * debugging btree reverse iteration * reduce time we hold locks during btree_split_child_leaf * further refine the locking in btree node splits and fix reverse iterator bug * btree iterator init at key other than min and add btree_iterator_seek * splinterdb_iterator_prev implmentated and working * clang formatting * improve the trunk iterator logic * corrections for pull request * more pull request fixes * assert fix * more pull request feedback * iterator stress test, bug fixes, formatting * final bit of pr feedback * formatting --------- Co-authored-by: Evan West <[email protected]>
1 parent 950df20 commit 3bf7023

19 files changed

+1537
-557
lines changed

include/splinterdb/splinterdb.h

+26-2
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,36 @@ splinterdb_iterator_deinit(splinterdb_iterator *iter);
330330

331331
// Checks that the iterator status is OK (no errors) and that get_current()
332332
// will succeed. If false, there are two possibilities:
333-
// 1. Iterator has passed the final item. In this case, status() == 0
333+
// 1. Iterator is out of bounds. In this case, status() == 0
334334
// 2. Iterator has encountered an error. In this case, status() != 0
335335
_Bool
336336
splinterdb_iterator_valid(splinterdb_iterator *iter);
337337

338-
// Attempts to advance the iterator to the next item.
338+
/*
339+
* splinterdb_iterator_can_next --
340+
* splinterdb_iterator_can_prev --
341+
*
342+
* Knowing the iterator is invalid does not provide enough information to
343+
* determine if next and prev are safe operations.
344+
*
345+
* These functions provide granular information on which operations are safe.
346+
* splinterdb_iterator_can_next == TRUE <-> splinterdb_iterator_next is safe
347+
* splinterdb_iterator_can_prev == TRUE <-> splinterdb_iterator_prev is safe
348+
*/
349+
_Bool
350+
splinterdb_iterator_can_prev(splinterdb_iterator *iter);
351+
352+
_Bool
353+
splinterdb_iterator_can_next(splinterdb_iterator *iter);
354+
355+
// Moves the iterator to the previous item.
356+
// Precondition for calling: splinterdb_iterator_can_prev() returns TRUE
357+
// Any error will cause valid() == false and be visible with status()
358+
void
359+
splinterdb_iterator_prev(splinterdb_iterator *iter);
360+
361+
// Moves the iterator to the next item.
362+
// Precondition for calling: splinterdb_iterator_can_next() returns TRUE
339363
// Any error will cause valid() == false and be visible with status()
340364
void
341365
splinterdb_iterator_next(splinterdb_iterator *iter);

0 commit comments

Comments
 (0)