Return an iterator over (key, value) pairs in the given range
(self, start_key=None, end_key=None)
| 457 | yield value |
| 458 | |
| 459 | def items(self, start_key=None, end_key=None) -> Iterator[Tuple[Any, Any]]: |
| 460 | """Return an iterator over (key, value) pairs in the given range""" |
| 461 | if start_key is None: |
| 462 | current = self.leaves |
| 463 | start_index = 0 |
| 464 | else: |
| 465 | current = self._find_leaf_for_key(start_key) |
| 466 | if current is None: |
| 467 | return |
| 468 | start_index = self._find_position_in_leaf(current, start_key) |
| 469 | |
| 470 | while current is not None: |
| 471 | for i in range(start_index, len(current.keys)): |
| 472 | key = current.keys[i] |
| 473 | if end_key is not None and key >= end_key: |
| 474 | return |
| 475 | yield (key, current.values[i]) |
| 476 | |
| 477 | current = current.next |
| 478 | start_index = 0 |
| 479 | |
| 480 | def _find_leaf_for_key(self, key: Any) -> Optional["LeafNode"]: |
| 481 | """Find the leaf node that contains or would contain the given key""" |