コード例 #1
0
 public void EraseRange(long firstKeyIndex, long lastKeyIndex)
 {
     lock (_log)
     {
         _log.WriteUInt8((byte)KVReplayOperation.EraseRange);
         _log.WriteVUInt32(TrIndex);
         _log.WriteVInt64(firstKeyIndex);
         _log.WriteVInt64(lastKeyIndex);
         _log.FlushBuffer();
     }
     _tr.EraseRange(firstKeyIndex, lastKeyIndex);
 }
コード例 #2
0
ファイル: ODBDictionary.cs プロジェクト: srsman/BTDB
        public long RemoveRange(TKey start, bool includeStart, TKey end, bool includeEnd)
        {
            var startKeyBytes = KeyToByteArray(start);
            var endKeyBytes   = KeyToByteArray(end);

            _keyValueTrProtector.Start();
            _modificationCounter++;
            _keyValueTr.SetKeyPrefix(_prefix);
            var result = _keyValueTr.Find(ByteBuffer.NewAsync(startKeyBytes));

            if (result == FindResult.NotFound)
            {
                return(0);
            }
            var startIndex = _keyValueTr.GetKeyIndex();

            if (result == FindResult.Exact)
            {
                if (!includeStart)
                {
                    startIndex++;
                }
            }
            else if (result == FindResult.Previous)
            {
                startIndex++;
            }
            result = _keyValueTr.Find(ByteBuffer.NewAsync(endKeyBytes));
            var endIndex = _keyValueTr.GetKeyIndex();

            if (result == FindResult.Exact)
            {
                if (!includeEnd)
                {
                    endIndex--;
                }
            }
            else if (result == FindResult.Next)
            {
                endIndex--;
            }
            _keyValueTr.EraseRange(startIndex, endIndex);
            return(Math.Max(0, endIndex - startIndex + 1));
        }
コード例 #3
0
ファイル: ODBSet.cs プロジェクト: yardee/BTDB
        public long RemoveRange(AdvancedEnumeratorParam <TKey> param)
        {
            _modificationCounter++;

            _keyValueTr.FindFirstKey(_prefix);
            var  prefixIndex = _keyValueTr.GetKeyIndex();
            long startIndex;
            long endIndex;

            if (param.EndProposition == KeyProposition.Ignored)
            {
                _keyValueTr.FindLastKey(_prefix);
                endIndex = _keyValueTr.GetKeyIndex() - prefixIndex - 1;
            }
            else
            {
                var keyBytes = KeyToByteArray(param.End);
                switch (_keyValueTr.Find(keyBytes, (uint)_prefix.Length))
                {
                case FindResult.Exact:
                    endIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
                    if (param.EndProposition == KeyProposition.Excluded)
                    {
                        endIndex--;
                    }

                    break;

                case FindResult.Previous:
                    endIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
                    break;

                case FindResult.Next:
                    endIndex = _keyValueTr.GetKeyIndex() - prefixIndex - 1;
                    break;

                case FindResult.NotFound:
                    endIndex = -1;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            if (param.StartProposition == KeyProposition.Ignored)
            {
                startIndex = 0;
            }
            else
            {
                var keyBytes = KeyToByteArray(param.Start);
                switch (_keyValueTr.Find(keyBytes, (uint)_prefix.Length))
                {
                case FindResult.Exact:
                    startIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
                    if (param.StartProposition == KeyProposition.Excluded)
                    {
                        startIndex++;
                    }

                    break;

                case FindResult.Previous:
                    startIndex = _keyValueTr.GetKeyIndex() - prefixIndex + 1;
                    break;

                case FindResult.Next:
                    startIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
                    break;

                case FindResult.NotFound:
                    startIndex = 0;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            _keyValueTr.EraseRange(prefixIndex + startIndex, prefixIndex + endIndex);
            _count = -1;
            return(Math.Max(0, endIndex - startIndex + 1));
        }
コード例 #4
0
 public void EraseRange(long firstKeyIndex, long lastKeyIndex)
 {
     EraseRangeCount++;
     _keyValueDBTransaction.EraseRange(firstKeyIndex, lastKeyIndex);
 }