/// <summary>Creates a new node with the right part of this node.</summary> /// <remarks> /// Creates a new node with the right part of this node. This should only be /// called on a full node /// </remarks> public virtual NeoDatis.Btree.IBTreeNode ExtractRightPart() { if (!IsFull()) { throw new NeoDatis.Btree.Exception.BTreeException("extract right part called on non full node" ); } // Creates an empty new node NeoDatis.Btree.IBTreeNode rightPart = btree.BuildNode(); int j = 0; for (int i = degree; i < maxNbKeys; i++) { rightPart.SetKeyAndValueAt(keys[i], values[i], j, false, false); keys[i] = null; values[i] = null; rightPart.SetChildAt(this, i, j, false); // TODO must we load all nodes to set new parent NeoDatis.Btree.IBTreeNode c = rightPart.GetChildAt(j, false); if (c != null) { c.SetParent(rightPart); } // rightPart.setChildAt(getChildAt(i,false), j); SetNullChildAt(i); j++; } // rightPart.setChildAt(getLastPositionChild(), j); rightPart.SetChildAt(this, GetMaxNbChildren() - 1, j, false); // correct father id NeoDatis.Btree.IBTreeNode c1 = rightPart.GetChildAt(j, false); if (c1 != null) { c1.SetParent(rightPart); } SetNullChildAt(maxNbChildren - 1); // resets last child keys[degree - 1] = null; // resets median element values[degree - 1] = null; // set numbers nbKeys = degree - 1; int originalNbChildren = nbChildren; nbChildren = System.Math.Min(nbChildren, degree); rightPart.SetNbKeys(degree - 1); rightPart.SetNbChildren(originalNbChildren - nbChildren); NeoDatis.Btree.Tool.BTreeValidator.ValidateNode(this); NeoDatis.Btree.Tool.BTreeValidator.ValidateNode(rightPart); NeoDatis.Btree.Tool.BTreeValidator.CheckDuplicateChildren(this, rightPart); return(rightPart); }