Esempio n. 1
0
        public void ReadData <T> (ref BTreeValue entry, Deserializer <T> deserializer, out T value)
        {
            var keyType = entry.KeyType;

            if (keyType == 0)
            {
                throw new InvalidDataException();

                fixed(BTreeValue *pEntry = &entry)
                ReadData(pEntry, keyType, deserializer, out value);
        }
Esempio n. 2
0
        public void WriteKey(ref BTreeValue btreeValue, TangleKey key)
        {
            var prefixSize = Math.Min(key.Data.Count, BTreeValue.KeyPrefixSize);

            fixed(byte *pPrefix = btreeValue.KeyPrefix)
            Unsafe.WriteBytes(pPrefix, 0, key.Data.Array, key.Data.Offset, prefixSize);

            if (prefixSize < key.Data.Count)
            {
                using (var keyRange = KeyStream.AccessRange(btreeValue.KeyOffset, btreeValue.KeyLength, MemoryMappedFileAccess.Write))
                    Unsafe.WriteBytes(keyRange.Pointer, 0, key.Data);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Inserts a new value and leaf into the specified BTree node at the specified position. Existing value(s) and leaves are moved.
        /// </summary>
        /// <param name="nodeIndex">The index of the node to insert into.</param>
        /// <param name="valueIndex">The index of the value to move forward.</param>
        /// <param name="value">The BTreeValue containing information on the value. It must be fully filled in.</param>
        /// <param name="leaf">The leaf associated with the new value.</param>
        private void Insert(long nodeIndex, uint valueIndex, ref BTreeValue value, ref BTreeLeaf leaf)
        {
            using (var range = PrepareForInsert(nodeIndex, valueIndex)) {
                var pNode   = (BTreeNode *)range.Pointer;
                var pValues = (BTreeValue *)(range.Pointer + BTreeNode.OffsetOfValues);
                var pLeaves = (BTreeLeaf *)(range.Pointer + BTreeNode.OffsetOfLeaves);

                pValues[valueIndex]     = value;
                pLeaves[valueIndex + 1] = leaf;

                UnlockNode(range);
            }
        }
Esempio n. 4
0
 // BTreeValue must be fully prepared for the write operation:
 //  KeyOffset/KeyLength must be filled in.
 //  DataOffset/DataLength must be filled in.
 //  The BTreeValue's IsValid must be 0.
 // newOffset must specify the offset within the data stream where the data is to be written.
 //  In most cases this should be equal to DataOffset, but in the case of AppendData it will be different.
 private void WriteData(ref BTreeValue btreeValue, ArraySegment <byte> data, bool append, long?dataOffset, uint size)
 {
     if (btreeValue.KeyType != 0)
         throw new InvalidDataException(); }