Split a full child node into two nodes. Args: parent: The parent node whose child is being split. child_index: The index of the child to split.
(self, parent: Node, child_index: int)
| 65 | self.root = Node() |
| 66 | |
| 67 | def _split_child(self, parent: Node, child_index: int) -> None: |
| 68 | """Split a full child node into two nodes. |
| 69 | |
| 70 | Args: |
| 71 | parent: The parent node whose child is being split. |
| 72 | child_index: The index of the child to split. |
| 73 | """ |
| 74 | new_right_child = Node() |
| 75 | half_max = self.max_number_of_keys // 2 |
| 76 | child = parent.children[child_index] |
| 77 | middle_key = child.keys[half_max] |
| 78 | new_right_child.keys = child.keys[half_max + 1 :] |
| 79 | child.keys = child.keys[:half_max] |
| 80 | |
| 81 | if not child.is_leaf: |
| 82 | new_right_child.children = child.children[half_max + 1 :] |
| 83 | child.children = child.children[: half_max + 1] |
| 84 | |
| 85 | parent.keys.insert(child_index, middle_key) |
| 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. |
no test coverage detected