public abstract class THash extends Object implements Cloneable, Externalizable
Modifier and Type | Field and Description |
---|---|
protected float |
_autoCompactionFactor
The auto-compaction factor for the table.
|
protected int |
_autoCompactRemovesRemaining
The number of removes that should be performed before an auto-compaction occurs.
|
protected int |
_free
the current number of free slots in the hash.
|
protected float |
_loadFactor
Determines how full the internal table can become before rehashing is required.
|
protected int |
_maxSize
The maximum number of elements allowed without allocating more space.
|
protected int |
_size
the current number of occupied slots in the hash.
|
protected static int |
DEFAULT_INITIAL_CAPACITY
the default initial capacity for the hash table.
|
protected static float |
DEFAULT_LOAD_FACTOR
the load above which rehashing occurs.
|
Constructor and Description |
---|
THash()
Creates a new
THash instance with the default capacity and load factor. |
THash(int initialCapacity)
Creates a new
THash instance with a prime capacity at or near the specified
capacity and with the default load factor. |
THash(int initialCapacity,
float loadFactor)
Creates a new
THash instance with a prime capacity at or near the minimum needed
to hold initialCapacity elements with load factor loadFactor without
triggering a rehash. |
Modifier and Type | Method and Description |
---|---|
protected int |
calculateGrownCapacity() |
protected abstract int |
capacity() |
void |
clear()
Empties the collection.
|
Object |
clone() |
void |
compact()
Compresses the hashtable to the minimum prime size (as defined by PrimeFinder) that will hold
all of the elements currently in the table.
|
void |
ensureCapacity(int desiredCapacity)
Ensure that this hashtable has sufficient capacity to hold desiredCapacity
additional elements without requiring a rehash.
|
float |
getAutoCompactionFactor() |
boolean |
isEmpty()
Tells whether this set is currently holding any elements.
|
protected void |
postInsertHook(boolean usedFreeSlot)
After an insert, this hook is called to adjust the size/free values of the set and to perform
rehashing if necessary.
|
void |
readExternal(ObjectInput in) |
protected void |
reenableAutoCompaction(boolean check_for_compaction)
Re-enable auto-compaction after it was disabled via
tempDisableAutoCompaction() . |
protected abstract void |
rehash(int newCapacity)
Rehashes the set.
|
protected void |
removeAt(int index)
Delete the record at index.
|
void |
setAutoCompactionFactor(float factor)
The auto-compaction factor controls whether and when a table performs a
compact()
automatically after a certain number of remove operations. |
protected int |
setUp(int initialCapacity)
initializes the hashtable to a prime capacity which is at least initialCapacity +
1.
|
int |
size()
Returns the number of distinct elements in this collection.
|
protected void |
tempDisableAutoCompaction()
Temporarily disables auto-compaction.
|
void |
trimToSize()
This simply calls
compact . |
void |
writeExternal(ObjectOutput out) |
protected static final float DEFAULT_LOAD_FACTOR
protected static final int DEFAULT_INITIAL_CAPACITY
protected transient int _size
protected transient int _free
protected float _loadFactor
protected int _maxSize
protected int _autoCompactRemovesRemaining
protected float _autoCompactionFactor
setAutoCompactionFactor(float)
public THash()
THash
instance with the default capacity and load factor.public THash(int initialCapacity)
THash
instance with a prime capacity at or near the specified
capacity and with the default load factor.initialCapacity
- an int
valuepublic THash(int initialCapacity, float loadFactor)
THash
instance with a prime capacity at or near the minimum needed
to hold initialCapacity elements with load factor loadFactor without
triggering a rehash.initialCapacity
- an int
valueloadFactor
- a float
valuepublic boolean isEmpty()
boolean
valuepublic int size()
int
valueprotected abstract int capacity()
public void ensureCapacity(int desiredCapacity)
desiredCapacity
- an int
valuepublic void compact()
public void setAutoCompactionFactor(float factor)
compact()
automatically after a certain number of remove operations. If the value is non-zero, the
number of removes that need to occur for auto-compaction is the size of table at the time of
the previous compaction (or the initial capacity) multiplied by this factor. Setting this value to zero will disable auto-compaction.
public float getAutoCompactionFactor()
setAutoCompactionFactor(float)
public final void trimToSize()
compact
. It is included for symmetry with other
collection classes. Note that the name of this method is somewhat misleading (which is why
we prefer compact) as the load factor may require capacity above and beyond the size
of this collection.compact()
protected void removeAt(int index)
index
- an int
valuepublic void clear()
protected int setUp(int initialCapacity)
initialCapacity
- an int
valueprotected abstract void rehash(int newCapacity)
newCapacity
- an int
valueprotected void tempDisableAutoCompaction()
reenableAutoCompaction(boolean)
.protected void reenableAutoCompaction(boolean check_for_compaction)
tempDisableAutoCompaction()
.check_for_compaction
- True if compaction should be performed if needed before
returning. If false, no compaction will be performed.protected final void postInsertHook(boolean usedFreeSlot)
protected int calculateGrownCapacity()
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
Copyright © GigaSpaces.