com.koloboke.collect.hash
Interface HashContainer

All Superinterfaces:
Container
All Known Subinterfaces:
HashByteByteMap, HashByteCharMap, HashByteDoubleMap, HashByteFloatMap, HashByteIntMap, HashByteLongMap, HashByteObjMap<V>, HashByteSet, HashByteShortMap, HashCharByteMap, HashCharCharMap, HashCharDoubleMap, HashCharFloatMap, HashCharIntMap, HashCharLongMap, HashCharObjMap<V>, HashCharSet, HashCharShortMap, HashDoubleByteMap, HashDoubleCharMap, HashDoubleDoubleMap, HashDoubleFloatMap, HashDoubleIntMap, HashDoubleLongMap, HashDoubleObjMap<V>, HashDoubleSet, HashDoubleShortMap, HashFloatByteMap, HashFloatCharMap, HashFloatDoubleMap, HashFloatFloatMap, HashFloatIntMap, HashFloatLongMap, HashFloatObjMap<V>, HashFloatSet, HashFloatShortMap, HashIntByteMap, HashIntCharMap, HashIntDoubleMap, HashIntFloatMap, HashIntIntMap, HashIntLongMap, HashIntObjMap<V>, HashIntSet, HashIntShortMap, HashLongByteMap, HashLongCharMap, HashLongDoubleMap, HashLongFloatMap, HashLongIntMap, HashLongLongMap, HashLongObjMap<V>, HashLongSet, HashLongShortMap, HashObjByteMap<K>, HashObjCharMap<K>, HashObjDoubleMap<K>, HashObjFloatMap<K>, HashObjIntMap<K>, HashObjLongMap<K>, HashObjObjMap<K,V>, HashObjSet<E>, HashObjShortMap<K>, HashShortByteMap, HashShortCharMap, HashShortDoubleMap, HashShortFloatMap, HashShortIntMap, HashShortLongMap, HashShortObjMap<V>, HashShortSet, HashShortShortMap

public interface HashContainer
extends Container

The root interface of sets and maps, based on hash tables.

Methods in this interface mostly regard to the specific operation on hash tables - rehash. During rehash, entries of this container are moved from the old table to the new one.

If the capacity of new table is greater than the old, such rehash is also referred as expansion or growth. It is performed when the hash container's load becomes too high, and operations' performance suffers, or it's simply no place to insert the new entries.

If the capacity of new table is lesser than the old, such rehash is also called compaction or shrink. It could be performed automatically after hash container construction, if the shrink condition of the hash container's hash config triggers, or manually via shrink() method. Shrink is useful for controlling hash container's memory consumption.

See Container mutability matrix for methods which are supported by hash containers with the specific mutability profile. All methods defined in this interface directly are supported by hash containers with any mutability profile.

See Also:
HashContainerFactory

Method Summary
 double currentLoad()
          Returns fullness of the internal tables, the fraction of taken slots.
 boolean ensureCapacity(long minSize)
          Prepares the hash for insertion of minSize - Container.size() new elements without excessive rehashes.
 HashConfig hashConfig()
          Returns the hash config which holds all "magic" parameters of this hash container: load and growth factors.
 boolean shrink()
          If the current load is less than hashConfig().
 
Methods inherited from interface com.koloboke.collect.Container
clear, isEmpty, size, sizeAsLong
 

Method Detail

hashConfig

@Nonnull
HashConfig hashConfig()
Returns the hash config which holds all "magic" parameters of this hash container: load and growth factors.

Returns:
the hash config of this container

currentLoad

double currentLoad()
Returns fullness of the internal tables, the fraction of taken slots. If the current load exceeds hashConfig().getMaxLoad(), expansion is triggered.

Returns:
fullness of the hash container

ensureCapacity

boolean ensureCapacity(long minSize)
Prepares the hash for insertion of minSize - Container.size() new elements without excessive rehashes. Call of this method is a hint, but not a strict guarantee that the next minSize - size() insertions will be done in real time.

If minSize is less than the current container size, the method returns false immediately.

Specified by:
ensureCapacity in interface Container
Parameters:
minSize - the desired minimum size, which the container is expected to reach soon
Returns:
true if rehash has been actually performed to ensure capacity, and the next minSize - size() insertions won't cause rehash for sure.
Throws:
IllegalArgumentException - if minSize is negative
UnsupportedOperationException - if the container doesn't support insertions

shrink

boolean shrink()
If the current load is less than hashConfig().getTargetLoad(), compaction is performed to fix this.

Specified by:
shrink in interface Container
Returns:
true if the hash has been actually shrunk
Throws:
UnsupportedOperationException - if the container is immutable