Switch Float/IntTaxonomyFacets to primitive list data structures in getAllChildren (#984)

This commit is contained in:
Greg Miller 2022-06-29 13:01:59 -07:00 committed by GitHub
parent 5c3d92d69d
commit bede1c3e8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 20 deletions

View File

@ -16,8 +16,9 @@
*/ */
package org.apache.lucene.facet.taxonomy; package org.apache.lucene.facet.taxonomy;
import com.carrotsearch.hppc.FloatArrayList;
import com.carrotsearch.hppc.IntArrayList;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -117,8 +118,8 @@ abstract class FloatTaxonomyFacets extends TaxonomyFacets {
int ord = children[dimOrd]; int ord = children[dimOrd];
float aggregatedValue = 0; float aggregatedValue = 0;
List<Integer> ordinals = new ArrayList<>(); IntArrayList ordinals = new IntArrayList();
List<Float> ordValues = new ArrayList<>(); FloatArrayList ordValues = new FloatArrayList();
while (ord != TaxonomyReader.INVALID_ORDINAL) { while (ord != TaxonomyReader.INVALID_ORDINAL) {
if (values[ord] > 0) { if (values[ord] > 0) {
@ -144,15 +145,11 @@ abstract class FloatTaxonomyFacets extends TaxonomyFacets {
// Our sum'd dim count is accurate, so we keep it // Our sum'd dim count is accurate, so we keep it
} }
// TODO: It would be nice if TaxonomyReader could directly support List in addition to an array // TODO: It would be nice if TaxonomyReader let us pass in a buffer + size so we didn't have to
// so that we don't need to do this copy just to look up bulk paths // do an array copy here:
int[] ordinalArray = new int[ordinals.size()]; FacetLabel[] bulkPath = taxoReader.getBulkPath(ordinals.toArray());
for (int i = 0; i < ordinals.size(); i++) {
ordinalArray[i] = ordinals.get(i);
}
LabelAndValue[] labelValues = new LabelAndValue[ordValues.size()]; LabelAndValue[] labelValues = new LabelAndValue[ordValues.size()];
FacetLabel[] bulkPath = taxoReader.getBulkPath(ordinalArray);
for (int i = 0; i < labelValues.length; i++) { for (int i = 0; i < labelValues.length; i++) {
labelValues[i] = new LabelAndValue(bulkPath[i].components[cp.length], ordValues.get(i)); labelValues[i] = new LabelAndValue(bulkPath[i].components[cp.length], ordValues.get(i));
} }

View File

@ -16,10 +16,10 @@
*/ */
package org.apache.lucene.facet.taxonomy; package org.apache.lucene.facet.taxonomy;
import com.carrotsearch.hppc.IntArrayList;
import com.carrotsearch.hppc.IntIntHashMap; import com.carrotsearch.hppc.IntIntHashMap;
import com.carrotsearch.hppc.cursors.IntIntCursor; import com.carrotsearch.hppc.cursors.IntIntCursor;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -175,8 +175,8 @@ abstract class IntTaxonomyFacets extends TaxonomyFacets {
int aggregatedValue = 0; int aggregatedValue = 0;
List<Integer> ordinals = new ArrayList<>(); IntArrayList ordinals = new IntArrayList();
List<Integer> ordValues = new ArrayList<>(); IntArrayList ordValues = new IntArrayList();
if (sparseValues != null) { if (sparseValues != null) {
for (IntIntCursor c : sparseValues) { for (IntIntCursor c : sparseValues) {
@ -218,15 +218,11 @@ abstract class IntTaxonomyFacets extends TaxonomyFacets {
// Our sum'd dim value is accurate, so we keep it // Our sum'd dim value is accurate, so we keep it
} }
// TODO: It would be nice if TaxonomyReader could directly support List in addition to an array // TODO: It would be nice if TaxonomyReader let us pass in a buffer + size so we didn't have to
// so that we don't need to do this copy just to look up bulk paths // do an array copy here:
int[] ordinalArray = new int[ordinals.size()]; FacetLabel[] bulkPath = taxoReader.getBulkPath(ordinals.toArray());
for (int i = 0; i < ordinals.size(); i++) {
ordinalArray[i] = ordinals.get(i);
}
LabelAndValue[] labelValues = new LabelAndValue[ordValues.size()]; LabelAndValue[] labelValues = new LabelAndValue[ordValues.size()];
FacetLabel[] bulkPath = taxoReader.getBulkPath(ordinalArray);
for (int i = 0; i < ordValues.size(); i++) { for (int i = 0; i < ordValues.size(); i++) {
labelValues[i] = new LabelAndValue(bulkPath[i].components[cp.length], ordValues.get(i)); labelValues[i] = new LabelAndValue(bulkPath[i].components[cp.length], ordValues.get(i));
} }