예제 #1
0
        public void SingleOnlyKeyEraseWorks()
        {
            var val = GetSampleValue().ToArray();
            var key = new byte[2];

            _cursor.Upsert(key, val);
            Assert.Equal(1, _cursor.EraseTo(_cursor));
            Assert.False(_cursor.IsValid());
            Assert.Equal(0, _root.GetCount());
        }
예제 #2
0
 public void EraseRange(long firstKeyIndex, long lastKeyIndex)
 {
     if (firstKeyIndex < 0)
     {
         firstKeyIndex = 0;
     }
     if (lastKeyIndex >= GetKeyValueCount())
     {
         lastKeyIndex = _prefixKeyCount - 1;
     }
     if (lastKeyIndex < firstKeyIndex)
     {
         return;
     }
     MakeWrittable();
     firstKeyIndex += _prefixKeyStart;
     lastKeyIndex  += _prefixKeyStart;
     if (_cursor2 == null)
     {
         _cursor2 = ArtRoot.CreateCursor();
     }
     _cursor.SeekIndex(firstKeyIndex);
     _cursor2.SeekIndex(lastKeyIndex);
     _cursor.EraseTo(_cursor2);
     InvalidateCurrentKey();
     _prefixKeyCount -= lastKeyIndex - firstKeyIndex + 1;
 }
 public void EraseRange(long firstKeyIndex, long lastKeyIndex)
 {
     if (firstKeyIndex < 0)
     {
         firstKeyIndex = 0;
     }
     if (lastKeyIndex >= GetKeyValueCount())
     {
         lastKeyIndex = _prefixKeyCount - 1;
     }
     if (lastKeyIndex < firstKeyIndex)
     {
         return;
     }
     MakeWritable();
     firstKeyIndex += _prefixKeyStart;
     lastKeyIndex  += _prefixKeyStart;
     _cursor.SeekIndex(firstKeyIndex);
     if (lastKeyIndex != firstKeyIndex)
     {
         if (_cursor2 == null)
         {
             _cursor2 = BTreeRoot.CreateCursor();
         }
         _cursor2.SeekIndex(lastKeyIndex);
         var firstKey  = GetCurrentKeyFromStack();
         var secondKey = ByteBuffer.NewAsync(new byte[_cursor2.GetKeyLength()]);
         _cursor2.FillByKey(secondKey.AsSyncSpan());
         _keyValueDB.WriteEraseRangeCommand(firstKey, secondKey);
         _cursor.EraseTo(_cursor2);
     }
     else
     {
         _keyValueDB.WriteEraseOneCommand(GetCurrentKeyFromStack());
         _cursor.Erase();
     }
     InvalidateCurrentKey();
     _prefixKeyCount -= lastKeyIndex - firstKeyIndex + 1;
 }