MCPcopy Create free account
hub / github.com/carsonpo/haystackdb / split

Method split

src/structures/tree/node.rs:63–102  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

61 }
62
63 pub fn split(&mut self) -> Result<(K, Node<K, V>), io::Error> {
64 match self.node_type {
65 NodeType::Internal => {
66 let split_index = (self.keys.len() + 1) / 2;
67 let median_key = self.keys[split_index].clone();
68
69 let sibling_keys = self.keys.split_off(split_index + 1);
70 let sibling_children = self.children.split_off(split_index + 1);
71
72 let sibling = Node {
73 keys: sibling_keys,
74 values: Vec::new(),
75 children: sibling_children,
76 max_keys: self.max_keys,
77 node_type: NodeType::Internal,
78 };
79
80 self.keys.pop();
81
82 Ok((median_key, sibling))
83 }
84 NodeType::Leaf => {
85 let split_index = (self.keys.len() + 1) / 2;
86 let median_key = self.keys[split_index].clone();
87
88 let sibling_keys = self.keys.split_off(split_index);
89 let sibling_values = self.values.split_off(split_index);
90
91 let sibling = Node {
92 keys: sibling_keys,
93 values: sibling_values,
94 children: Vec::new(),
95 max_keys: self.max_keys,
96 node_type: NodeType::Leaf,
97 };
98
99 Ok((median_key, sibling))
100 }
101 }
102 }
103}
104impl<K, V> Default for Node<K, V> {
105 fn default() -> Self {

Callers 5

insertMethod · 0.45
insert_non_fullMethod · 0.45
batch_insertMethod · 0.45
insertMethod · 0.45
insert_non_fullMethod · 0.45

Calls 2

lenMethod · 0.80
cloneMethod · 0.80

Tested by

no test coverage detected