public interface HashContainer extends Container
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.
HashContainerFactory
Modifier and Type | Method and Description |
---|---|
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()
|
clear, isEmpty, size, sizeAsLong
@Nonnull HashConfig hashConfig()
double currentLoad()
hashConfig()
.getMaxLoad()
,
expansion is triggered.boolean ensureCapacity(long minSize)
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.
ensureCapacity
in interface Container
minSize
- the desired minimum size, which the container is expected to reach soontrue
if rehash has been actually performed to ensure capacity,
and the next minSize - size()
insertions won't cause rehash for sure.IllegalArgumentException
- if minSize
is negativeUnsupportedOperationException
- if the container doesn't support insertionsboolean shrink()
shrink
in interface Container
true
if the hash has been actually shrunkUnsupportedOperationException
- if the container is immutable