Beispiel #1
0
        public BTree(StreamSource storage, string prefix)
        {
            Storage = storage;
            Prefix  = prefix;

            IndexStream = Storage.Open(prefix + "index");
            KeyStream   = Storage.Open(prefix + "keys");
            DataStream  = Storage.Open(prefix + "data");

            VersionCheck(IndexStream);
            VersionCheck(KeyStream);
            VersionCheck(DataStream);

            bool needInit = IndexStream.Length < BTreeHeader.Size;

            IndexStream.LengthChanging += IndexStream_LengthChanging;
            IndexStream.LengthChanged  += IndexStream_LengthChanged;

            DataStream.LengthChanging += DataStream_LengthChanging;
            DataStream.LengthChanged  += DataStream_LengthChanged;

            _GetKeyOfEntry = ReadKey;

            _HeaderRange = IndexStream.AccessRangeUncached(0, BTreeHeader.Size);

            if (needInit)
            {
                InitializeBTree();
            }

            _FreelistBucketLocks = new object[FreelistIndex.BucketCount];
            for (int i = 0; i < _FreelistBucketLocks.Length; i++)
            {
                _FreelistBucketLocks[i] = new object();
            }

            EnsureFreelistExists();
        }