BadgerDB
 All Classes Namespaces Functions Variables Typedefs Friends Pages
Public Member Functions | List of all members
badgerdb::PageIterator Class Reference

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)
 
PageIteratoroperator++ ()
 
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
 

Detailed Description

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.

Constructor & Destructor Documentation

badgerdb::PageIterator::PageIterator ( )
inline

Constructs an empty iterator.

Definition at line 28 of file page_iterator.h.

29  : page_(NULL) {
30  current_record_ = {Page::INVALID_NUMBER, Page::INVALID_SLOT};
31  }
static const SlotId INVALID_SLOT
Definition: page.h:128
static const PageId INVALID_NUMBER
Definition: page.h:123
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.

Parameters
pagePage to iterate over.

Definition at line 39 of file page_iterator.h.

40  : page_(page) {
41  assert(page_ != NULL);
42  const SlotId used_slot = getNextUsedSlot(Page::INVALID_SLOT /* start */);
43  current_record_ = {page_->page_number(), used_slot};
44  }
SlotId getNextUsedSlot(const SlotId start) const
PageId page_number() const
Definition: page.h:193
static const SlotId INVALID_SLOT
Definition: page.h:128
std::uint16_t SlotId
Identifier for a slot in a page.
Definition: types.h:20
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.

Parameters
pagePage to iterate over.
record_idID of record to start iterator at.

Definition at line 53 of file page_iterator.h.

54  : page_(page),
55  current_record_(record_id) {
56  }

Member Function Documentation

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.

Parameters
startSlot to start search at.
Returns
Next used slot after given slot or Page::INVALID_SLOT.

Definition at line 111 of file page_iterator.h.

111  {
112  SlotId slot_number = Page::INVALID_SLOT;
113  for (SlotId i = start + 1; i <= page_->header_.num_slots; ++i) {
114  const PageSlot* slot = page_->getSlot(i);
115  if (slot->used) {
116  slot_number = i;
117  break;
118  }
119  }
120  return slot_number;
121  }
SlotId num_slots
Definition: page.h:43
static const SlotId INVALID_SLOT
Definition: page.h:128
std::uint16_t SlotId
Identifier for a slot in a page.
Definition: types.h:20
std::string badgerdb::PageIterator::operator* ( ) const
inline

Dereferences the iterator, returning a copy of the current record in the page.

Returns
Record in page.

Definition at line 100 of file page_iterator.h.

100  {
101  return page_->getRecord(current_record_);
102  }
std::string getRecord(const RecordId &record_id) const
Definition: page.cpp:43
PageIterator& badgerdb::PageIterator::operator++ ( )
inline

Advances the iterator to the next record in the page.

Definition at line 61 of file page_iterator.h.

61  {
62  assert(page_ != NULL);
63  const SlotId used_slot = getNextUsedSlot(current_record_.slot_number);
64  current_record_ = {page_->page_number(), used_slot};
65 
66  return *this;
67  }
SlotId getNextUsedSlot(const SlotId start) const
SlotId slot_number
Definition: types.h:39
PageId page_number() const
Definition: page.h:193
std::uint16_t SlotId
Identifier for a slot in a page.
Definition: types.h:20
bool badgerdb::PageIterator::operator== ( const PageIterator rhs) const
inline

Returns true if this iterator is equal to the given iterator.

Parameters
rhsIterator to compare against.
Returns
True if other iterator is equal to this one.

Definition at line 84 of file page_iterator.h.

84  {
85  return page_->page_number() == rhs.page_->page_number() &&
86  current_record_ == rhs.current_record_;
87  }
PageId page_number() const
Definition: page.h:193

The documentation for this class was generated from the following file: