wisc_db
Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
wiscdb::Page Class Reference

Class which represents a fixed-size database page containing records. More...

#include <page.h>

Public Member Functions

 Page ()
 
RecordId insertRecord (const char *record_data)
 
std::string getRecord (const RecordId &record_id) const
 
void updateRecord (const RecordId &record_id, const char *record_data)
 
void deleteRecord (const RecordId &record_id)
 
bool hasSpaceForRecord (const char *record_data) const
 
std::uint16_t getFreeSpace () const
 
PageId page_number () const
 
PageId next_page_number () const
 
PageIterator begin ()
 
PageIterator end ()
 
void print ()
 

Public Attributes

PageHeader header
 

Static Public Attributes

static const std::size_t SIZE
 
static const std::size_t DATA_SIZE = SIZE - sizeof(PageHeader)
 
static const PageId INVALID_NUMBER = 0
 
static const SlotId INVALID_SLOT = 0
 

Friends

class File
 
class PageIterator
 
class PageTest
 
class BufferTest
 

Detailed Description

Class which represents a fixed-size database page containing records.

This Page is heap-ordered, and handles variable-length records using slots. Slot meta-data is stored at the end of the file. A page is a fixed-size unit of data storage. Each page holds zero or more records, which consist of arbitrary binary data. Records are placed into slots and identified by a RecordId. Although a record's actual contents may be moved on the page, accessing a record by its slot is consistent.

Warning
This class is not threadsafe.

Definition at line 110 of file page.h.

Constructor & Destructor Documentation

wiscdb::Page::Page ( )

Constructs a new, uninitialized page.

Member Function Documentation

PageIterator wiscdb::Page::begin ( )

Returns an iterator at the first record in the page.

Returns
Iterator at first record of page.
void wiscdb::Page::deleteRecord ( const RecordId record_id)

Deletes the record with the given ID. Page is compacted upon delete to ensure that data of all records is contiguous. Slot array is compacted if the slot deleted is at the end of the slot array.

Parameters
record_idID of the record to delete.
Exceptions
InvalidRecordExceptionif passed record_id is invalid
PageIterator wiscdb::Page::end ( )

Returns an iterator representing the record after the last record in the page. This iterator should not be dereferenced.

Returns
Iterator representing record after the last record in the page.
std::uint16_t wiscdb::Page::getFreeSpace ( ) const

Returns this page's free space in bytes.

Returns
Free space in bytes.
std::string wiscdb::Page::getRecord ( const RecordId record_id) const

Returns the record with the given ID. Returned data is a copy of what is stored on the page; use updateRecord to change it.

See also
updateRecord
Parameters
record_idID of the record to return.
Returns
A copy of the record.
Exceptions
InvalidRecordExceptionif passed record_id is invalid
bool wiscdb::Page::hasSpaceForRecord ( const char *  record_data) const

Returns true if the page has enough free space to hold the given data.

Parameters
record_dataBytes that compose the record.
Returns
Whether the page can hold the data.
RecordId wiscdb::Page::insertRecord ( const char *  record_data)

Inserts a new record into the page.

Parameters
record_dataBytes that compose the record.
Returns
ID of the newly inserted record.
Exceptions
InsufficientSpaceExceptionif not enough space on page for record
PageId wiscdb::Page::next_page_number ( ) const

Returns the number of the next used page this page in its file.

Returns
Page number of next used page in file.
PageId wiscdb::Page::page_number ( ) const

Returns this page's number in its file.

Returns
Page number.
void wiscdb::Page::print ( )

For debugging purposes; prints the contents of a page

void wiscdb::Page::updateRecord ( const RecordId record_id,
const char *  record_data 
)

Updates the record with the given ID, replacing its data with a new version. This is equivalent to deleting the old record and inserting a new one, with the exception that the record ID will not change.

Parameters
record_idID of record to update.
record_dataUpdated bytes that compose the record.
Exceptions
InvalidRecordExceptionif passed record_id is invalid
InsufficientSpaceExceptionif the the new data for the recorde cannot fit in the page

Member Data Documentation

const std::size_t wiscdb::Page::DATA_SIZE = SIZE - sizeof(PageHeader)
static

Size of page free space area in bytes.

Definition at line 127 of file page.h.

PageHeader wiscdb::Page::header

Header metadata.

Definition at line 144 of file page.h.

const PageId wiscdb::Page::INVALID_NUMBER = 0
static

Number of page indicating that it's invalid.

Definition at line 132 of file page.h.

const SlotId wiscdb::Page::INVALID_SLOT = 0
static

Number of slot indicating that it's invalid.

Definition at line 137 of file page.h.

const std::size_t wiscdb::Page::SIZE
static
Initial value:
=
sizeof(PageHeader) + 10*sizeof(PageSlot) + 10*strlen("Hello!") + 5

Page size in bytes. If this is changed, database files created with a different page size value will be unreadable by the resulting binaries.

Definition at line 121 of file page.h.


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