heap
Class HFPage

java.lang.Object
  extended by global.Page
      extended by heap.HFPage
All Implemented Interfaces:
GlobalConst

public class HFPage
extends Page

Heap file data pages are implemented as slotted pages, with the slots at the front and the records in the back, both growing into the free space in the middle of the page. This design assumes that records are kept compacted when deletions are performed. Each slot contains the length and offset of its corresponding record.


Field Summary
static int HEADER_SIZE
          Total size of the header fields.
static int SLOT_SIZE
          Size of a record slot.
 
Fields inherited from interface global.GlobalConst
EMPTY_SLOT, FIRST_PAGEID, INVALID_PAGEID, MAX_COLSIZE, MAX_TUPSIZE, NAME_MAXLEN, PAGE_SIZE, PIN_DISKIO, PIN_MEMCPY, UNPIN_CLEAN, UNPIN_DIRTY
 
Constructor Summary
HFPage()
          Default constructor; creates a heap file page with default values.
HFPage(Page page)
          Constructor that wraps an existing heap file page.
 
Method Summary
 void deleteRecord(RID rid)
          Deletes a record from the page, compacting the records space.
 RID firstRecord()
          Gets the RID of the first record on the page, or null if none.
 PageId getCurPage()
          Gets the current page's id.
 short getFreeSpace()
          Gets the amount of free space (in bytes).
 PageId getNextPage()
          Gets the next page's id.
 PageId getPrevPage()
          Gets the previous page's id.
 short getSlotCount()
          Gets the number of slots on the page.
 short getSlotLength(int slotno)
          Gets the length of the record referenced by the given slot.
 short getSlotOffset(int slotno)
          Gets the offset of the record referenced by the given slot.
 short getType()
          Gets the arbitrary type of the page.
 boolean hasNext(RID curRid)
          Returns true if the iteration has more elements.
 RID insertRecord(byte[] record)
          Inserts a new record into the page.
 RID nextRecord(RID curRid)
          Gets the next RID after the given one, or null if no more.
 void print()
          Prints the contents of a heap file page.
 byte[] selectRecord(RID rid)
          Selects a record from the page.
 void setCurPage(PageId pageno)
          Sets the current page's id.
 void setNextPage(PageId pageno)
          Sets the next page's id.
 void setPrevPage(PageId pageno)
          Sets the previous page's id.
 void setType(short type)
          Sets the arbitrary type of the page.
 void updateRecord(RID rid, byte[] record)
          Updates a record on the page.
 
Methods inherited from class global.Page
copyPage, getCharValue, getData, getFloatValue, getIntValue, getShortValue, getStringValue, setCharValue, setData, setFloatValue, setIntValue, setPage, setShortValue, setStringValue
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEADER_SIZE

public static final int HEADER_SIZE
Total size of the header fields.

See Also:
Constant Field Values

SLOT_SIZE

public static final int SLOT_SIZE
Size of a record slot.

See Also:
Constant Field Values
Constructor Detail

HFPage

public HFPage()
Default constructor; creates a heap file page with default values.


HFPage

public HFPage(Page page)
Constructor that wraps an existing heap file page.

Method Detail

getSlotCount

public short getSlotCount()
Gets the number of slots on the page.


getFreeSpace

public short getFreeSpace()
Gets the amount of free space (in bytes).


getType

public short getType()
Gets the arbitrary type of the page.


setType

public void setType(short type)
Sets the arbitrary type of the page.


getPrevPage

public PageId getPrevPage()
Gets the previous page's id.


setPrevPage

public void setPrevPage(PageId pageno)
Sets the previous page's id.


getNextPage

public PageId getNextPage()
Gets the next page's id.


setNextPage

public void setNextPage(PageId pageno)
Sets the next page's id.


getCurPage

public PageId getCurPage()
Gets the current page's id.


setCurPage

public void setCurPage(PageId pageno)
Sets the current page's id.


getSlotLength

public short getSlotLength(int slotno)
Gets the length of the record referenced by the given slot.


getSlotOffset

public short getSlotOffset(int slotno)
Gets the offset of the record referenced by the given slot.


insertRecord

public RID insertRecord(byte[] record)
Inserts a new record into the page.

Returns:
RID of new record, or null if insufficient space

selectRecord

public byte[] selectRecord(RID rid)
Selects a record from the page.

Throws:
java.lang.IllegalArgumentException - if the rid is invalid

updateRecord

public void updateRecord(RID rid,
                         byte[] record)
Updates a record on the page.

Throws:
java.lang.IllegalArgumentException - if the rid or record size is invalid

deleteRecord

public void deleteRecord(RID rid)
Deletes a record from the page, compacting the records space. The slot directory cannot be compacted because that would alter existing RIDs.

Throws:
java.lang.IllegalArgumentException - if the rid is invalid

firstRecord

public RID firstRecord()
Gets the RID of the first record on the page, or null if none.


hasNext

public boolean hasNext(RID curRid)
Returns true if the iteration has more elements.

Throws:
java.lang.IllegalArgumentException - if the rid is invalid

nextRecord

public RID nextRecord(RID curRid)
Gets the next RID after the given one, or null if no more.

Throws:
java.lang.IllegalArgumentException - if the rid is invalid

print

public void print()
Prints the contents of a heap file page.