Skip to content

Commit cf4ff1a

Browse files
committed
Add get_min_item() and get_max_item().
These were removed to reduce code but they are actually needed by delete().
1 parent 52ac69d commit cf4ff1a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

pyperformance/data-files/benchmarks/bm_btree/run_benchmark.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@ def get_level(self):
133133
else:
134134
return 1 + self.nodes[0].get_level()
135135

136+
def get_min_item(self):
137+
"""() -> (key:anything, value:anything)
138+
Return the item with the minimal key.
139+
"""
140+
if self.is_leaf():
141+
return self.items[0]
142+
else:
143+
return self.nodes[0].get_min_item()
144+
145+
def get_max_item(self):
146+
"""() -> (key:anything, value:anything)
147+
Return the item with the maximal key.
148+
"""
149+
if self.is_leaf():
150+
return self.items[-1]
151+
else:
152+
return self.nodes[-1].get_max_item()
153+
136154
def delete(self, key):
137155
"""(key:anything)
138156
Delete the item with this key.

0 commit comments

Comments
 (0)