Iterator for iterating over the records in a page. More...
#include <page_iterator.h>
Public Member Functions | |
PageIterator () | |
PageIterator (Page *page) | |
PageIterator (Page *page, const RecordId &record_id) | |
PageIterator & | operator++ () |
PageIterator | operator++ (int) |
bool | operator== (const PageIterator &rhs) const |
bool | operator!= (const PageIterator &rhs) const |
std::string | operator* () const |
SlotId | getNextUsedSlot (const SlotId start) const |
Iterator for iterating over the records in a page.
This class provides a forward-only iterator that iterates over all the records stored in a Page.
Definition at line 23 of file page_iterator.h.
badgerdb::PageIterator::PageIterator | ( | ) | [inline] |
Constructs an empty iterator.
Definition at line 28 of file page_iterator.h.
: page_(NULL) { current_record_ = {Page::INVALID_NUMBER, Page::INVALID_SLOT}; }
badgerdb::PageIterator::PageIterator | ( | Page * | page | ) | [inline] |
Constructors an iterator over the records in the given page, starting at the first record. Page must not be null.
page | Page to iterate over. |
Definition at line 39 of file page_iterator.h.
: page_(page) { assert(page_ != NULL); const SlotId used_slot = getNextUsedSlot(Page::INVALID_SLOT /* start */); current_record_ = {page_->page_number(), used_slot}; }
badgerdb::PageIterator::PageIterator | ( | Page * | page, |
const RecordId & | record_id | ||
) | [inline] |
Constructs an iterator over the records in the given page, starting at the given record.
page | Page to iterate over. |
record_id | ID of record to start iterator at. |
Definition at line 53 of file page_iterator.h.
: page_(page), current_record_(record_id) { }
SlotId badgerdb::PageIterator::getNextUsedSlot | ( | const SlotId | start | ) | const [inline] |
Returns the next used slot in the page after the given slot or Page::INVALID_SLOT if no slots are used after the given slot.
start | Slot to start search at. |
Definition at line 111 of file page_iterator.h.
{ SlotId slot_number = Page::INVALID_SLOT; for (SlotId i = start + 1; i <= page_->header_.num_slots; ++i) { const PageSlot* slot = page_->getSlot(i); if (slot->used) { slot_number = i; break; } } return slot_number; }
std::string badgerdb::PageIterator::operator* | ( | ) | const [inline] |
Dereferences the iterator, returning a copy of the current record in the page.
Definition at line 100 of file page_iterator.h.
{ return page_->getRecord(current_record_); }
PageIterator& badgerdb::PageIterator::operator++ | ( | ) | [inline] |
Advances the iterator to the next record in the page.
Definition at line 61 of file page_iterator.h.
{ assert(page_ != NULL); const SlotId used_slot = getNextUsedSlot(current_record_.slot_number); current_record_ = {page_->page_number(), used_slot}; return *this; }
bool badgerdb::PageIterator::operator== | ( | const PageIterator & | rhs | ) | const [inline] |
Returns true if this iterator is equal to the given iterator.
rhs | Iterator to compare against. |
Definition at line 84 of file page_iterator.h.
{ return page_->page_number() == rhs.page_->page_number() && current_record_ == rhs.current_record_; }