コード例 #1
0
        public void FinalizeInsert(StreamRange range)
        {
            UnlockNode(range);

            var pHeader = (BTreeHeader *)_HeaderRange.Pointer;

            Interlocked.Increment(ref pHeader->ItemCount);
        }
コード例 #2
0
        public void UnlockNode(StreamRange range)
        {
            var pNode = (BTreeNode *)range.Pointer;

            if (pNode->IsValid != 0)
            {
                throw new InvalidDataException();
            }

            pNode->IsValid = 1;
        }
コード例 #3
0
        public uint GetValueDataTotalBytes(StreamRange nodeRange, long valueIndex, ushort keyType)
        {
            unchecked {
                var pEntry = (BTreeValue *)(nodeRange.Pointer + BTreeNode.OffsetOfValues + (valueIndex * BTreeValue.Size));

                if (pEntry->KeyType != keyType)
                {
                    throw new InvalidDataException();
                }

                return(pEntry->DataLength + pEntry->ExtraDataBytes);
            }
        }
コード例 #4
0
        public BTreeValue *LockValue(StreamRange nodeRange, long valueIndex, ushort keyType)
        {
            unchecked {
                var pEntry = (BTreeValue *)(nodeRange.Pointer + BTreeNode.OffsetOfValues + (valueIndex * BTreeValue.Size));

                if (pEntry->KeyType != keyType)
                {
                    throw new InvalidDataException();
                }

                pEntry->KeyType = 0;

                return(pEntry);
            }
        }
コード例 #5
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();
        }
コード例 #6
0
 void IndexStream_LengthChanged(object sender, EventArgs e)
 {
     _HeaderRange = IndexStream.AccessRangeUncached(0, BTreeHeader.Size);
 }
コード例 #7
0
        public void WriteNewKey(StreamRange nodeRange, uint valueIndex, TangleKey key)
        {
            long position = BTreeNode.OffsetOfValues + (valueIndex * BTreeValue.Size);

            WriteNewKey((BTreeValue *)(nodeRange.Pointer + position), key);
        }