test.naiveheapfile
Class NaiveHeapFile

java.lang.Object
  extended by neustore.base.DBIndex
      extended by test.naiveheapfile.NaiveHeapFile

public class NaiveHeapFile
extends DBIndex

A naive version of the heap file. It stores a list of integers. The only update is to append an integer at the end of the file. The only search is to tell whether an integer exists in the file or not. This file is not meant to be used. Rather, it shows an example of using the NEU Storage Package.

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

Field Summary
 
Fields inherited from class neustore.base.DBIndex
buffer, CREATE, file, firstEmpty, numPages, OPEN, OVERHEAD, pageSize
 
Constructor Summary
NaiveHeapFile(DBBuffer _buffer, java.lang.String filename, boolean isCreate)
           
 
Method Summary
protected  void initIndexHead()
          Initializes index head information.
 void insert(int key)
          Appends a new integer to the end of the file.
protected  NaiveHeapFilePage myReadPage(int pageID)
          Reads a page from buffer and parse it if not parsed already.
protected  void readIndexHead(byte[] head)
          Reads index head information from a byte array.
 boolean search(int key)
          Searches for an integer.
protected  void writeIndexHead(byte[] head)
          Writes index head information to a byte array.
 
Methods inherited from class neustore.base.DBIndex
allocate, close, freePage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NaiveHeapFile

public NaiveHeapFile(DBBuffer _buffer,
                     java.lang.String filename,
                     boolean isCreate)
              throws java.io.IOException
Throws:
java.io.IOException
Method Detail

initIndexHead

protected void initIndexHead()
Description copied from class: DBIndex
Initializes index head information. Called when creating a DBIndex.

Specified by:
initIndexHead in class DBIndex

myReadPage

protected NaiveHeapFilePage myReadPage(int pageID)
                                throws java.io.IOException
Reads a page from buffer and parse it if not parsed already.

Parameters:
pageID -
Returns:
the parsed page
Throws:
java.io.IOException

readIndexHead

protected void readIndexHead(byte[] head)
Description copied from class: DBIndex
Reads index head information from a byte array. Called when opening a DBIndex.

Specified by:
readIndexHead in class DBIndex
Parameters:
head - the byte array of length pageSize-OVERHEAD

writeIndexHead

protected void writeIndexHead(byte[] head)
Description copied from class: DBIndex
Writes index head information to a byte array. Called before closing a DBIndex.

Specified by:
writeIndexHead in class DBIndex
Parameters:
head - the byte array of length pageSize-OVERHEAD

insert

public void insert(int key)
            throws java.io.IOException
Appends a new integer to the end of the file.

Parameters:
key - the integer to be appended
Throws:
java.io.IOException

search

public boolean search(int key)
               throws java.io.IOException
Searches for an integer.

Parameters:
key - the integer to search for
Returns:
whether found
Throws:
java.io.IOException