public class HashIndexFactory<Key,Value> extends 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.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUCKET_CAPACITY |
static int |
DEFAULT_LOAD_FACTOR |
static int |
DEFAULT_MAXIMUM_BUCKET_CAPACITY |
static int |
DEFAULT_MINIMUM_BUCKET_CAPACITY |
static String |
PROPERTY_PREFIX |
Constructor and Description |
---|
HashIndexFactory() |
Modifier and Type | Method and Description |
---|---|
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.
|
Index<Key,Value> |
openOrCreate(Paged paged) |
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.
|
public static final String PROPERTY_PREFIX
public static final int DEFAULT_BUCKET_CAPACITY
public static final int DEFAULT_MAXIMUM_BUCKET_CAPACITY
public static final int DEFAULT_MINIMUM_BUCKET_CAPACITY
public static final int DEFAULT_LOAD_FACTOR
public Index<Key,Value> open(Paged paged, int indexNumber)
open
in interface IndexFactory<Key,Value>
public Index<Key,Value> open(Paged paged)
open
in interface IndexFactory<Key,Value>
public Index<Key,Value> create(Paged paged)
create
in interface IndexFactory<Key,Value>
public Index<Key,Value> openOrCreate(Paged paged)
openOrCreate
in interface IndexFactory<Key,Value>
public org.fusesource.hawtbuf.codec.Codec<Key> getKeyCodec()
ObjectCodec
if not explicitly set.public void setKeyCodec(org.fusesource.hawtbuf.codec.Codec<Key> codec)
codec
- the marshaller used for keys.public org.fusesource.hawtbuf.codec.Codec<Value> getValueCodec()
ObjectCodec
if not explicitly set.public void setValueCodec(org.fusesource.hawtbuf.codec.Codec<Value> codec)
codec
- the marshaller used for valuespublic int getMaximumBucketCapacity()
public void setMaximumBucketCapacity(int value)
value
- the new capacitypublic int getMinimumBucketCapacity()
public void setMinimumBucketCapacity(int value)
value
- the new capacitypublic int getLoadFactor()
public void setLoadFactor(int loadFactor)
loadFactor
- public int getBucketCapacity()
public void setBucketCapacity(int binCapacity)
binCapacity
- public void setFixedCapacity(int value)
value
- public boolean isDeferredEncoding()
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.
enable
- should deferred encoding be enabled.Copyright © 2009–2016 FuseSource, Corp.. All rights reserved.