Insert a key into a non-full node. Args: node: The non-full node to insert into. key: The key to insert.
(self, node: Node, key: int)
| 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. |
| 105 | |
| 106 | Args: |
| 107 | node: The non-full node to insert into. |
| 108 | key: The key to insert. |
| 109 | """ |
| 110 | i = len(node.keys) - 1 |
| 111 | while i >= 0 and node.keys[i] >= key: |
| 112 | i -= 1 |
| 113 | |
| 114 | if node.is_leaf: |
| 115 | node.keys.insert(i + 1, key) |
| 116 | else: |
| 117 | if len(node.children[i + 1].keys) >= self.max_number_of_keys: |
| 118 | self._split_child(node, i + 1) |
| 119 | if node.keys[i + 1] < key: |
| 120 | i += 1 |
| 121 | self._insert_to_nonfull_node(node.children[i + 1], key) |
| 122 | |
| 123 | def find(self, key: int) -> bool: |
| 124 | """Search for a key in the B-tree. |
no test coverage detected