Skip to content

Commit

Permalink
Properly reset BTree iteration state on boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt committed Oct 24, 2022
1 parent 2a11bb0 commit 3e86952
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/btree/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl BTreeIterState {

fn exit(&mut self, direction: IterDirection) -> bool {
loop {
if self.state.len() < 2 {
if self.state.is_empty() {
return true
}
self.state.pop();
Expand Down
4 changes: 4 additions & 0 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,10 @@ mod tests {
iter.seek_to_first().unwrap();
assert_eq!(iter.next().unwrap(), Some((key1.clone(), b"value1".to_vec())));
assert_eq!(iter.next().unwrap(), None);
assert_eq!(iter.prev().unwrap(), Some((key1.clone(), b"value1".to_vec())));
assert_eq!(iter.prev().unwrap(), None);
assert_eq!(iter.next().unwrap(), Some((key1.clone(), b"value1".to_vec())));
assert_eq!(iter.next().unwrap(), None);

iter.seek_to_first().unwrap();
assert_eq!(iter.next().unwrap(), Some((key1.clone(), b"value1".to_vec())));
Expand Down

0 comments on commit 3e86952

Please sign in to comment.