neustore.heapfile
Class HeapFilePage

java.lang.Object
  extended by neustore.base.DBPage
      extended by neustore.heapfile.HeapFilePage

public class HeapFilePage
extends DBPage

A memory-version page of a heap file.

Author:
Donghui Zhang <donghui@ccs.neu.edu>
See Also:
HeapFile

Field Summary
protected  int availableBytes
          available space in the page
protected  int next
          the next page in the linked list.
protected  int prev
          the previous page in the linked list.
protected  java.util.Vector<neustore.heapfile.HeapFilePage.HeapFileRecord> records
          the list of records
protected  int RESERVED
          size for the reserved space.
 
Fields inherited from class neustore.base.DBPage
nodeType, pageSize
 
Constructor Summary
HeapFilePage(int _pageSize, Key _sampleKey, Data _sampleData)
          Constructor fo HeapFilePage.
 
Method Summary
 boolean delete(Key key)
          Deletes a record from the page.
 void insert(Key key, Data data)
          Inserts a new record into this page.
 boolean isFull()
          Whether the page is full.
 int numRecs()
          Returns the number of records in the page.
protected  void read(byte[] page)
          Reads the object from a byte array.
 Data search(Key key)
          Searches for a record in the page.
protected  void write(byte[] page)
          Writes the object to a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESERVED

protected final int RESERVED
size for the reserved space. The first 20 bytes of the disk-version of the HeapFilePage are reserved for: nodeType=1, prev, next, availableBytes, numRecs.

See Also:
Constant Field Values

records

protected java.util.Vector<neustore.heapfile.HeapFilePage.HeapFileRecord> records
the list of records


next

protected int next
the next page in the linked list. -1 if not exist. Whether this page is in the full-page list or the nonfull-page list depends on whether this page is full.


prev

protected int prev
the previous page in the linked list. -1 if not exist. Whether this page is in the full-page list or the nonfull-page list depends on whether this page is full.


availableBytes

protected int availableBytes
available space in the page

Constructor Detail

HeapFilePage

public HeapFilePage(int _pageSize,
                    Key _sampleKey,
                    Data _sampleData)
Constructor fo HeapFilePage. Similar to the constructor of HeapFile, here a sample key and a sample data are taken to enable the generic feature of the index.

Parameters:
_pageSize - page size
_sampleKey - a sample key
_sampleData - a sample data
Method Detail

numRecs

public int numRecs()
Returns the number of records in the page.

Returns:
number of records

isFull

public boolean isFull()
Whether the page is full.

Returns:
whether full

insert

public void insert(Key key,
                   Data data)
Inserts a new record into this page. The caller needs to make sure that the page has enough space.

Parameters:
key - the key part of the new record
data - the data part of the new record

search

public Data search(Key key)
Searches for a record in the page.

Parameters:
key - the key to search for
Returns:
the data if found; null otherwise.

delete

public boolean delete(Key key)
Deletes a record from the page. It is the caller's responsibility to free an empty page.

Parameters:
key - the key to delete
Returns:
whether deleted

read

protected void read(byte[] page)
             throws java.io.IOException
Description copied from class: DBPage
Reads the object from a byte array.

Specified by:
read in class DBPage
Throws:
java.io.IOException

write

protected void write(byte[] page)
              throws java.io.IOException
Description copied from class: DBPage
Writes the object to a byte array.

Specified by:
write in class DBPage
Throws:
java.io.IOException