taco-db  0.1.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
taco::Table::Iterator Class Reference

The Iterator interface for scanning the heap file. More...

#include <storage/Table.h>

Public Member Functions

 Iterator ()
 Constructs an invalid iterator. More...
 
 ~Iterator ()
 Destructs an iterator. More...
 
 Iterator (Iterator &&it)=default
 Default move constructor. More...
 
Iteratoroperator= (Iterator &&it)=default
 We can use the default move assignment only if EndScan does not do anything other than unpin the page and we use ScopedBufferId to store the buffer ID. More...
 
 Iterator (const Iterator &it)=delete
 Deleted copy constructor. More...
 
Iteratoroperator= (const Iterator &it)=delete
 Deleted copy assignment. More...
 
TableGetTable () const
 Returns the table. More...
 
const RecordGetCurrentRecord () const
 Returns the current record, which is only valid when a previous Next() call returns true. More...
 
RecordId GetCurrentRecordId () const
 Returns the record ID of the current record. More...
 
bool IsAtValidRecord () const
 Returns GetCurrentRecord().IsValid(). More...
 
bool Next ()
 Moves the iterator to the next record in the file. More...
 
void EndScan ()
 Ends the scan, which may perform operations that may throw errors such as releasing page pins. More...
 

Private Member Functions

 Iterator (Table *tbl, RecordId rid)
 Constructs an iterator right before the specified record ID. More...
 

Private Attributes

Tablem_table
 The table that the iterator is iterating on. More...
 
Record m_cur_record
 The current record the iterator is on if the most recent Next() call returns true. More...
 
ScopedBufferId m_pinned_bufid
 A pin on the page where the current record is located. More...
 
PageNumber m_lastpg_pid
 

Friends

class Table
 

Detailed Description

The Iterator interface for scanning the heap file.

Note: a call to Table::InsertRecord(), Table::UpdateRecord(), or Table::EraseRecord() may insert a new record and/or remove a record somewhere in the file. You do not have to worry about them in the heap file project as long as the implementation is able to return exactly all the records in the file, provided that there are no concurrent update operations, or there's only in-place update of the current record.

Constructor & Destructor Documentation

◆ Iterator() [1/4]

taco::Table::Iterator::Iterator ( )
inline

Constructs an invalid iterator.

◆ Iterator() [2/4]

taco::Table::Iterator::Iterator ( Table tbl,
RecordId  rid 
)
private

Constructs an iterator right before the specified record ID.

A Next() call will return the first valid record after that if any.

◆ ~Iterator()

taco::Table::Iterator::~Iterator ( )
inline

Destructs an iterator.

It should attemp to call EndScan() but may not throw any error.

◆ Iterator() [3/4]

taco::Table::Iterator::Iterator ( Iterator &&  it)
default

Default move constructor.

◆ Iterator() [4/4]

taco::Table::Iterator::Iterator ( const Iterator it)
delete

Deleted copy constructor.

Member Function Documentation

◆ EndScan()

void taco::Table::Iterator::EndScan ( )

Ends the scan, which may perform operations that may throw errors such as releasing page pins.

You should always explicitly calling EndScan() to avoid any error being thrown and caught in the destructor.

After the EndScan() call, the iterator becomes invalid and the only functions may be called on this iterator are EndScan() and the destructor (which should do nothing). Note that EndScan() may be called from the destructor after the table object is destructed in exception handling, so make sure not to dereference m_table in EndScan().

◆ GetCurrentRecord()

const Record& taco::Table::Iterator::GetCurrentRecord ( ) const
inline

Returns the current record, which is only valid when a previous Next() call returns true.

◆ GetCurrentRecordId()

RecordId taco::Table::Iterator::GetCurrentRecordId ( ) const
inline

Returns the record ID of the current record.

◆ GetTable()

Table* taco::Table::Iterator::GetTable ( ) const
inline

Returns the table.

It is only non-null when the iterator is a valid iterator and has not been ended.

◆ IsAtValidRecord()

bool taco::Table::Iterator::IsAtValidRecord ( ) const
inline

Returns GetCurrentRecord().IsValid().

◆ Next()

bool taco::Table::Iterator::Next ( )

Moves the iterator to the next record in the file.

Returns true if there is such a record, and the current record of this iterator stores a pointer to its buffer on a buffered page. The page pin should be held as long as the current record still points the buffer on the buffered page. Otherwise, it returns false.

Note: the tuples that appear on an earlier page of the file must be iterated before those that appear on a later page, and the tuples on the same page must be iterated in the order from the smallest occupied slot id to the largest occupied slot id.

◆ operator=() [1/2]

Iterator& taco::Table::Iterator::operator= ( const Iterator it)
delete

Deleted copy assignment.

◆ operator=() [2/2]

Iterator& taco::Table::Iterator::operator= ( Iterator &&  it)
default

We can use the default move assignment only if EndScan does not do anything other than unpin the page and we use ScopedBufferId to store the buffer ID.

Otherwise, you'll have to implement your own move assignment operator.

Friends And Related Function Documentation

◆ Table

friend class Table
friend

Member Data Documentation

◆ m_cur_record

Record taco::Table::Iterator::m_cur_record
private

The current record the iterator is on if the most recent Next() call returns true.

Otherwise, it should be invalid.

◆ m_lastpg_pid

PageNumber taco::Table::Iterator::m_lastpg_pid
private

◆ m_pinned_bufid

ScopedBufferId taco::Table::Iterator::m_pinned_bufid
private

A pin on the page where the current record is located.

◆ m_table

Table* taco::Table::Iterator::m_table
private

The table that the iterator is iterating on.


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