Exemple #1
0
        public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator()
        {
            long prevProtectionCounter   = 0;
            var  prevModificationCounter = 0;
            long pos = 0;

            while (true)
            {
                _keyValueTrProtector.Start();
                if (pos == 0)
                {
                    prevModificationCounter = _modificationCounter;
                    _keyValueTr.SetKeyPrefix(_prefix);
                    if (!_keyValueTr.FindFirstKey())
                    {
                        break;
                    }
                }
                else
                {
                    if (_keyValueTrProtector.WasInterupted(prevProtectionCounter))
                    {
                        if (prevModificationCounter != _modificationCounter)
                        {
                            ThrowModifiedDuringEnum();
                        }
                        _keyValueTr.SetKeyPrefix(_prefix);
                        if (!_keyValueTr.SetKeyIndex(pos))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (!_keyValueTr.FindNextKey())
                        {
                            break;
                        }
                    }
                }
                prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;
                var keyBytes   = _keyValueTr.GetKeyAsByteArray();
                var valueBytes = _keyValueTr.GetValueAsByteArray();
                var key        = ByteArrayToKey(keyBytes);
                var value      = ByteArrayToValue(valueBytes);
                yield return(new KeyValuePair <TKey, TValue>(key, value));

                pos++;
            }
        }
        public bool NextKey(out TKey key)
        {
            if (_seekState == SeekState.Ready)
            {
                _pos++;
            }
            if (_pos >= _count)
            {
                key = default(TKey);
                return(false);
            }

            _keyValueTrProtector.Start();
            if (_keyValueTrProtector.WasInterupted(_prevProtectionCounter))
            {
                _keyValueTr.SetKeyPrefix(_keyBytes);
                Seek();
            }
            else if (_seekState != SeekState.Ready)
            {
                Seek();
            }
            else
            {
                if (_ascending)
                {
                    _keyValueTr.FindNextKey();
                }
                else
                {
                    _keyValueTr.FindPreviousKey();
                }
            }

            _prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;
            //read key
            var keyData = _keyValueTr.GetKeyAsByteArray();
            var reader  = new ByteArrayReader(keyData);

            key = _keyReader(reader, null);
            return(true);
        }
Exemple #3
0
 public bool NextKey(out TKey key)
 {
     if (_seekState == SeekState.Ready)
     {
         _pos++;
     }
     if (_pos >= _count)
     {
         key = default(TKey);
         return(false);
     }
     _keyValueTrProtector.Start();
     if (_keyValueTrProtector.WasInterupted(_prevProtectionCounter))
     {
         if (_prevModificationCounter != _owner._modificationCounter)
         {
             ThrowModifiedDuringEnum();
         }
         _keyValueTr.SetKeyPrefix(_owner._prefix);
         Seek();
     }
     else if (_seekState != SeekState.Ready)
     {
         Seek();
     }
     else
     {
         if (_ascending)
         {
             _keyValueTr.FindNextKey();
         }
         else
         {
             _keyValueTr.FindPreviousKey();
         }
     }
     _prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;
     key = _owner.ByteArrayToKey(_keyValueTr.GetKeyAsByteArray());
     return(true);
 }