def __getitem__(self, key: K) -> Optional[V]: dummy = Entry(key, None) leaf = self.root.find_leaf(key) if dummy in leaf.entries: i = leaf.entries.index(dummy) return leaf.entries[i].value return None
def delete(self, key: K) -> ChildStatus: """ Remove the entry given by key If we're deficient, signal to the parent by returning REBALANCE """ dummy = Entry(key, None) i = bisect_left(self.entries, dummy) if self.entries[i] == dummy: del self.entries[i] if len(self.entries) < self.tree.MIN_KEYS: return ChildStatus.REBALANCE return ChildStatus.DONE
def insert(self, key: K, value: V) -> ChildStatus: """ Insert the key and value into this leaf. Notify the parent of the result. We either: 1. Are done 2. Split """ e = Entry(key, value) i = bisect_left(self.entries, e) if e in self.entries: # replace the old entry self.entries[i] = e else: # insert the entry self.entries.insert(i, e) if len(self.entries) > self.tree.MAX_KEYS: return ChildStatus.REBALANCE # inserted without a problem return ChildStatus.DONE
def __contains__(self, key: K) -> bool: dummy = Entry(key, None) leaf = self.root.find_leaf(key) return dummy in leaf.entries