ByteBuffer GetCurrentKeyFromStack() { var result = ByteBuffer.NewAsync(new byte[_cursor.GetKeyLength()]); _cursor.FillByKey(result.AsSyncSpan()); return(result); }
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; }
public void CanInsertFirstData(byte[] key) { Assert.Equal(0, _root.GetCount()); var val = GetSampleValue(); Assert.True(_cursor.Upsert(key, val)); Assert.Equal(1, _root.GetCount()); Assert.Equal(key.Length, _cursor.GetKeyLength()); Assert.Equal(key, _cursor.FillByKey(new byte[key.Length]).ToArray()); Assert.Equal(val.Length, _cursor.GetValueLength()); Assert.Equal(val.ToArray(), _cursor.GetValue().ToArray()); }