MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / items

Method items

python/tests/test_optimized_bplus_tree.py:269–292  ·  view source on GitHub ↗

Iterate over key-value pairs in range.

(self, start_key=None, end_key=None)

Source from the content-addressed store, hash-verified

267 return None
268
269 def items(self, start_key=None, end_key=None) -> Iterator[Tuple[Any, Any]]:
270 """Iterate over key-value pairs in range."""
271 # Find start leaf
272 if start_key is None:
273 current = self.leaves
274 else:
275 current = self.root
276 while not current.is_leaf():
277 current = current.get_child(start_key)
278
279 # Iterate through leaves
280 while current is not None:
281 start_pos = 0
282 if start_key is not None and current is self.root:
283 start_pos = current.find_position(start_key)
284
285 for i in range(start_pos, current.num_keys):
286 key = current.data[i]
287 if end_key is not None and key >= end_key:
288 return
289 yield (key, current.data[current.capacity + i])
290
291 current = current.next
292 start_key = None # Only apply to first leaf
293
294
295def test_optimized_performance():

Callers 15

range_queriesMethod · 0.45
test_empty_treeFunction · 0.45
test_single_itemFunction · 0.45
test_iteration_orderFunction · 0.45
verify_consistencyMethod · 0.45
run_fuzz_testMethod · 0.45

Calls 3

is_leafMethod · 0.45
get_childMethod · 0.45
find_positionMethod · 0.45

Tested by

no test coverage detected