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

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

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

Uses to create Hash based storage of key/values. The hash index consists of contiguous array of pages allocated on the page file. Each page is considered a bucket. keys get hashed to a bucket indexes and the key and value are stored in the bucket. Each bucket is actually a BTree root and can therefore store multiple keys and values and overflow to additional pages if needed.

Once the percentage of hash buckets used passes the configured load factor, the hash index will "resize" to use a larger number of buckets to keep the number items per bucket low which increases access time of the items as there are fewer page access required.

Unlike BTree indexes, Hash indexes are not kept in key sorted order.

Author:
Hiram Chirino

Field Summary
static int DEFAULT_BUCKET_CAPACITY
           
static int DEFAULT_LOAD_FACTOR
           
static int DEFAULT_MAXIMUM_BUCKET_CAPACITY
           
static int DEFAULT_MINIMUM_BUCKET_CAPACITY
           
static java.lang.String PROPERTY_PREFIX
           
 
Constructor Summary
HashIndexFactory()
           
 
Method Summary
 Index<Key,Value> create(Paged paged)
          Creates a new hash index on the Paged object.
 int getBucketCapacity()
           
 org.fusesource.hawtbuf.codec.Codec<Key> getKeyCodec()
          Defaults to an ObjectCodec if not explicitly set.
 int getLoadFactor()
           
 int getMaximumBucketCapacity()
           
 int getMinimumBucketCapacity()
           
 org.fusesource.hawtbuf.codec.Codec<Value> getValueCodec()
          Defaults to an ObjectCodec if not explicitly set.
 boolean isDeferredEncoding()
           
 Index<Key,Value> open(Paged paged)
          Loads an existing hash index from the paged object.
 Index<Key,Value> open(Paged paged, int indexNumber)
          Loads an existing hash index from the paged object.
 void setBucketCapacity(int binCapacity)
          sets the initial bucket capacity.
 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 setFixedCapacity(int value)
          Convenience method which sets the maximum, minimum and initial bucket capacity to be the specified value.
 void setKeyCodec(org.fusesource.hawtbuf.codec.Codec<Key> codec)
          Allows you to configure custom marshalling logic to encode the index keys.
 void setLoadFactor(int loadFactor)
          Sets the index load factor.
 void setMaximumBucketCapacity(int value)
          Sets the maximum bucket capacity.
 void setMinimumBucketCapacity(int value)
          Sets the minimum bucket capacity.
 void setValueCodec(org.fusesource.hawtbuf.codec.Codec<Value> codec)
          Allows you to configure custom marshalling logic to encode the index values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_PREFIX

public static final java.lang.String PROPERTY_PREFIX

DEFAULT_BUCKET_CAPACITY

public static final int DEFAULT_BUCKET_CAPACITY

DEFAULT_MAXIMUM_BUCKET_CAPACITY

public static final int DEFAULT_MAXIMUM_BUCKET_CAPACITY

DEFAULT_MINIMUM_BUCKET_CAPACITY

public static final int DEFAULT_MINIMUM_BUCKET_CAPACITY

DEFAULT_LOAD_FACTOR

public static final int DEFAULT_LOAD_FACTOR
Constructor Detail

HashIndexFactory

public HashIndexFactory()
Method Detail

open

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

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

open

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

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

create

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

Specified by:
create 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

getMaximumBucketCapacity

public int getMaximumBucketCapacity()
Returns:
the maximum bucket capacity

setMaximumBucketCapacity

public void setMaximumBucketCapacity(int value)
Sets the maximum bucket capacity.

Parameters:
value - the new capacity

getMinimumBucketCapacity

public int getMinimumBucketCapacity()
Returns:
the minimum bucket capacity

setMinimumBucketCapacity

public void setMinimumBucketCapacity(int value)
Sets the minimum bucket capacity.

Parameters:
value - the new capacity

getLoadFactor

public int getLoadFactor()
Returns:
the index load factor

setLoadFactor

public void setLoadFactor(int loadFactor)
Sets the index load factor. When this load factor percentage of used buckets is execeeded, the index will resize to increase the bucket capacity.

Parameters:
loadFactor -

getBucketCapacity

public int getBucketCapacity()
Returns:
the initial bucket capacity

setBucketCapacity

public void setBucketCapacity(int binCapacity)
sets the initial bucket capacity.

Parameters:
binCapacity -

setFixedCapacity

public void setFixedCapacity(int value)
Convenience method which sets the maximum, minimum and initial bucket capacity to be the specified value.

Parameters:
value -

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.


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