public interface HashSlotArray extends Disposable
A Flyweight object that manages the backbone array of an off-heap open-addressed hashtable.
The backbone consists of slots, where each slot has a key part and an optional value part.
The size of the key part varies by subtype (HashSlotArray8byteKey
, HashSlotArray16byteKey
).
The size of the value part can be specified on instantiation and there are subtypes specialized for
zero-size values (HashSlotArray8byteKeyNoValue
, HashSlotArray16byteKeyNoValue
).
At this level of abstraction the slot-accessing methods are not defined because they are specific
to a given key size. These methods are defined in the key size-specific subtypes. The notes presented
here, however, apply to all cases.
The update operations only ensure that a slot for a given key exists/doesn't exist and it is
up to the caller to manage the contents of the value part. The caller will be provided
with the raw address of the value, suitable for accessing with the associated
MemoryAccessor
.
The returned address is valid only up to the next map update operation.
Since this is a Flyweight-style object, the same instance can be used to manage many
hashtables, one at a time. The gotoAddress(long)
method resets the instance to work
with the hashtable at the provided address and gotoNew()
allocates a new hashtable.
It is the caller's duty to ensure against memory leaks by keeping track of all existing hashtables'
base addresses. Since an update operation may trigger a new allocation, freeing the old block,
it is the caller's duty to save the new address before moving on to another base address.
The base address, returned by address()
, is the addres of the first slot in the array.
It is preceded by the header of size 24
which holds the metadata
that pertains to the structure as a whole (capacity
, size
, and expandAt
).
A slot consists of the key part and the value part, in that order, and the size of a slot is exactly the sum of the
sizes of the key and value parts. The size of the memory block that backs the entire structure is equal to
24 + (capacity()
* slot size), and
its base address is address()
- 24.
A special value must be reserved to mark an
Modifier and Type | Method and Description |
---|---|
long |
address() |
long |
capacity() |
void |
clear()
After this method returns, all slots in the current hash slot array are unassigned.
|
long |
expansionThreshold()
Array expansion and rehashing will be triggered when
size reaches this value. |
void |
gotoAddress(long address)
Position this flyweight to the supplied base address.
|
long |
gotoNew()
Allocate a new array and position this flyweight to its base address.
|
long |
size() |
boolean |
trimToSize()
Compact the array by reducing its capacity, if allowed by the current size and load factor.
|
dispose
long address()
void gotoAddress(long address)
long gotoNew()
long size()
long capacity()
long expansionThreshold()
size
reaches this value.void clear()
boolean trimToSize()
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.