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

Method split

python/bplustree/bplus_tree.py:935–956  ·  view source on GitHub ↗

Split this branch node, returning the new right node

(self)

Source from the content-addressed store, hash-verified

933 return self.children[index]
934
935 def split(self) -> "BranchNode":
936 """Split this branch node, returning the new right node"""
937 # Find the midpoint
938 mid = len(self.keys) // 2
939
940 # Create new branch for right half
941 new_branch = BranchNode(self.capacity)
942
943 # The middle key becomes the separator to be promoted
944 separator_key = self.keys[mid]
945
946 # Move right half of keys to new branch (excluding the middle key)
947 new_branch.keys = self.keys[mid + 1 :]
948
949 # Move corresponding children to new branch
950 new_branch.children = self.children[mid + 1 :]
951
952 # Keep left half in this branch
953 self.keys = self.keys[:mid]
954 self.children = self.children[: mid + 1]
955
956 return new_branch, separator_key
957
958 def insert_child_and_split_if_needed(
959 self, child_index: int, separator_key: Any, new_child: "Node"

Callers 2

Calls 1

BranchNodeClass · 0.70

Tested by 1