// Commented by Olivier 05/11/2007 // persister.flush(); private void InsertNonFull(NeoDatis.Btree.IBTreeNode node, System.IComparable key , object value) { if (node.IsLeaf()) { node.InsertKeyAndValue(key, value); persister.SaveNode(node); return; } int position = node.GetPositionOfKey(key); // return an index starting // from 1 instead of 0 int realPosition = -position - 1; // If position is positive, the key must be inserted in this node if (position >= 0) { realPosition = position - 1; node.InsertKeyAndValue(key, value); persister.SaveNode(node); return; } // descend NeoDatis.Btree.IBTreeNode nodeToDescend = node.GetChildAt(realPosition, true); if (nodeToDescend.IsFull()) { Split(node, nodeToDescend, realPosition); if (node.GetKeyAt(realPosition).CompareTo(key) < 0) { nodeToDescend = node.GetChildAt(realPosition + 1, true); } } InsertNonFull(nodeToDescend, key, value); }
public virtual void Insert(System.IComparable key, object value) { // check if root is full if (root.IsFull()) { NeoDatis.Btree.IBTreeNode newRoot = BuildNode(); NeoDatis.Btree.IBTreeNode oldRoot = root; newRoot.SetChildAt(root, 0); newRoot.SetNbChildren(1); root = newRoot; Split(newRoot, oldRoot, 0); height++; persister.SaveNode(oldRoot); // TODO Remove the save of the new root : the save on the btree // should do the save on the new root(after introspector // refactoring) persister.SaveNode(newRoot); persister.SaveBTree(this); NeoDatis.Btree.Tool.BTreeValidator.ValidateNode(newRoot, true); } InsertNonFull(root, key, value); size++; persister.SaveBTree(this); }