com.caucho.db.index
Class BTree

java.lang.Object
  extended by com.caucho.db.index.BTree

public final class BTree
extends java.lang.Object

Structure of the table:

 b4 - flags
 b4 - length
 b8 - parent
 b8 - next
 tuples*
 
Structure of a tuple:
 b8  - ptr to the actual data
 key - the tuple's key
 
For a non-leaf node, the key is the last matching entry in the subtree.


Field Summary
static long FAIL
           
 
Constructor Summary
BTree(BlockStore store, long rootBlockId, int keySize, KeyCompare keyCompare)
          Creates a new BTree with the given backing.
 
Method Summary
 void close()
           
 void create()
          Creates and initializes the btree.
static BTree createStringTest(Path path, int keySize)
           
static BTree createTest(Path path, int keySize)
           
 java.util.ArrayList<java.lang.String> getBlockKeys(long blockIndex)
          Testing: returns the keys for a block
 long getBlockNext(long blockIndex)
          Testing: returns the keys for a block
 long getIndexRoot()
          Returns the index root.
 void insert(byte[] keyBuffer, int keyOffset, int keyLength, long value, boolean isOverride)
          Inserts the new value for the given key.
 long lookup(byte[] keyBuffer, int keyOffset, int keyLength)
           
 void remove(byte[] keyBuffer, int keyOffset, int keyLength)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FAIL

public static final long FAIL
See Also:
Constant Field Values
Constructor Detail

BTree

public BTree(BlockStore store,
             long rootBlockId,
             int keySize,
             KeyCompare keyCompare)
      throws java.io.IOException
Creates a new BTree with the given backing.

Parameters:
store - the underlying store containing the btree.
Throws:
java.io.IOException
Method Detail

getIndexRoot

public long getIndexRoot()
Returns the index root.


create

public void create()
            throws java.io.IOException
Creates and initializes the btree.

Throws:
java.io.IOException

lookup

public long lookup(byte[] keyBuffer,
                   int keyOffset,
                   int keyLength)
            throws java.io.IOException,
                   java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

insert

public void insert(byte[] keyBuffer,
                   int keyOffset,
                   int keyLength,
                   long value,
                   boolean isOverride)
            throws java.sql.SQLException
Inserts the new value for the given key.

Throws:
java.sql.SQLException

remove

public void remove(byte[] keyBuffer,
                   int keyOffset,
                   int keyLength)
            throws java.sql.SQLException
Throws:
java.sql.SQLException

getBlockKeys

public java.util.ArrayList<java.lang.String> getBlockKeys(long blockIndex)
                                                   throws java.io.IOException
Testing: returns the keys for a block

Throws:
java.io.IOException

getBlockNext

public long getBlockNext(long blockIndex)
                  throws java.io.IOException
Testing: returns the keys for a block

Throws:
java.io.IOException

createTest

public static BTree createTest(Path path,
                               int keySize)
                        throws java.io.IOException,
                               java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

createStringTest

public static BTree createStringTest(Path path,
                                     int keySize)
                              throws java.io.IOException,
                                     java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

close

public void close()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object