Split this branch node, returning the new right node and promoted key.
(&mut self)
| 546 | |
| 547 | /// Split this branch node, returning the new right node and promoted key. |
| 548 | pub fn split_data(&mut self) -> (BranchNode<K, V>, K) { |
| 549 | // For branch nodes, we need to ensure both resulting nodes have at least min_keys |
| 550 | // The middle key gets promoted, so we need at least min_keys on each side |
| 551 | let min_keys = self.min_keys(); |
| 552 | let _total_keys = self.keys.len(); |
| 553 | |
| 554 | // For branch splits, we promote the middle key, so we need: |
| 555 | // - Left side: min_keys keys |
| 556 | // - Middle: 1 key (promoted) |
| 557 | // - Right side: min_keys keys |
| 558 | // Total needed: min_keys + 1 + min_keys |
| 559 | let mid = min_keys; |
| 560 | |
| 561 | // Extract the promoted key |
| 562 | let promoted_key = self.keys[mid].clone(); |
| 563 | |
| 564 | // Split keys and children |
| 565 | let right_keys = self.keys.split_off(mid + 1); // Skip the promoted key |
| 566 | let right_children = self.children.split_off(mid + 1); |
| 567 | |
| 568 | // Remove the promoted key from left side |
| 569 | self.keys.pop(); // Remove the key that was promoted |
| 570 | |
| 571 | // Create the new right branch |
| 572 | let new_right = BranchNode { |
| 573 | capacity: self.capacity, |
| 574 | keys: right_keys, |
| 575 | children: right_children, |
| 576 | }; |
| 577 | |
| 578 | (new_right, promoted_key) |
| 579 | } |
| 580 | |
| 581 | // ============================================================================ |
| 582 | // STATUS CHECKS |
no test coverage detected