Skip to content

Apache Lucene open-source search software

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

Greg Millerbede1c3e8c81
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FloatTaxonomyFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FloatTaxonomyFacets.java
index d8381ae51dc..515f60229d3 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FloatTaxonomyFacets.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FloatTaxonomyFacets.java
@@ -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));
}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java
index 9c40079c4fa..1c7ef0df2dc 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java
@@ -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));
}