示例#1
0
        /// <summary>
        /// 从指定的流初始化树
        /// </summary>
        /// <param name="fromFile">指定的流</param>
        /// <param name="seekStart">流起始查询点</param>
        /// <returns>树</returns>
        public static BPlusTreeLong SetupFromExistingStream(Stream fromFile, long seekStart)
        {
            if (fromFile == null)
            {
                throw new ArgumentNullException("fromFile");
            }

            BPlusTreeLong tree = new BPlusTreeLong(fromFile, seekStart, 100, 7, (byte)1); // dummy values for nodesize, keysize

            tree.ReadHeader();
            tree.BlockFile = BlockFile.SetupFromExistingStream(fromFile, seekStart + HeaderSize, StoredConstants.BlockFileHeaderPrefix);

            if (tree.BlockFile.BlockSize != tree.BlockSize)
            {
                throw new BPlusTreeException("inner and outer block sizes should match");
            }

            if (tree.RootNodeBlockNumber != StoredConstants.NullBlockNumber)
            {
                tree.RootNode = BPlusTreeNode.MakeRoot(tree, true);
                tree.RootNode.LoadFromBlock(tree.RootNodeBlockNumber);
            }

            return(tree);
        }
示例#2
0
        /// <summary>
        /// 从指定的流初始化链式块文件
        /// </summary>
        /// <param name="fromFile">指定的流</param>
        /// <param name="seekStart">流起始索引点</param>
        /// <returns>链式块文件</returns>
        public static LinkedFile SetupFromExistingStream(Stream fromFile, long seekStart)
        {
            LinkedFile file = new LinkedFile(fromFile, seekStart, StoredConstants.LinkedFileHeaderPrefix, 100); // dummy block size for now

            file.ReadFileHeader();
            file.BlockFile = BlockFile.SetupFromExistingStream(fromFile, seekStart + file.FileHeaderSize, StoredConstants.BlockFileHeaderPrefix);
            return(file);
        }