index
Class SortedPage

java.lang.Object
  extended by global.Page
      extended by index.SortedPage
All Implemented Interfaces:
GlobalConst
Direct Known Subclasses:
HashBucket

 class SortedPage
extends Page

A base class for index pages that automatically stores records in ascending order by key value. SortedPage supports variable-length records by using a slot directory, with the slots at the front and the records in the back, both growing and shrinking into and from the free space in the middle of the page.


Field Summary
 
Fields inherited from class global.Page
data
 
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
SortedPage()
          Default constructor; creates a sorted page with default values.
SortedPage(Page page)
          Constructor that wraps an existing sorted page.
 
Method Summary
 boolean deleteEntry(DataEntry entry)
          Deletes a record from the page, compacting the free space (including the slot directory).
 int findEntry(SearchKey key)
          Searches for the first entry that matches the given search key.
 DataEntry getEntryAt(int slotno)
          Gets the entry at the given slot number.
 short getEntryCount()
          Gets the number of entries on the page.
 SearchKey getFirstKey()
          Gets the key of the first entry on the page.
 short getFreeSpace()
          Gets the amount of free space (in bytes).
 SearchKey getKeyAt(int slotno)
          Gets the key at the given slot number.
 PageId getNextPage()
          Gets the next page's id.
 boolean insertEntry(DataEntry entry)
          Inserts a new record into the page in sorted order.
 int nextEntry(SearchKey key, int slotno)
          Searches for the next entry that matches the given search key, and stored after the given slot.
 void setNextPage(PageId pageno)
          Sets the next page's id.
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortedPage

public SortedPage()
Default constructor; creates a sorted page with default values.


SortedPage

public SortedPage(Page page)
Constructor that wraps an existing sorted page.

Method Detail

getEntryCount

public short getEntryCount()
Gets the number of entries on the page.


getFreeSpace

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


getNextPage

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


setNextPage

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


getEntryAt

public DataEntry getEntryAt(int slotno)
Gets the entry at the given slot number.

Throws:
java.lang.IllegalArgumentException - if the slot number is invalid

getKeyAt

public SearchKey getKeyAt(int slotno)
Gets the key at the given slot number.

Throws:
java.lang.IllegalArgumentException - if the slot number is invalid

getFirstKey

public SearchKey getFirstKey()
Gets the key of the first entry on the page.

Throws:
java.lang.IllegalStateException - if the page is empty

insertEntry

public boolean insertEntry(DataEntry entry)
Inserts a new record into the page in sorted order.

Returns:
true if inserting made this page dirty, false otherwise
Throws:
java.lang.IllegalStateException - if insufficient space

deleteEntry

public boolean deleteEntry(DataEntry entry)
Deletes a record from the page, compacting the free space (including the slot directory).

Returns:
true if deleting made this page dirty, false otherwise
Throws:
java.lang.IllegalArgumentException - if the entry doesn't exist

findEntry

public int findEntry(SearchKey key)
Searches for the first entry that matches the given search key.

Returns:
the slot number of the entry, or -1 if not found

nextEntry

public int nextEntry(SearchKey key,
                     int slotno)
Searches for the next entry that matches the given search key, and stored after the given slot.

Returns:
the slot number of the entry, or -1 if not found