public class ByteArrayOrdinalMap
extends java.lang.Object
The pointersAndOrdinals
AtomicLongArray contains keys, and the ByteDataBuffer
contains values. Each key has two components.
The high 29 bits in the key represents the ordinal. The low 35 bits represents the pointer to the start position
of the byte sequence in the ByteDataBuffer. Each byte sequence is preceded by a variable-length integer
(see VarInt
), indicating the length of the sequence.
Constructor and Description |
---|
ByteArrayOrdinalMap()
Creates a byte array ordinal map with a an initial capacity of 256 elements,
and a load factor of 70%.
|
ByteArrayOrdinalMap(int size)
Creates a byte array ordinal map with an initial capacity of a given size
rounded up to the nearest power of two, and a load factor of 70%.
|
Modifier and Type | Method and Description |
---|---|
void |
compact(ThreadSafeBitSet usedOrdinals)
Reclaim space in the byte array used in the previous cycle, but not referenced in this cycle.
|
int |
get(ByteDataBuffer serializedRepresentation)
Returns the ordinal for a previously added byte sequence.
|
ByteDataBuffer |
getByteData() |
long |
getDataSize() |
int |
getOrAssignOrdinal(ByteDataBuffer serializedRepresentation) |
int |
getOrAssignOrdinal(ByteDataBuffer serializedRepresentation,
int preferredOrdinal)
Adds a sequence of bytes to this map.
|
static int |
getOrdinal(long pointerAndOrdinal) |
static long |
getPointer(long pointerAndOrdinal) |
long |
getPointerForData(int ordinal) |
java.util.concurrent.atomic.AtomicLongArray |
getPointersAndOrdinals() |
java.util.BitSet |
getUnusedPreviousOrdinals() |
static boolean |
isPointerAndOrdinalEmpty(long pointerAndOrdinal) |
boolean |
isReadyForAddingObjects() |
boolean |
isReadyForWriting() |
int |
maxOrdinal() |
void |
prepareForWrite()
Create an array mapping the ordinals to pointers, so that they can be easily looked up
when writing to blob streams.
|
void |
put(ByteDataBuffer serializedRepresentation,
int ordinal)
Assign a predefined ordinal to a serialized representation.
|
void |
recalculateFreeOrdinals() |
void |
reservePreviouslyPopulatedOrdinals(java.util.BitSet populatedOrdinals) |
void |
resize(int size)
Resize the ordinal map by increasing its capacity.
|
public ByteArrayOrdinalMap()
public ByteArrayOrdinalMap(int size)
public int getOrAssignOrdinal(ByteDataBuffer serializedRepresentation)
public int getOrAssignOrdinal(ByteDataBuffer serializedRepresentation, int preferredOrdinal)
This operation is thread-safe.
serializedRepresentation
- the sequence of bytespreferredOrdinal
- the preferred ordinal to assign, if not already assigned to
another sequence of bytes and the given sequence of bytes has not previously been addedpublic void put(ByteDataBuffer serializedRepresentation, int ordinal)
WARNING: THIS OPERATION IS NOT THREAD-SAFE.
WARNING: THIS OPERATION WILL NOT UPDATE THE FreeOrdinalTracker.
serializedRepresentation
- the serialized representationordinal
- the ordinalpublic void recalculateFreeOrdinals()
public void reservePreviouslyPopulatedOrdinals(java.util.BitSet populatedOrdinals)
public java.util.BitSet getUnusedPreviousOrdinals()
public int get(ByteDataBuffer serializedRepresentation)
This is intended for use in the client-side heap-safe double snapshot load.
serializedRepresentation
- the serialized representationpublic void prepareForWrite()
public void compact(ThreadSafeBitSet usedOrdinals)
This is achieved by shifting all used byte sequences down in the byte array, then updating the key array to reflect the new pointers and exclude the removed entries. This is also where ordinals which are unused are returned to the pool.
usedOrdinals
- a bit set representing the ordinals which are currently referenced by any image.public long getPointerForData(int ordinal)
public boolean isReadyForWriting()
public boolean isReadyForAddingObjects()
public long getDataSize()
public int maxOrdinal()
public void resize(int size)
No action is take if the current capacity is sufficient for the given size.
WARNING: THIS OPERATION IS NOT THREAD-SAFE.
size
- the size to increase to, rounded up to the nearest power of two.public ByteDataBuffer getByteData()
public java.util.concurrent.atomic.AtomicLongArray getPointersAndOrdinals()
public static boolean isPointerAndOrdinalEmpty(long pointerAndOrdinal)
public static long getPointer(long pointerAndOrdinal)
public static int getOrdinal(long pointerAndOrdinal)