public class CompactLabelToOrdinal extends LabelToOrdinal
Since the HashArrays don't handle collisions, a CollisionMap
is used
to store the colliding labels.
This data structure grows by adding a new HashArray whenever the number of
collisions in the CollisionMap
exceeds loadFactor
*
LabelToOrdinal.getMaxOrdinal()
. Growing also includes reinserting all colliding
labels into the HashArrays to possibly reduce the number of collisions.
For setting the loadFactor
see
CompactLabelToOrdinal(int, float, int)
.
This data structure has a much lower memory footprint (~30%) compared to a
Java HashMap
Modifier and Type | Field and Description |
---|---|
static float |
DefaultLoadFactor |
counter, InvalidOrdinal
Constructor and Description |
---|
CompactLabelToOrdinal(int initialCapacity,
float loadFactor,
int numHashArrays) |
Modifier and Type | Method and Description |
---|---|
void |
addLabel(CategoryPath label,
int ordinal)
Adds a new label if its not yet in the table.
|
void |
addLabel(CategoryPath label,
int prefixLen,
int ordinal)
Adds a new label if its not yet in the table.
|
int |
getOrdinal(CategoryPath label) |
int |
getOrdinal(CategoryPath label,
int prefixLen) |
int |
sizeOfMap() |
getMaxOrdinal, getNextOrdinal
public static final float DefaultLoadFactor
public CompactLabelToOrdinal(int initialCapacity, float loadFactor, int numHashArrays)
public int sizeOfMap()
public void addLabel(CategoryPath label, int ordinal)
LabelToOrdinal
IllegalArgumentException
if the same label with
a different ordinal was previoulsy added to this table.addLabel
in class LabelToOrdinal
public void addLabel(CategoryPath label, int prefixLen, int ordinal)
LabelToOrdinal
IllegalArgumentException
if the same label with
a different ordinal was previoulsy added to this table.addLabel
in class LabelToOrdinal
public int getOrdinal(CategoryPath label)
getOrdinal
in class LabelToOrdinal
LabelToOrdinal.InvalidOrdinal
if the label cannot be found in this table.public int getOrdinal(CategoryPath label, int prefixLen)
getOrdinal
in class LabelToOrdinal
LabelToOrdinal.InvalidOrdinal
if the label cannot be found in this table.