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<String, Integer>. It also only uses a small fraction of objects a HashMap would use, thus limiting the GC overhead. Ingestion speed was also ~50% faster compared to a HashMap for 3M unique labels.
| Modifier and Type | Field and Description |
|---|---|
static float |
DefaultLoadFactor
Default maximum load factor.
|
counter, INVALID_ORDINAL| Constructor and Description |
|---|
CompactLabelToOrdinal(int initialCapacity,
float loadFactor,
int numHashArrays)
Sole constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLabel(FacetLabel label,
int ordinal)
Adds a new label if its not yet in the table.
|
int |
getOrdinal(FacetLabel label)
Returns the ordinal assigned to the given label,
or
LabelToOrdinal.INVALID_ORDINAL if the label cannot be found in this table. |
int |
sizeOfMap()
How many labels.
|
getMaxOrdinal, getNextOrdinalpublic static final float DefaultLoadFactor
public CompactLabelToOrdinal(int initialCapacity,
float loadFactor,
int numHashArrays)
public int sizeOfMap()
public void addLabel(FacetLabel label, int ordinal)
LabelToOrdinalIllegalArgumentException if the same label with
a different ordinal was previoulsy added to this table.addLabel in class LabelToOrdinalpublic int getOrdinal(FacetLabel label)
LabelToOrdinalLabelToOrdinal.INVALID_ORDINAL if the label cannot be found in this table.getOrdinal in class LabelToOrdinalCopyright © 2000-2016 Apache Software Foundation. All Rights Reserved.