예제 #1
0
            public bool MoveNext()
            {
                AssertNoChanges();

                while (_currentPage != null)
                {
                    _currentPage.LastSearchPosition++;
                    if (_currentPage.LastSearchPosition < _currentPage.NumberOfEntries)
                    {
                        // run out of entries, need to select the next page...
                        while (_currentPage.IsBranch)
                        {
                            _parent._cursor.Push(_currentPage);
                            var childParentNumber = _currentPage.GetEntry(_currentPage.LastSearchPosition)->PageNumber;
                            _currentPage = _parent.GetReadOnlyPage(childParentNumber);

                            _currentPage.LastSearchPosition = 0;
                        }
                        return(true);// there is another entry in this page
                    }
                    if (_parent._cursor.Count == 0)
                    {
                        break;
                    }
                    _currentPage = _parent._cursor.Pop();
                }
                _currentPage = null;

                return(false);
            }
예제 #2
0
            public bool MovePrev()
            {
                AssertNoChanges();

                if (_currentPage == null)
                {
                    throw new InvalidOperationException("No current page was set");
                }

                while (_currentPage != null)
                {
                    _currentPage.LastSearchPosition--;
                    if (_currentPage.LastSearchPosition >= 0)
                    {
                        // run out of entries, need to select the next page...
                        while (_currentPage.IsBranch)
                        {
                            _parent._cursor.Push(_currentPage);
                            var childParentNumber = _currentPage.GetEntry(_currentPage.LastSearchPosition)->PageNumber;
                            _currentPage = _parent.GetReadOnlyPage(childParentNumber);

                            _currentPage.LastSearchPosition = _currentPage.NumberOfEntries - 1;
                        }
                        return(true);// there is another entry in this page
                    }
                    if (_parent._cursor.Count == 0)
                    {
                        break;
                    }
                    _currentPage = _parent._cursor.Pop();
                }
                _currentPage = null;

                return(false);
            }
            public bool MoveNext()
            {
                AssertNoChanges();

                if (_currentPage == null)
                {
                    throw new InvalidOperationException("No current page was set");
                }

                while (_currentPage != null)
                {
                    _currentPage.LastSearchPosition++;
                    if (_currentPage.LastSearchPosition < _currentPage.NumberOfEntries)
                    {
                        // run out of entries, need to select the next page...
                        while (_currentPage.IsBranch)
                        {
                            _parent._cursor.Push(_currentPage);
                            var childParentNumber = _parent.PageValueFor(_currentPage, _currentPage.LastSearchPosition);
                            _currentPage = _parent._tx.GetReadOnlyFixedSizeTreePage(childParentNumber);

                            _currentPage.LastSearchPosition = 0;
                        }
                        return(true);// there is another entry in this page
                    }
                    if (_parent._cursor.Count == 0)
                    {
                        break;
                    }
                    _currentPage = _parent._cursor.Pop();
                }
                _currentPage = null;

                return(false);
            }
예제 #4
0
            public bool Skip(long count)
            {
                if (count > 0)
                {
                    if (MoveNext(count) == false)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (MovePrev(-count) == false)
                    {
                        return(false);
                    }
                }

                var seek = _currentPage != null && _currentPage.LastSearchPosition != _currentPage.NumberOfEntries;

                if (seek == false)
                {
                    _currentPage = null;
                }
                return(seek);
            }
예제 #5
0
            private bool MovePrev(long skip)
            {
                AssertNoChanges();

                if (_currentPage == null || _currentPage.IsLeaf == false)
                {
                    throw new InvalidOperationException("No current page was set or is wasn't a leaf!");
                }

                while (skip >= 0)
                {
                    var skipInPage = (int)Math.Min(_currentPage.LastSearchPosition, skip);
                    skip -= skipInPage;
                    _currentPage.LastSearchPosition -= skipInPage;
                    if (skip == 0)
                    {
                        return(true);
                    }

                    while (true)
                    {
                        if (_parent._cursor.TryPeek(out var parent) == false)
                        {
                            return(false);
                        }

                        parent.LastSearchPosition--;

                        if (parent.LastSearchPosition < 0)
                        {
                            _parent._cursor.Pop();
                            continue;
                        }

                        var nextChildPageNumber = parent.GetEntry(parent.LastSearchPosition)->PageNumber;
                        var childPage           = _parent.GetReadOnlyPage(nextChildPageNumber);

                        // we move one beyond the end of elements because in both cases
                        // (branch and leaf) we first decrement and then run it
                        childPage.LastSearchPosition = childPage.NumberOfEntries;
                        if (childPage.IsBranch)
                        {
                            _parent._cursor.Push(childPage);
                            continue;
                        }

                        _currentPage = childPage;
                        break;
                    }
                }
                _currentPage = null;

                return(false);
            }
예제 #6
0
            public bool Skip(int count)
            {
                if (count != 0)
                {
                    for (int i = 0; i < Math.Abs(count); i++)
                    {
                        if (!MoveNext())
                        {
                            break;
                        }
                    }
                }

                var seek = _currentPage != null && _currentPage.LastSearchPosition != _currentPage.NumberOfEntries;

                if (seek == false)
                {
                    _currentPage = null;
                }
                return(seek);
            }
예제 #7
0
            private bool MoveNext(long skip)
            {
                AssertNoChanges();

                if (_currentPage == null || _currentPage.IsLeaf == false)
                {
                    throw new InvalidOperationException("No current page was set or is wasn't a leaf!");
                }

                while (skip >= 0)
                {
                    var skipInPage = (int)Math.Min(_currentPage.NumberOfEntries - _currentPage.LastSearchPosition, skip);
                    skip -= skipInPage;
                    _currentPage.LastSearchPosition += skipInPage;
                    if (skip == 0)
                    {
                        if (_currentPage.LastSearchPosition >= _currentPage.NumberOfEntries)
                        {
                            return(MoveNext());
                        }
                        return(true);
                    }

                    while (true)
                    {
                        if (_parent._cursor.TryPeek(out var parent) == false)
                        {
                            return(false);
                        }

                        parent.LastSearchPosition++;

                        if (parent.LastSearchPosition >= parent.NumberOfEntries)
                        {
                            _parent._cursor.Pop();
                            continue;
                        }

                        var nextChildPageNumber = parent.GetEntry(parent.LastSearchPosition)->PageNumber;
                        var childPage           = _parent.GetReadOnlyPage(nextChildPageNumber);

                        if (childPage.IsBranch)
                        {
                            // we set it to negative one so the first
                            // call will increment that to zero
                            childPage.LastSearchPosition = -1;
                            _parent._cursor.Push(childPage);
                            continue;
                        }
                        else
                        {
                            childPage.LastSearchPosition = 0;
                        }

                        _currentPage = childPage;
                        break;
                    }
                }
                _currentPage = null;

                return(false);
            }
예제 #8
0
 public bool SeekToLast()
 {
     _currentPage = _parent.FindPageFor(long.MaxValue);
     return(true);
 }
예제 #9
0
 public bool Seek(long key)
 {
     _currentPage = _parent.FindPageFor(key);
     return(_currentPage.LastMatch <= 0 || MoveNext());
 }