Get the previous element, or return None if on the left boundary.
(self)
| 452 | self.parking_key = None |
| 453 | |
| 454 | def prev(self) -> ET | None: |
| 455 | """Get the previous element, or return None if on the left boundary.""" |
| 456 | self._maybe_unpark() |
| 457 | self.parking_key = None |
| 458 | if self.current_node is None: |
| 459 | # on a boundary |
| 460 | if self.current_index == 0: |
| 461 | # left boundary, there is no prev |
| 462 | return None |
| 463 | else: |
| 464 | assert self.current_index == 1 |
| 465 | # right boundary; seek to the actual boundary |
| 466 | # so we can do a prev() |
| 467 | self.current_node = self.btree.root |
| 468 | self.current_index = len(self.btree.root.elts) |
| 469 | self._seek_greatest() |
| 470 | while True: |
| 471 | if self.recurse: |
| 472 | if not self.increasing: |
| 473 | # We only want to recurse if we are continuing in the decreasing |
| 474 | # direction. |
| 475 | self._seek_greatest() |
| 476 | self.recurse = False |
| 477 | self.increasing = False |
| 478 | self.current_index -= 1 |
| 479 | if self.current_index >= 0: |
| 480 | elt = self.current_node.elts[self.current_index] |
| 481 | if not self.current_node.is_leaf: |
| 482 | self.recurse = True |
| 483 | self.parking_key = elt.key() |
| 484 | self.parking_key_read = True |
| 485 | return elt |
| 486 | else: |
| 487 | if len(self.parents) > 0: |
| 488 | self.current_node, self.current_index = self.parents.pop() |
| 489 | else: |
| 490 | self.current_node = None |
| 491 | self.current_index = 0 |
| 492 | return None |
| 493 | |
| 494 | def next(self) -> ET | None: |
| 495 | """Get the next element, or return None if on the right boundary.""" |