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

Method insert

python/bplustree/bplus_tree.py:746–761  ·  view source on GitHub ↗

Insert a key-value pair. Returns old value if key exists.

(self, key: Any, value: Any)

Source from the content-addressed store, hash-verified

744 return pos, exists
745
746 def insert(self, key: Any, value: Any) -> Optional[Any]:
747 """
748 Insert a key-value pair. Returns old value if key exists.
749 """
750 pos, exists = self.find_position(key)
751
752 if exists:
753 # Update existing value
754 old_value = self.values[pos]
755 self.values[pos] = value
756 return old_value
757 else:
758 # Insert new key-value pair
759 self.keys.insert(pos, key)
760 self.values.insert(pos, value)
761 return None
762
763 def get(self, key: Any) -> Optional[Any]:
764 """Get value for a key, returns None if not found"""

Callers 15

test_leaf_node_insertMethod · 0.95
test_leaf_node_fullMethod · 0.95
split_and_insertMethod · 0.95
conftest.pyFile · 0.45
migration_guide.pyFile · 0.45
range_queries.pyFile · 0.45
basic_usage.pyFile · 0.45
_insert_into_leafMethod · 0.45

Calls 1

find_positionMethod · 0.95

Tested by 4

test_leaf_node_insertMethod · 0.76
test_leaf_node_fullMethod · 0.76