MCPcopy
hub / github.com/keon/algorithms / insert_key

Method insert_key

algorithms/data_structures/b_tree.py:88–101  ·  view source on GitHub ↗

Insert a key into the B-tree. Args: key: The key to insert.

(self, key: int)

Source from the content-addressed store, hash-verified

86 parent.children.insert(child_index + 1, new_right_child)
87
88 def insert_key(self, key: int) -> None:
89 """Insert a key into the B-tree.
90
91 Args:
92 key: The key to insert.
93 """
94 if len(self.root.keys) >= self.max_number_of_keys:
95 new_root = Node()
96 new_root.children.append(self.root)
97 self.root = new_root
98 self._split_child(new_root, 0)
99 self._insert_to_nonfull_node(self.root, key)
100 else:
101 self._insert_to_nonfull_node(self.root, key)
102
103 def _insert_to_nonfull_node(self, node: Node, key: int) -> None:
104 """Insert a key into a non-full node.

Calls 3

_split_childMethod · 0.95
NodeClass · 0.70