gnu.trove.impl.hash
Class THash
- java.lang.Object
-
- gnu.trove.impl.hash.THash
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable
- Direct Known Subclasses:
- TObjectHash, TPrimitiveHash
public abstract class THash extends java.lang.Object implements java.io.ExternalizableBase class for hashtables that use open addressing to resolve collisions. Created: Wed Nov 28 21:11:16 2001- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description THash()Creates a newTHashinstance with the default capacity and load factor.THash(int initialCapacity)Creates a newTHashinstance with a prime capacity at or near the specified capacity and with the default load factor.THash(int initialCapacity, float loadFactor)Creates a newTHashinstance with a prime capacity at or near the minimum needed to hold initialCapacity elements with load factor loadFactor without triggering a rehash.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description abstract intcapacity()voidclear()Empties the collection.voidcompact()Compresses the hashtable to the minimum prime size (as defined by PrimeFinder) that will hold all of the elements currently in the table.voidensureCapacity(int desiredCapacity)Ensure that this hashtable has sufficient capacity to hold desiredCapacity additional elements without requiring a rehash.floatgetAutoCompactionFactor()booleanisEmpty()Tells whether this set is currently holding any elements.voidreadExternal(java.io.ObjectInput in)voidreenableAutoCompaction(boolean check_for_compaction)Re-enable auto-compaction after it was disabled viatempDisableAutoCompaction().voidsetAutoCompactionFactor(float factor)The auto-compaction factor controls whether and when a table performs acompact()automatically after a certain number of remove operations.intsize()Returns the number of distinct elements in this collection.voidtempDisableAutoCompaction()Temporarily disables auto-compaction.voidtrimToSize()This simply callscompact.voidwriteExternal(java.io.ObjectOutput out)
-
-
-
Constructor Detail
-
THash
public THash()
Creates a newTHashinstance with the default capacity and load factor.
-
THash
public THash(int initialCapacity)
Creates a newTHashinstance with a prime capacity at or near the specified capacity and with the default load factor.- Parameters:
initialCapacity- anintvalue
-
THash
public THash(int initialCapacity, float loadFactor)Creates a newTHashinstance with a prime capacity at or near the minimum needed to hold initialCapacity elements with load factor loadFactor without triggering a rehash.- Parameters:
initialCapacity- anintvalueloadFactor- afloatvalue
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Tells whether this set is currently holding any elements.- Returns:
- a
booleanvalue
-
size
public int size()
Returns the number of distinct elements in this collection.- Returns:
- an
intvalue
-
capacity
public abstract int capacity()
- Returns:
- the current physical capacity of the hash table.
-
ensureCapacity
public void ensureCapacity(int desiredCapacity)
Ensure that this hashtable has sufficient capacity to hold desiredCapacity additional elements without requiring a rehash. This is a tuning method you can call before doing a large insert.- Parameters:
desiredCapacity- anintvalue
-
compact
public 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. If you have done a lot of remove operations and plan to do a lot of queries or insertions or iteration, it is a good idea to invoke this method. Doing so will accomplish two things:- You'll free memory allocated to the table but no longer needed because of the remove()s.
- You'll get better query/insert/iterator performance because there won't be any REMOVED slots to skip over when probing for indices in the table.
-
setAutoCompactionFactor
public void setAutoCompactionFactor(float factor)
The auto-compaction factor controls whether and when a table performs acompact()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.- Parameters:
factor- a float that indicates the auto-compaction factor
-
getAutoCompactionFactor
public float getAutoCompactionFactor()
- Returns:
- a <float that represents the auto-compaction factor.
- See Also:
setAutoCompactionFactor(float)
-
trimToSize
public final void trimToSize()
This simply callscompact. 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.- See Also:
compact()
-
clear
public void clear()
Empties the collection.
-
tempDisableAutoCompaction
public void tempDisableAutoCompaction()
Temporarily disables auto-compaction. MUST be followed by callingreenableAutoCompaction(boolean).
-
reenableAutoCompaction
public void reenableAutoCompaction(boolean check_for_compaction)
Re-enable auto-compaction after it was disabled viatempDisableAutoCompaction().- Parameters:
check_for_compaction- True if compaction should be performed if needed before returning. If false, no compaction will be performed.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG