Example #1
0
        public Span <byte> FillByKey(Span <byte> buffer)
        {
            AssertValid();
            var stack     = _stack;
            var keyLength = (int)stack[stack.Count - 1]._keyOffset;

            if (buffer.Length < keyLength || keyLength < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(buffer),
                                                      "Key has " + keyLength + " bytes, but provided buffer has only " + buffer.Length);
            }
            var offset = 0;
            var i      = 0u;

            while (offset < keyLength)
            {
                ref var stackItem = ref stack[i++];
                if (offset < stackItem._keyOffset - (stackItem._posInNode == -1 ? 0 : 1))
                {
                    var(keyPrefixSize, keyPrefixPtr) = NodeUtilsV.GetPrefixSizeAndPtr(stackItem._node);
                    unsafe
                    {
                        Unsafe.CopyBlockUnaligned(ref MemoryMarshal.GetReference(buffer.Slice(offset)),
                                                  ref Unsafe.AsRef <byte>(keyPrefixPtr.ToPointer()), keyPrefixSize);
                    }

                    offset += (int)keyPrefixSize;
                }

                if (stackItem._posInNode != -1)
                {
                    buffer[offset++] = stackItem._byte;
                }
            }
Example #2
0
        public IRootNode CreateWritableTransaction()
        {
            if (_writable)
            {
                throw new InvalidOperationException("Only readonly root node could be CreateWritableTransaction");
            }
            var node = new RootNodeV(_impl);

            node._writable     = true;
            node._root         = _root;
            node.CommitUlong   = CommitUlong;
            node.TransactionId = TransactionId + 1;
            node.TrLogFileId   = TrLogFileId;
            node.TrLogOffset   = TrLogOffset;
            node._ulongs       = _ulongs == null ? null : (ulong[])_ulongs.Clone();
            NodeUtilsV.Reference(_root);
            return(node);
        }
Example #3
0
        public IRootNode Snapshot()
        {
            var snapshot = new RootNodeV(_impl);

            snapshot._writable     = false;
            snapshot._root         = _root;
            snapshot.CommitUlong   = CommitUlong;
            snapshot.TransactionId = TransactionId;
            snapshot.TrLogFileId   = TrLogFileId;
            snapshot.TrLogOffset   = TrLogOffset;
            snapshot._ulongs       = _ulongs == null ? null : (ulong[])_ulongs.Clone();
            if (_writable)
            {
                TransactionId++;
            }
            NodeUtilsV.Reference(_root);
            return(snapshot);
        }