org.fusesource.hawtdb.api
Class BTreeIndexFactory<Key,Value>

java.lang.Object
  extended by org.fusesource.hawtdb.api.BTreeIndexFactory<Key,Value>
All Implemented Interfaces:
IndexFactory<Key,Value>

public class BTreeIndexFactory<Key,Value>
extends java.lang.Object
implements IndexFactory<Key,Value>

This object is used to create variable magnitude b+tree indexes. A b+tree can be used for set or map-based indexing. Leaf nodes are linked together for faster iteration of the values.
The variable magnitude attribute means that the b+tree attempts to store as many values and pointers on one page as is possible.
It will act as a simple-prefix b+tree if a prefixer is configured.
In a simple-prefix b+tree, instead of promoting actual keys to branch pages, when leaves are split, a shortest-possible separator is generated at the pivot. That separator is what is promoted to the parent branch (and continuing up the list). As a result, actual keys and pointers can only be found at the leaf level. This also affords the index the ability to ignore costly merging and redistribution of pages when deletions occur. Deletions only affect leaf pages in this implementation, and so it is entirely possible for a leaf page to be completely empty after all of its keys have been removed.

Author:
Hiram Chirino

Constructor Summary
BTreeIndexFactory()
           
 
Method Summary
 SortedIndex<Key,Value> create(Paged paged)
          Creates a new BTree index on the Paged object.
 java.util.Comparator getComparator()
          Gets the custom configured Comparator used to sort the keys in the index.
 org.fusesource.hawtbuf.codec.Codec<Key> getKeyCodec()
          Defaults to an ObjectCodec if not explicitly set.
 Prefixer<Key> getPrefixer()
           
 org.fusesource.hawtbuf.codec.Codec<Value> getValueCodec()
          Defaults to an ObjectCodec if not explicitly set.
 boolean isDeferredEncoding()
           
 SortedIndex<Key,Value> open(Paged paged)
          Loads an existing BTree index from the paged object.
 SortedIndex<Key,Value> open(Paged paged, int indexNumber)
          Loads an existing BTree index from the paged object.
 void setComparator(java.util.Comparator comparator)
          Configures a custom Comparator used to sort the keys in the index.
 void setDeferredEncoding(boolean enable)
           When deferred encoding is enabled, the index avoids encoding keys and values for as long as possible so take advantage of collapsing multiple updates of the same key/value into a single update operation and single encoding operation.
 void setKeyCodec(org.fusesource.hawtbuf.codec.Codec<Key> codec)
          Allows you to configure custom marshalling logic to encode the index keys.
 void setPrefixer(Prefixer<Key> prefixer)
           
 void setValueCodec(org.fusesource.hawtbuf.codec.Codec<Value> codec)
          Allows you to configure custom marshalling logic to encode the index values.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BTreeIndexFactory

public BTreeIndexFactory()
Method Detail

create

public SortedIndex<Key,Value> create(Paged paged)
Creates a new BTree index on the Paged object.

Specified by:
create in interface IndexFactory<Key,Value>
Returns:

toString

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

open

public SortedIndex<Key,Value> open(Paged paged,
                                   int indexNumber)
Loads an existing BTree index from the paged object.

Specified by:
open in interface IndexFactory<Key,Value>
Returns:

open

public SortedIndex<Key,Value> open(Paged paged)
Loads an existing BTree index from the paged object.

Specified by:
open in interface IndexFactory<Key,Value>
Returns:

getKeyCodec

public org.fusesource.hawtbuf.codec.Codec<Key> getKeyCodec()
Defaults to an ObjectCodec if not explicitly set.

Returns:
the marshaller used for keys.

setKeyCodec

public void setKeyCodec(org.fusesource.hawtbuf.codec.Codec<Key> codec)
Allows you to configure custom marshalling logic to encode the index keys.

Parameters:
codec - the marshaller used for keys.

getValueCodec

public org.fusesource.hawtbuf.codec.Codec<Value> getValueCodec()
Defaults to an ObjectCodec if not explicitly set.

Returns:
the marshaller used for values.

setValueCodec

public void setValueCodec(org.fusesource.hawtbuf.codec.Codec<Value> codec)
Allows you to configure custom marshalling logic to encode the index values.

Parameters:
codec - the marshaller used for values

isDeferredEncoding

public boolean isDeferredEncoding()
Returns:
true if deferred encoding enabled

setDeferredEncoding

public void setDeferredEncoding(boolean enable)

When deferred encoding is enabled, the index avoids encoding keys and values for as long as possible so take advantage of collapsing multiple updates of the same key/value into a single update operation and single encoding operation.

Using this feature requires the keys and values to be immutable objects since unexpected errors would occur if they are changed after they have been handed to to the index for storage.

Parameters:
enable - should deferred encoding be enabled.

getPrefixer

public Prefixer<Key> getPrefixer()

setPrefixer

public void setPrefixer(Prefixer<Key> prefixer)

getComparator

public java.util.Comparator getComparator()
Gets the custom configured Comparator used to sort the keys in the index. Defaults to null.

Returns:

setComparator

public void setComparator(java.util.Comparator comparator)
Configures a custom Comparator used to sort the keys in the index. If not set, the keys must implement the Comparable interface.

Parameters:
comparator -


Copyright © 2009-2011 FuseSource, Corp.. All Rights Reserved.