CLASS SortedPage

#include <sortedpage.h>

SortedPage is a special kind of HeapPage that arrange the records in page in sorted order according to a specified key. Records and slots directory on the page are compact. Therefore it is unsafe to retrieve a record on a SortedPage based on RecordID after a deletion.

Class Heirarchy

Page --- HeapPage --- SortedPage

Methods

Status InsertRecord(char * recPtr, int recLen, RecordID& rid)

Insert a record, pointed to by pointer recPtr, of length recLen, into this page. Output the record id of the inserted record as rid.

Status DeleteRecord(const RecordID& rid)

Delete a record with record id rid from the page,

void SetType(short t)

Set the type of the page to t.

short GetType()

Return the type of the page.

int GetNumOfRecords()

Return the number of records on this page.

Inherited Methods Relevent to B+ Tree Assignment

void Init(PageID pageNo)

Initialize the data members in this page. Set the page id of this page to pageNo.

PageID PageNo()

Return the page id of this page.

int AvailableSpace()

Return the size of empty space on this page (in bytes).

Inherited Members Relevant to B+ Tree Assignment

short type

can be set to INDEX_NODE or LEAF_NODE to indicate the type of this object. INDEX_NODE indicates that this object is a BTIndexPage object, LEAF_NODE indicates a BTLeafPage object.

Slots slots[1]

Each Slots is contains two attributes : offset and length. Even though this array is defined as size 1, we can access slots[i] as long as it is within the boundry of the page.

char data[HEAPPAGE_DATA_SIZE]

This array represents the area where data (including slots directories) can be stored on this page. HEAPPAGE_DATA_SIZE is the size of this area.

Examples

To check if a page is half filled :

    AvailableSpace() > HEAPPAGE_DATA_SIZE/2

To create a new page of type BTLeafNode:

    Status s;
    PageID pid;
    SortedPage *page;
    s = MINIBASE_BM->NewPage(pid, (Page *&)page);
    if (s != OK)
    {
        // error;
    }
    page->Init(pid);
    page->SetType(LEAF_NODE);

To get an entry at slot number i:

    data + slots[i].offset