Exemplo n.º 1
0
            public IEnumerator <TKey> GetEnumerator()
            {
                long prevProtectionCounter   = 0;
                var  prevModificationCounter = 0;
                long pos = 0;

                while (true)
                {
                    _parent._keyValueTrProtector.Start();
                    if (pos == 0)
                    {
                        prevModificationCounter = _parent._modificationCounter;
                        _parent._keyValueTr.SetKeyPrefix(_parent._prefix);
                        if (!_parent._keyValueTr.FindFirstKey())
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (_parent._keyValueTrProtector.WasInterupted(prevProtectionCounter))
                        {
                            if (prevModificationCounter != _parent._modificationCounter)
                            {
                                ThrowModifiedDuringEnum();
                            }
                            _parent._keyValueTr.SetKeyPrefix(_parent._prefix);
                            if (!_parent._keyValueTr.SetKeyIndex(pos))
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (!_parent._keyValueTr.FindNextKey())
                            {
                                break;
                            }
                        }
                    }

                    prevProtectionCounter = _parent._keyValueTrProtector.ProtectionCounter;
                    var keyBytes = _parent._keyValueTr.GetKey();
                    var key      = _parent.ByteArrayToKey(keyBytes);
                    yield return(key);

                    pos++;
                }
            }
Exemplo n.º 2
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);
 }