void CalcPrefixKeyStart()
 {
     if (_prefixKeyStart >= 0)
     {
         return;
     }
     if (_cursor2 == null)
     {
         _cursor2 = BTreeRoot.CreateCursor();
     }
     if (_cursor2.FindFirst(_prefix))
     {
         _prefixKeyStart = _cursor2.CalcIndex();
     }
     else
     {
         _prefixKeyStart = -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;
 }
 public long GetKeyValueCount()
 {
     if (_prefixKeyCount >= 0)
     {
         return(_prefixKeyCount);
     }
     if (_prefix.Length == 0)
     {
         _prefixKeyCount = BTreeRoot.GetCount();
         return(_prefixKeyCount);
     }
     CalcPrefixKeyStart();
     if (_prefixKeyStart < 0)
     {
         _prefixKeyCount = 0;
         return(0);
     }
     if (_cursor2 == null)
     {
         _cursor2 = BTreeRoot.CreateCursor();
     }
     _prefixKeyCount = _cursor2.FindLastWithPrefix(_prefix) - _prefixKeyStart + 1;
     return(_prefixKeyCount);
 }