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;
import com.carrotsearch.hppc.FloatArrayList;
import com.carrotsearch.hppc.IntArrayList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -117,8 +118,8 @@ abstract class FloatTaxonomyFacets extends TaxonomyFacets {
int ord = children[dimOrd];
float aggregatedValue = 0;
List<Integer> ordinals = new ArrayList<>();
List<Float> ordValues = new ArrayList<>();
IntArrayList ordinals = new IntArrayList();
FloatArrayList ordValues = new FloatArrayList();
while (ord != TaxonomyReader.INVALID_ORDINAL) {
if (values[ord] > 0) {
@ -144,15 +145,11 @@ abstract class FloatTaxonomyFacets extends TaxonomyFacets {
// 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
// so that we don't need to do this copy just to look up bulk paths
int[] ordinalArray = new int[ordinals.size()];
for (int i = 0; i < ordinals.size(); i++) {
ordinalArray[i] = ordinals.get(i);
}
// TODO: It would be nice if TaxonomyReader let us pass in a buffer + size so we didn't have to
// do an array copy here:
FacetLabel[] bulkPath = taxoReader.getBulkPath(ordinals.toArray());
LabelAndValue[] labelValues = new LabelAndValue[ordValues.size()];
FacetLabel[] bulkPath = taxoReader.getBulkPath(ordinalArray);
for (int i = 0; i < labelValues.length; 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;
import com.carrotsearch.hppc.IntArrayList;
import com.carrotsearch.hppc.IntIntHashMap;
import com.carrotsearch.hppc.cursors.IntIntCursor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -175,8 +175,8 @@ abstract class IntTaxonomyFacets extends TaxonomyFacets {
int aggregatedValue = 0;
List<Integer> ordinals = new ArrayList<>();
List<Integer> ordValues = new ArrayList<>();
IntArrayList ordinals = new IntArrayList();
IntArrayList ordValues = new IntArrayList();
if (sparseValues != null) {
for (IntIntCursor c : sparseValues) {
@ -218,15 +218,11 @@ abstract class IntTaxonomyFacets extends TaxonomyFacets {
// 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
// so that we don't need to do this copy just to look up bulk paths
int[] ordinalArray = new int[ordinals.size()];
for (int i = 0; i < ordinals.size(); i++) {
ordinalArray[i] = ordinals.get(i);
}
// TODO: It would be nice if TaxonomyReader let us pass in a buffer + size so we didn't have to
// do an array copy here:
FacetLabel[] bulkPath = taxoReader.getBulkPath(ordinals.toArray());
LabelAndValue[] labelValues = new LabelAndValue[ordValues.size()];
FacetLabel[] bulkPath = taxoReader.getBulkPath(ordinalArray);
for (int i = 0; i < ordValues.size(); i++) {
labelValues[i] = new LabelAndValue(bulkPath[i].components[cp.length], ordValues.get(i));
}