krati.store
Class DynamicDataSet

java.lang.Object
  extended by krati.store.DynamicDataSet
All Implemented Interfaces:
DataSet<byte[]>

public class DynamicDataSet
extends Object
implements DataSet<byte[]>

DynamicDataSet is implemented using Linear Hashing. Its capacity grows as needed. The values are stored in the underlying DataArray using the following format:

 [count:int][value-length:int][value:bytes][value-length:int][value:bytes]...
            +-----------value 1------------+-----------value 2-----------+
 

Author:
jwu

Constructor Summary
DynamicDataSet(File homeDir, int initLevel, int entrySize, int maxEntries, int segmentFileSizeMB, SegmentFactory segmentFactory)
          Creates a dynamic DataSet with the settings below:
DynamicDataSet(File homeDir, int initLevel, int entrySize, int maxEntries, int segmentFileSizeMB, SegmentFactory segmentFactory, double segmentCompactFactor, double hashLoadThreshold, HashFunction<byte[]> hashFunction)
          Creates a dynamic DataSet.
DynamicDataSet(File homeDir, int initLevel, int entrySize, int maxEntries, int segmentFileSizeMB, SegmentFactory segmentFactory, double hashLoadThreshold, HashFunction<byte[]> hashFunction)
          Creates a dynamic DataSet.
DynamicDataSet(File homeDir, int initLevel, int segmentFileSizeMB, SegmentFactory segmentFactory)
          Creates a dynamic DataSet with the settings below:
DynamicDataSet(File homeDir, int initLevel, int segmentFileSizeMB, SegmentFactory segmentFactory, double hashLoadThreshold, HashFunction<byte[]> hashFunction)
          Creates a dynamic DataSet with the settings below:
DynamicDataSet(File homeDir, int initLevel, SegmentFactory segmentFactory)
          Creates a dynamic DataSet with the settings below:
DynamicDataSet(File homeDir, int initLevel, SegmentFactory segmentFactory, HashFunction<byte[]> hashFunction)
          Creates a dynamic DataSet with the settings below:
DynamicDataSet(File homeDir, SegmentFactory segmentFactory)
          Creates a dynamic DataSet with the settings below:
 
Method Summary
 boolean add(byte[] value)
           
protected  boolean addInternal(int index, byte[] value)
           
 void clear()
           
 int countCollisions(byte[] value)
           
protected  DynamicLongArray createAddressArray(int entrySize, int maxEntries, File homeDirectory)
           
 boolean delete(byte[] value)
           
protected  boolean deleteInternal(int index, byte[] value)
           
 int getCapacity()
           
 DataArray getDataArray()
           
protected  int getIndex(byte[] value)
           
protected  int getIndex(long hashCode)
           
 int getLevel()
           
 int getLevelCapacity()
           
 int getLoadCount()
           
 double getLoadFactor()
           
 double getLoadThreshold()
           
 int getSplit()
           
 String getStatus()
           
 int getUnitCapacity()
           
 boolean has(byte[] value)
           
protected  long hash(byte[] value)
           
 boolean hasWithoutCollisions(byte[] value)
           
protected  long nextScn()
           
 void persist()
           
 void rehash()
           
 void sync()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicDataSet

public DynamicDataSet(File homeDir,
                      SegmentFactory segmentFactory)
               throws Exception
Creates a dynamic DataSet with the settings below:
    Initial Level            : 0
    Entry Size               : 10000
    Max Entries              : 5
    Segment File Size        : 256MB
    Segment Compact Factor   : 0.5
    DataSet Hash Load Factor : 0.75
    DataSet Hash Function    : krati.util.FnvHashFunction
 

Parameters:
homeDir - the home directory of DataSet
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
Throws:
Exception - if this dynamic data set cannot be created.

DynamicDataSet

public DynamicDataSet(File homeDir,
                      int initLevel,
                      SegmentFactory segmentFactory)
               throws Exception
Creates a dynamic DataSet with the settings below:
    Entry Size               : 10000
    Max Entries              : 5
    Segment File Size        : 256MB
    Segment Compact Factor   : 0.5
    DataSet Hash Load Factor : 0.75
    DataSet Hash Function    : krati.util.FnvHashFunction
 

Parameters:
homeDir - the home directory of DataSet
initLevel - the initial level when DataSet is created
segmentFactory - the segment factory
Throws:
Exception - if this dynamic data set cannot be created.

DynamicDataSet

public DynamicDataSet(File homeDir,
                      int initLevel,
                      SegmentFactory segmentFactory,
                      HashFunction<byte[]> hashFunction)
               throws Exception
Creates a dynamic DataSet with the settings below:
    Entry Size               : 10000
    Max Entries              : 5
    Segment File Size        : 256MB
    Segment Compact Factor   : 0.5
    DataSet Hash Load Factor : 0.75
 

Parameters:
homeDir - the home directory of DataSet
initLevel - the initial level when DataSet is created
segmentFactory - the segment factory
hashFunction - the hash function for mapping values to indexes
Throws:
Exception - if this dynamic data set cannot be created.

DynamicDataSet

public DynamicDataSet(File homeDir,
                      int initLevel,
                      int segmentFileSizeMB,
                      SegmentFactory segmentFactory)
               throws Exception
Creates a dynamic DataSet with the settings below:
    Entry Size               : 10000
    Max Entries              : 5
    Segment Compact Factor   : 0.5
    DataSet Hash Load Factor : 0.75
    DataSet Hash Function    : krati.util.FnvHashFunction
 

Parameters:
homeDir - the home directory of DataSet
initLevel - the initial level when DataSet is created
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
Throws:
Exception - if this dynamic data set cannot be created.

DynamicDataSet

public DynamicDataSet(File homeDir,
                      int initLevel,
                      int segmentFileSizeMB,
                      SegmentFactory segmentFactory,
                      double hashLoadThreshold,
                      HashFunction<byte[]> hashFunction)
               throws Exception
Creates a dynamic DataSet with the settings below:
    Entry Size               : 10000
    Max Entries              : 5
    Segment Compact Factor   : 0.5
 

Parameters:
homeDir - the home directory of DataSet
initLevel - the initial level when DataSet is created
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
hashLoadThreshold - the load factor of the underlying address array (hash table)
hashFunction - the hash function for mapping values to indexes
Throws:
Exception - if this dynamic data set cannot be created.

DynamicDataSet

public DynamicDataSet(File homeDir,
                      int initLevel,
                      int entrySize,
                      int maxEntries,
                      int segmentFileSizeMB,
                      SegmentFactory segmentFactory)
               throws Exception
Creates a dynamic DataSet with the settings below:
    Segment Compact Factor   : 0.5
    DataSet Hash Load Factor : 0.75
    DataSet Hash Function    : krati.util.FnvHashFunction
 

Parameters:
homeDir - the home directory of DataSet
initLevel - the initial level when DataSet is created
entrySize - the redo entry size (i.e., batch size)
maxEntries - the number of redo entries required for updating the underlying address array
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
Throws:
Exception - if this dynamic data set cannot be created.

DynamicDataSet

public DynamicDataSet(File homeDir,
                      int initLevel,
                      int entrySize,
                      int maxEntries,
                      int segmentFileSizeMB,
                      SegmentFactory segmentFactory,
                      double hashLoadThreshold,
                      HashFunction<byte[]> hashFunction)
               throws Exception
Creates a dynamic DataSet.
    Segment Compact Factor   : 0.5
 

Parameters:
homeDir - the home directory of DataSet
initLevel - the initial level when DataSet is created
entrySize - the redo entry size (i.e., batch size)
maxEntries - the number of redo entries required for updating the underlying address array
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
hashLoadThreshold - the load factor of the underlying address array (hash table)
hashFunction - the hash function for mapping values to indexes
Throws:
Exception - if this dynamic data set cannot be created.

DynamicDataSet

public DynamicDataSet(File homeDir,
                      int initLevel,
                      int entrySize,
                      int maxEntries,
                      int segmentFileSizeMB,
                      SegmentFactory segmentFactory,
                      double segmentCompactFactor,
                      double hashLoadThreshold,
                      HashFunction<byte[]> hashFunction)
               throws Exception
Creates a dynamic DataSet.

Parameters:
homeDir - the home directory of DataSet
initLevel - the initial level when DataSet is created
entrySize - the redo entry size (i.e., batch size)
maxEntries - the number of redo entries required for updating the underlying address array
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
segmentCompactFactor - the load factor of segment, below which a segment is eligible for compaction
hashLoadThreshold - the load factor of the underlying address array (hash table)
hashFunction - the hash function for mapping values to indexes
Throws:
Exception - if this dynamic data set cannot be created.
Method Detail

createAddressArray

protected DynamicLongArray createAddressArray(int entrySize,
                                              int maxEntries,
                                              File homeDirectory)
                                       throws Exception
Throws:
Exception

hash

protected long hash(byte[] value)

nextScn

protected long nextScn()

sync

public void sync()
          throws IOException
Specified by:
sync in interface DataSet<byte[]>
Throws:
IOException

persist

public void persist()
             throws IOException
Specified by:
persist in interface DataSet<byte[]>
Throws:
IOException

has

public boolean has(byte[] value)
Specified by:
has in interface DataSet<byte[]>

countCollisions

public final int countCollisions(byte[] value)

hasWithoutCollisions

public final boolean hasWithoutCollisions(byte[] value)

add

public boolean add(byte[] value)
            throws Exception
Specified by:
add in interface DataSet<byte[]>
Throws:
Exception

delete

public boolean delete(byte[] value)
               throws Exception
Specified by:
delete in interface DataSet<byte[]>
Throws:
Exception

clear

public void clear()
           throws IOException
Specified by:
clear in interface DataSet<byte[]>
Throws:
IOException

getIndex

protected final int getIndex(byte[] value)

getIndex

protected final int getIndex(long hashCode)

addInternal

protected boolean addInternal(int index,
                              byte[] value)
                       throws Exception
Throws:
Exception

deleteInternal

protected boolean deleteInternal(int index,
                                 byte[] value)
                          throws Exception
Throws:
Exception

getLevel

public final int getLevel()

getSplit

public final int getSplit()

getCapacity

public final int getCapacity()

getUnitCapacity

public final int getUnitCapacity()

getLevelCapacity

public final int getLevelCapacity()

getLoadCount

public final int getLoadCount()

getLoadFactor

public final double getLoadFactor()

getLoadThreshold

public final double getLoadThreshold()

rehash

public void rehash()
            throws Exception
Throws:
Exception

getStatus

public String getStatus()
Returns:
the status of this data set.

getDataArray

public DataArray getDataArray()
Returns:
the underlying data array.


Copyright © 2011. All Rights Reserved.