You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2023/08/03 05:16:49 UTC
[lucene] branch main updated: Clenup duplication in BKDWriter (#12469)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new e78feb78098 Clenup duplication in BKDWriter (#12469)
e78feb78098 is described below
commit e78feb78098605e09b01a97d3ca32ff700e42a4b
Author: Armin Braun <me...@obrown.io>
AuthorDate: Thu Aug 3 07:16:44 2023 +0200
Clenup duplication in BKDWriter (#12469)
The logic for creating the writer runnable could be deduplicated.
Also, a couple of annonymous classes could be turned into lambdas.
---
.../java/org/apache/lucene/util/bkd/BKDWriter.java | 73 +++++-----------------
1 file changed, 17 insertions(+), 56 deletions(-)
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
index dd3d4f59508..b4b8f1fe66d 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
@@ -546,37 +546,7 @@ public class BKDWriter implements Closeable {
scratchBytesRef1.length = config.bytesPerDim;
scratchBytesRef1.bytes = splitPackedValues;
- BKDTreeLeafNodes leafNodes =
- new BKDTreeLeafNodes() {
- @Override
- public long getLeafLP(int index) {
- return leafBlockFPs[index];
- }
-
- @Override
- public BytesRef getSplitValue(int index) {
- scratchBytesRef1.offset = index * config.bytesPerDim;
- return scratchBytesRef1;
- }
-
- @Override
- public int getSplitDimension(int index) {
- return splitDimensionValues[index] & 0xff;
- }
-
- @Override
- public int numLeaves() {
- return leafBlockFPs.length;
- }
- };
-
- return () -> {
- try {
- writeIndex(metaOut, indexOut, config.maxPointsInLeafNode, leafNodes, dataStartFP);
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- };
+ return makeWriter(metaOut, indexOut, splitDimensionValues, leafBlockFPs, dataStartFP);
}
/* In the 1D case, we can simply sort points in ascending order and use the
@@ -830,12 +800,9 @@ public class BKDWriter implements Closeable {
scratchBytesRef1.bytes = leafValues;
final IntFunction<BytesRef> packedValues =
- new IntFunction<BytesRef>() {
- @Override
- public BytesRef apply(int i) {
- scratchBytesRef1.offset = config.packedBytesLength * i;
- return scratchBytesRef1;
- }
+ i -> {
+ scratchBytesRef1.offset = config.packedBytesLength * i;
+ return scratchBytesRef1;
};
assert valuesInOrderAndBounds(
config,
@@ -999,6 +966,15 @@ public class BKDWriter implements Closeable {
scratchBytesRef1.bytes = splitPackedValues;
scratchBytesRef1.length = config.bytesPerDim;
+ return makeWriter(metaOut, indexOut, splitDimensionValues, leafBlockFPs, dataStartFP);
+ }
+
+ private Runnable makeWriter(
+ IndexOutput metaOut,
+ IndexOutput indexOut,
+ byte[] splitDimensionValues,
+ long[] leafBlockFPs,
+ long dataStartFP) {
BKDTreeLeafNodes leafNodes =
new BKDTreeLeafNodes() {
@Override
@@ -1717,12 +1693,9 @@ public class BKDWriter implements Closeable {
// Write the full values:
IntFunction<BytesRef> packedValues =
- new IntFunction<BytesRef>() {
- @Override
- public BytesRef apply(int i) {
- reader.getValue(from + i, scratchBytesRef1);
- return scratchBytesRef1;
- }
+ i -> {
+ reader.getValue(from + i, scratchBytesRef1);
+ return scratchBytesRef1;
};
assert valuesInOrderAndBounds(
config, count, sortedDim, minPackedValue, maxPackedValue, packedValues, docIDs, 0);
@@ -1973,19 +1946,7 @@ public class BKDWriter implements Closeable {
// Write the full values:
IntFunction<BytesRef> packedValues =
- new IntFunction<BytesRef>() {
- final BytesRef scratch = new BytesRef();
-
- {
- scratch.length = config.packedBytesLength;
- }
-
- @Override
- public BytesRef apply(int i) {
- PointValue value = heapSource.getPackedValueSlice(from + i);
- return value.packedValue();
- }
- };
+ i -> heapSource.getPackedValueSlice(from + i).packedValue();
assert valuesInOrderAndBounds(
config, count, sortedDim, minPackedValue, maxPackedValue, packedValues, docIDs, 0);
writeLeafBlockPackedValues(