public bool Seek(Slice key) { if (_disposed) { throw new ObjectDisposedException("TreeIterator " + _tree.Name); } TreeNodeHeader * node; Func <Slice, TreeCursor> constructor; _currentPage = _tree.FindPageFor(key, node: out node, cursor: out constructor, allowCompressed: false); _cursor = constructor(key); _cursor.Pop(); if (node != null) { _prevKeyScope.Dispose(); _prevKeyScope = TreeNodeHeader.ToSlicePtr(_tx.Allocator, node, out _currentInternalKey); _currentKey = _currentInternalKey; if (DoRequireValidation) { return(this.ValidateCurrentKey(_tx, Current)); } return(true); } // The key is not found in the db, but we are Seek()ing for equals or starts with. // We know that the exact value isn't there, but it is possible that the next page has values // that is actually greater than the key, so we need to check it as well. _currentPage.LastSearchPosition = _currentPage.NumberOfEntries; // force next MoveNext to move to the next _page_. return(MoveNext()); }
public bool MovePrev() { if (_disposed) { throw new ObjectDisposedException("TreeIterator " + _tree.Name); } while (true) { _currentPage.LastSearchPosition--; if (_currentPage.LastSearchPosition >= 0) { // run out of entries, need to select the next page... while (_currentPage.IsBranch) { // In here we will also have the 'current' page (even if we are traversing a compressed node). if (_prefetch) { MaybePrefetchPagesReferencedBy(_currentPage); } _cursor.Push(_currentPage); var node = _currentPage.GetNode(_currentPage.LastSearchPosition); _currentPage = _tree.GetReadOnlyTreePage(node->PageNumber); if (_currentPage.IsCompressed) { DecompressedCurrentPage(); } _currentPage.LastSearchPosition = _currentPage.NumberOfEntries - 1; } // We should be prefetching data pages down here. if (_prefetch) { MaybePrefetchPagesReferencedBy(_currentPage); } var current = _currentPage.GetNode(_currentPage.LastSearchPosition); if (DoRequireValidation && this.ValidateCurrentKey(_tx, current) == false) { return(false); } _prevKeyScope.Dispose(); _prevKeyScope = TreeNodeHeader.ToSlicePtr(_tx.Allocator, current, out _currentInternalKey); _currentKey = _currentInternalKey; return(true);// there is another entry in this page } if (_cursor.PageCount == 0) { break; } _currentPage = _cursor.Pop(); } _currentPage = null; return(false); }
public bool MovePrev() { if (_disposed) { throw new ObjectDisposedException("TreeIterator " + _tree.Name); } while (true) { _currentPage.LastSearchPosition--; if (_currentPage.LastSearchPosition >= 0) { // run out of entries, need to select the next page... while (_currentPage.IsBranch) { _cursor.Push(_currentPage); var node = _currentPage.GetNode(_currentPage.LastSearchPosition); _currentPage = _tree.GetReadOnlyTreePage(node->PageNumber); _currentPage.LastSearchPosition = _currentPage.NumberOfEntries - 1; if (_prefetch && _currentPage.IsLeaf) { MaybePrefetchOverflowPages(_currentPage); } } var current = _currentPage.GetNode(_currentPage.LastSearchPosition); if (DoRequireValidation && this.ValidateCurrentKey(_tx, current) == false) { return(false); } _prevKeyScope.Dispose(); _prevKeyScope = TreeNodeHeader.ToSlicePtr(_tx.Allocator, current, out _currentInternalKey); _currentKey = _currentInternalKey; return(true);// there is another entry in this page } if (_cursor.PageCount == 0) { break; } _currentPage = _cursor.Pop(); } _currentPage = null; return(false); }
public bool Seek(Slice key) { if (_disposed) { throw new ObjectDisposedException("PageIterator"); } var current = _page.Search(_tx, key); if (current == null) { return(false); } _prevScopeDispose.Dispose(); _prevScopeDispose = TreeNodeHeader.ToSlicePtr(_tx.Allocator, current, out _currentInternalKey); _currentKey = _currentInternalKey; if (DoRequireValidation) { return(this.ValidateCurrentKey(_tx, current)); } return(true); }
private bool TrySetPosition() { if (_disposed) { throw new ObjectDisposedException("PageIterator"); } if (_page.LastSearchPosition < 0 || _page.LastSearchPosition >= _page.NumberOfEntries) { return(false); } var current = _page.GetNode(_page.LastSearchPosition); if (DoRequireValidation && this.ValidateCurrentKey(_tx, current) == false) { return(false); } _prevScopeDispose.Dispose(); _prevScopeDispose = TreeNodeHeader.ToSlicePtr(_tx.Allocator, current, out _currentInternalKey); _currentKey = _currentInternalKey; return(true); }