simpledb.index.btree
Class BTreePage

java.lang.Object
  extended by simpledb.index.btree.BTreePage

public class BTreePage
extends Object

B-tree directory and leaf pages have many commonalities: in particular, their records are stored in sorted order, and pages split when full. A BTreePage object contains this common functionality.

Author:
Edward Sciore

Constructor Summary
BTreePage(Block currentblk, TableInfo ti, Transaction tx)
          Opens a page for the specified B-tree block.
 
Method Summary
 Block appendNew(int flag)
          Appends a new block to the end of the specified B-tree file, having the specified flag value.
 void close()
          Closes the page by unpinning its buffer.
 void delete(int slot)
          Deletes the index record at the specified slot.
 int findSlotBefore(Constant searchkey)
          Calculates the position where the first record having the specified search key should be, then returns the position before it.
 int getChildNum(int slot)
          Returns the block number stored in the index record at the specified slot.
 RID getDataRid(int slot)
          Returns the dataRID value stored in the specified leaf index record.
 Constant getDataVal(int slot)
          Returns the dataval of the record at the specified slot.
 int getFlag()
          Returns the value of the page's flag field
 int getNumRecs()
          Returns the number of index records in this page.
 void insertDir(int slot, Constant val, int blknum)
          Inserts a directory entry at the specified slot.
 void insertLeaf(int slot, Constant val, RID rid)
          Inserts a leaf index record at the specified slot.
 boolean isFull()
          Returns true if the block is full.
 void setFlag(int val)
          Sets the page's flag field to the specified value
 Block split(int splitpos, int flag)
          Splits the page at the specified position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BTreePage

public BTreePage(Block currentblk,
                 TableInfo ti,
                 Transaction tx)
Opens a page for the specified B-tree block.

Parameters:
currentblk - a reference to the B-tree block
ti - the metadata for the particular B-tree file
tx - the calling transaction
Method Detail

findSlotBefore

public int findSlotBefore(Constant searchkey)
Calculates the position where the first record having the specified search key should be, then returns the position before it.

Parameters:
searchkey - the search key
Returns:
the position before where the search key goes

close

public void close()
Closes the page by unpinning its buffer.


isFull

public boolean isFull()
Returns true if the block is full.

Returns:
true if the block is full

split

public Block split(int splitpos,
                   int flag)
Splits the page at the specified position. A new page is created, and the records of the page starting at the split position are transferred to the new page.

Parameters:
splitpos - the split position
flag - the initial value of the flag field
Returns:
the reference to the new block

getDataVal

public Constant getDataVal(int slot)
Returns the dataval of the record at the specified slot.

Parameters:
slot - the integer slot of an index record
Returns:
the dataval of the record at that slot

getFlag

public int getFlag()
Returns the value of the page's flag field

Returns:
the value of the page's flag field

setFlag

public void setFlag(int val)
Sets the page's flag field to the specified value

Parameters:
val - the new value of the page flag

appendNew

public Block appendNew(int flag)
Appends a new block to the end of the specified B-tree file, having the specified flag value.

Parameters:
flag - the initial value of the flag
Returns:
a reference to the newly-created block

getChildNum

public int getChildNum(int slot)
Returns the block number stored in the index record at the specified slot.

Parameters:
slot - the slot of an index record
Returns:
the block number stored in that record

insertDir

public void insertDir(int slot,
                      Constant val,
                      int blknum)
Inserts a directory entry at the specified slot.

Parameters:
slot - the slot of an index record
val - the dataval to be stored
blknum - the block number to be stored

getDataRid

public RID getDataRid(int slot)
Returns the dataRID value stored in the specified leaf index record.

Parameters:
slot - the slot of the desired index record
Returns:
the dataRID value store at that slot

insertLeaf

public void insertLeaf(int slot,
                       Constant val,
                       RID rid)
Inserts a leaf index record at the specified slot.

Parameters:
slot - the slot of the desired index record
val - the new dataval
rid - the new dataRID

delete

public void delete(int slot)
Deletes the index record at the specified slot.

Parameters:
slot - the slot of the deleted index record

getNumRecs

public int getNumRecs()
Returns the number of index records in this page.

Returns:
the number of index records in this page


Copyright © 2011. All Rights Reserved.