/// <summary> /// 从指定的流初始化树 /// </summary> /// <param name="fromFile">指定的流</param> /// <param name="seekStart">流起始查询点</param> /// <returns>树</returns> public static BPlusTree SetupFromExistingStream(Stream fromFile, long seekStart) { if (fromFile == null) { throw new ArgumentNullException("fromFile"); } BPlusTree tree = new BPlusTree(fromFile, seekStart, 100, 7, (byte)1); tree.ReadHeader(); tree.BlockFile = BlockFile.SetupFromExistingStream( fromFile, seekStart + HeaderSize, StorageConstants.BlockFileHeaderPrefix); if (tree.BlockFile.BlockSize != tree.BlockSize) { throw new BPlusTreeException("Inner and outer block sizes should match."); } if (tree.RootNodeBlockNumber != StorageConstants.NullBlockNumber) { tree.RootNode = BPlusTreeNode.MakeRoot(tree, true); tree.RootNode.LoadFromBlock(tree.RootNodeBlockNumber); } return(tree); }
/// <summary> /// 从指定的流初始化块文件 /// </summary> /// <param name="fromFile">指定的流</param> /// <param name="seekStart">流起始索引点</param> /// <param name="blockFileHeaderPrefix">块存储头部前缀</param> /// <returns>块文件</returns> public static BlockFile SetupFromExistingStream(Stream fromFile, long seekStart, byte[] blockFileHeaderPrefix) { BlockFile file = new BlockFile(fromFile, seekStart, blockFileHeaderPrefix, 100); // dummy block size for now file.ReadFileHeader(); return(file); }
/// <summary> /// 从指定的流初始化块文件 /// </summary> /// <param name="fromFile">指定的流</param> /// <param name="seekStart">流起始索引点</param> /// <param name="blockFileHeaderPrefix">块存储头部前缀</param> /// <param name="blockSize">块的大小</param> /// <returns>块文件</returns> public static BlockFile InitializeInStream(Stream fromFile, long seekStart, byte[] blockFileHeaderPrefix, int blockSize) { BlockFile file = new BlockFile(fromFile, seekStart, blockFileHeaderPrefix, blockSize); file.WriteFileHeader(); return(file); }
/// <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); }