private void SplitChild(Node parent, int i, Node child) { var z = new Node(); for (int j = 0; j < _lowerBound; j++) { z.AddOrUpdateKey(j, child[j + _t]); } if (!child.IsLeaf) { for (int j = 0; j < _t; j++) { z.AddOrUpdateChild(j, child.Children[j + _t]); } } for (int j = parent.Count(); j > i; j--) { parent.AddOrUpdateChild(j + 1, parent.Children[j]); } parent.AddOrUpdateChild(i + 1, z); for (int j = parent.Count() - 1; j >= i; j--) { parent.AddOrUpdateKey(j + 1, parent[j]); } parent.AddOrUpdateKey(i, child[_lowerBound]); child._keys.RemoveRange(_lowerBound, child.Count() - _t + 1); }
private void InsertNonFull(Node child, NodeKey key) { int i = child.Count() - 1; if (child.IsLeaf) { while (i >= 0 && key.Key < child[i].Key) { child[i + 1].Key = child[i].Key; i--; } child.AddOrUpdateKey(i + 1, key); } else { while (i >= 0 && key.Key < child[i].Key) { i--; } i++; if (child.Children[i].Count() == _upperBound) { SplitChild(child, i, child.Children[i]); if (key.Key > child[i].Key) { i++; } } InsertNonFull(child.Children[i], key); } }