/// <summary> /// 从指定的流初始化树 /// </summary> /// <param name="fromFile">指定的流</param> /// <param name="seekStart">流起始查询点</param> /// <param name="keyLength">键长度</param> /// <param name="nodeCapacity">节点容量</param> /// <returns>树</returns> public static BPlusTree InitializeInStream(Stream fromFile, long seekStart, int keyLength, int nodeCapacity) { if (fromFile == null) { throw new ArgumentNullException("fromFile"); } if (fromFile.Length > seekStart) { throw new BPlusTreeException("Cannot initialize tree inside written area of stream."); } BPlusTree tree = new BPlusTree(fromFile, seekStart, keyLength, nodeCapacity, (byte)1); tree.WriteHeader(); tree.BlockFile = BlockFile.InitializeInStream( fromFile, seekStart + HeaderSize, StorageConstants.BlockFileHeaderPrefix, tree.BlockSize); return(tree); }
public static BPlusTreeNode BinaryRoot( BPlusTreeNode oldRoot, string splitFirstKey, BPlusTreeNode splitNode, BPlusTree tree) { if (oldRoot == null) { throw new ArgumentNullException("oldRoot"); } if (splitNode == null) { throw new ArgumentNullException("splitNode"); } BPlusTreeNode newRoot = MakeRoot(tree, false); newRoot._childKeys[0] = splitFirstKey; oldRoot.ResetParent(newRoot, 0); splitNode.ResetParent(newRoot, 1); return(newRoot); }
/// <summary> /// 为树构造一个根节点 /// </summary> /// <param name="tree">指定树</param> /// <param name="isLeaf">是否为叶节点</param> /// <returns>根节点</returns> public static BPlusTreeNode MakeRoot(BPlusTree tree, bool isLeaf) { return(new BPlusTreeNode(tree, null, -1, isLeaf)); }