All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class btree.BT

java.lang.Object
   |
   +----btree.BT

public class BT
extends Object
implements GlobalConst
This file contains, among some debug utilities, the interface to our key and data abstraction. The BTLeafPage and BTIndexPage code know very little about the various key types. Essentially we provide a way for those classes to package and unpackage pairs in a space-efficient manner. That is, the packaged result contains the key followed immediately by the data value; No padding bytes are used (not even for alignment). Furthermore, the BT<*>Page classes need not know anything about the possible AttrType values, since all their processing of pairs is done by the functions declared here. In addition to packaging/unpacking of pairs, we provide a keyCompare function for the (obvious) purpose of comparing keys of arbitrary type (as long as they are defined here). For debug utilities, you could implement methods to print any page or the whole B+ tree structure or all leaf pages.


Constructor Index

 o BT()

Method Index

 o getBytesFromEntry(KeyDataEntry)
It convert a keyDataEntry to byte[].
 o getDataLength(short)
It gets the length of the data
 o getEntryFromBytes(byte[], int, int, int, short)
It gets an keyDataEntry from bytes array and position
 o getKeyDataLength(KeyClass, short)
It gets the length of the (key,data) pair in leaf or index page.
 o getKeyLength(KeyClass)
It gets the length of the key
 o keyCompare(KeyClass, KeyClass)
It compares two keys.

Constructors

 o BT
 public BT()

Methods

 o keyCompare
 public static final int keyCompare(KeyClass key1,
                                    KeyClass key2) throws KeyNotMatchException
It compares two keys.

Parameters:
key1 - the first key to compare. Input parameter.
key2 - the second key to compare. Input parameter.
Returns:
return negative if key1 less than key2; positive if key1 bigger than key2; 0 if key1=key2.
Throws: KeyNotMatchException
key is not IntegerKey or StringKey class
 o getKeyLength
 public static final int getKeyLength(KeyClass key) throws KeyNotMatchException, IOException
It gets the length of the key

Parameters:
key - specify the key whose length will be calculated. Input parameter.
Returns:
return the length of the key
Throws: KeyNotMatchException
key is neither StringKey nor IntegerKey
Throws: IOException
error from the lower layer
 o getDataLength
 public static final int getDataLength(short pageType) throws NodeNotMatchException
It gets the length of the data

Parameters:
pageType - NodeType.LEAF or NodeType.INDEX. Input parameter.
Returns:
return 8 if it is of NodeType.LEA; return 4 if it is of NodeType.INDEX.
Throws: NodeNotMatchException
pageType is neither NodeType.LEAF nor NodeType.INDEX.
 o getKeyDataLength
 public static final int getKeyDataLength(KeyClass key,
                                          short pageType) throws KeyNotMatchException, NodeNotMatchException, IOException
It gets the length of the (key,data) pair in leaf or index page.

Parameters:
key - an object of KeyClass. Input parameter.
pageType - NodeType.LEAF or NodeType.INDEX. Input parameter.
Returns:
return the lenrth of the (key,data) pair.
Throws: KeyNotMatchException
key is neither StringKey nor IntegerKey
Throws: NodeNotMatchException
pageType is neither NodeType.LEAF nor NodeType.INDEX.
Throws: IOException
error from the lower layer
 o getEntryFromBytes
 public static final KeyDataEntry getEntryFromBytes(byte from[],
                                                    int offset,
                                                    int length,
                                                    int keyType,
                                                    short nodeType) throws KeyNotMatchException, NodeNotMatchException, ConvertException
It gets an keyDataEntry from bytes array and position

Parameters:
from - It's a bytes array where KeyDataEntry will come from. Input parameter.
offset - the offset in the bytes. Input parameter.
keyType - It specifies the type of key. It can be AttrType.attrString or AttrType.attrInteger. Input parameter.
nodeType - It specifes NodeType.LEAF or NodeType.INDEX. Input parameter.
length - The length of (key, data) in byte array "from". Input parameter.
Returns:
return a KeyDataEntry object
Throws: KeyNotMatchException
key is neither StringKey nor IntegerKey
Throws: NodeNotMatchException
nodeType is neither NodeType.LEAF nor NodeType.INDEX.
Throws: ConvertException
error from the lower layer
 o getBytesFromEntry
 public static final byte[] getBytesFromEntry(KeyDataEntry entry) throws KeyNotMatchException, NodeNotMatchException, ConvertException
It convert a keyDataEntry to byte[].

Parameters:
entry - specify the data entry. Input parameter.
Returns:
return a byte array with size equal to the size of (key,data).
Throws: KeyNotMatchException
entry.key is neither StringKey nor IntegerKey
Throws: NodeNotMatchException
entry.data is neither LeafData nor IndexData
Throws: ConvertException
error from converting from entry to bytes

All Packages  Class Hierarchy  This Package  Previous  Next  Index