Class CompactLabelToOrdinal
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatDefault maximum load factor.Fields inherited from class org.apache.lucene.facet.taxonomy.writercache.LabelToOrdinal
INVALID_ORDINAL -
Constructor Summary
ConstructorsConstructorDescriptionCompactLabelToOrdinal(int initialCapacity, float loadFactor, int numHashArrays) Sole constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLabel(FacetLabel label, int ordinal) Adds a new label if its not yet in the table.intgetOrdinal(FacetLabel label) Returns the ordinal assigned to the given label, orLabelToOrdinal.INVALID_ORDINALif the label cannot be found in this table.intHow many labels.Methods inherited from class org.apache.lucene.facet.taxonomy.writercache.LabelToOrdinal
getMaxOrdinal, getNextOrdinal
-
Field Details
-
DefaultLoadFactor
public static final float DefaultLoadFactorDefault maximum load factor.- See Also:
-
-
Constructor Details
-
CompactLabelToOrdinal
public CompactLabelToOrdinal(int initialCapacity, float loadFactor, int numHashArrays) Sole constructor.
-
-
Method Details
-
sizeOfMap
public int sizeOfMap()How many labels. -
addLabel
Description copied from class:LabelToOrdinalAdds a new label if its not yet in the table. Throws anIllegalArgumentExceptionif the same label with a different ordinal was previoulsy added to this table.- Specified by:
addLabelin classLabelToOrdinal
-
getOrdinal
Description copied from class:LabelToOrdinalReturns the ordinal assigned to the given label, orLabelToOrdinal.INVALID_ORDINALif the label cannot be found in this table.- Specified by:
getOrdinalin classLabelToOrdinal
-