Skip to content

Commit f8a6fe7

Browse files
committed
Merge branch 'remove-fst-ctor' into pr-12543-1
2 parents f0b78d2 + 4f85e19 commit f8a6fe7

File tree

21 files changed

+85
-80
lines changed

21 files changed

+85
-80
lines changed

lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/TokenInfoDictionary.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.lucene.analysis.ja.dict;
1818

19+
import static org.apache.lucene.util.fst.FST.readMetadata;
20+
1921
import java.io.BufferedInputStream;
2022
import java.io.IOException;
2123
import java.io.InputStream;
@@ -103,7 +105,7 @@ private TokenInfoDictionary(
103105
FST<Long> fst;
104106
try (InputStream is = new BufferedInputStream(fstResource.get())) {
105107
DataInput in = new InputStreamDataInput(is);
106-
fst = new FST<>(in, in, PositiveIntOutputs.getSingleton());
108+
fst = new FST<>(readMetadata(in, PositiveIntOutputs.getSingleton()), in);
107109
}
108110
// TODO: some way to configure?
109111
this.fst = new TokenInfoFST(fst, true);

lucene/analysis/nori/src/java/org/apache/lucene/analysis/ko/dict/TokenInfoDictionary.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.lucene.analysis.ko.dict;
1818

19+
import static org.apache.lucene.util.fst.FST.readMetadata;
20+
1921
import java.io.BufferedInputStream;
2022
import java.io.IOException;
2123
import java.io.InputStream;
@@ -102,7 +104,7 @@ private TokenInfoDictionary(
102104
FST<Long> fst;
103105
try (InputStream is = new BufferedInputStream(fstResource.get())) {
104106
DataInput in = new InputStreamDataInput(is);
105-
fst = new FST<>(in, in, PositiveIntOutputs.getSingleton());
107+
fst = new FST<>(readMetadata(in, PositiveIntOutputs.getSingleton()), in);
106108
}
107109
this.fst = new TokenInfoFST(fst);
108110
}

lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene40/blocktree/FieldReader.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.lucene.backward_codecs.lucene40.blocktree;
1818

19+
import static org.apache.lucene.util.fst.FST.readMetadata;
20+
1921
import java.io.IOException;
2022
import org.apache.lucene.index.FieldInfo;
2123
import org.apache.lucene.index.IndexOptions;
@@ -89,9 +91,17 @@ public final class FieldReader extends Terms {
8991
final IndexInput clone = indexIn.clone();
9092
clone.seek(indexStartFP);
9193
if (metaIn == indexIn) { // Only true before Lucene 8.6
92-
index = new FST<>(clone, clone, ByteSequenceOutputs.getSingleton(), new OffHeapFSTStore());
94+
index =
95+
new FST<>(
96+
readMetadata(clone, ByteSequenceOutputs.getSingleton()),
97+
clone,
98+
new OffHeapFSTStore());
9399
} else {
94-
index = new FST<>(metaIn, clone, ByteSequenceOutputs.getSingleton(), new OffHeapFSTStore());
100+
index =
101+
new FST<>(
102+
readMetadata(metaIn, ByteSequenceOutputs.getSingleton()),
103+
clone,
104+
new OffHeapFSTStore());
95105
}
96106
/*
97107
if (false) {

lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.lucene.codecs.blockterms;
1818

19+
import static org.apache.lucene.util.fst.FST.readMetadata;
20+
1921
import java.io.IOException;
2022
import java.util.Collection;
2123
import java.util.Collections;
@@ -154,7 +156,7 @@ private final class FieldIndexData implements Accountable {
154156
public FieldIndexData(IndexInput in, FieldInfo fieldInfo, long indexStart) throws IOException {
155157
IndexInput clone = in.clone();
156158
clone.seek(indexStart);
157-
fst = new FST<>(clone, clone, fstOutputs);
159+
fst = new FST<>(readMetadata(clone, fstOutputs), clone);
158160
clone.close();
159161

160162
/*

lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsFieldReader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.lucene.codecs.blocktreeords;
1818

19+
import static org.apache.lucene.util.fst.FST.readMetadata;
20+
1921
import java.io.IOException;
2022
import org.apache.lucene.codecs.blocktreeords.FSTOrdsOutputs.Output;
2123
import org.apache.lucene.index.FieldInfo;
@@ -85,7 +87,7 @@ final class OrdsFieldReader extends Terms {
8587
final IndexInput clone = indexIn.clone();
8688
// System.out.println("start=" + indexStartFP + " field=" + fieldInfo.name);
8789
clone.seek(indexStartFP);
88-
index = new FST<>(clone, clone, OrdsBlockTreeTermsWriter.FST_OUTPUTS);
90+
index = new FST<>(readMetadata(clone, OrdsBlockTreeTermsWriter.FST_OUTPUTS), clone);
8991

9092
/*
9193
if (true) {

lucene/codecs/src/java/org/apache/lucene/codecs/memory/FSTTermsReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ final class TermsReader extends Terms {
194194
this.sumDocFreq = sumDocFreq;
195195
this.docCount = docCount;
196196
OffHeapFSTStore offHeapFSTStore = new OffHeapFSTStore();
197-
this.dict = new FST<>(in, in, new FSTTermOutputs(fieldInfo), offHeapFSTStore);
197+
FSTTermOutputs outputs = new FSTTermOutputs(fieldInfo);
198+
this.dict = new FST<>(FST.readMetadata(in, outputs), in, offHeapFSTStore);
198199
in.skipBytes(offHeapFSTStore.size());
199200
}
200201

lucene/codecs/src/java/org/apache/lucene/codecs/uniformsplit/FSTDictionary.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ protected static FSTDictionary read(
8989
isFSTOnHeap = true;
9090
}
9191
PositiveIntOutputs fstOutputs = PositiveIntOutputs.getSingleton();
92+
FST.FSTMetadata<Long> metadata = FST.readMetadata(fstDataInput, fstOutputs);
9293
FST<Long> fst =
9394
isFSTOnHeap
94-
? new FST<>(fstDataInput, fstDataInput, fstOutputs)
95-
: new FST<>(fstDataInput, fstDataInput, fstOutputs, new OffHeapFSTStore());
95+
? new FST<>(metadata, fstDataInput)
96+
: new FST<>(metadata, fstDataInput, new OffHeapFSTStore());
9697
return new FSTDictionary(fst);
9798
}
9899

lucene/core/src/java/org/apache/lucene/codecs/lucene90/blocktree/FieldReader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ public final class FieldReader extends Terms {
9191
// Initialize FST always off-heap.
9292
final IndexInput clone = indexIn.clone();
9393
clone.seek(indexStartFP);
94-
index = new FST<>(metaIn, clone, ByteSequenceOutputs.getSingleton(), new OffHeapFSTStore());
94+
index =
95+
new FST<>(
96+
FST.readMetadata(metaIn, ByteSequenceOutputs.getSingleton()),
97+
clone,
98+
new OffHeapFSTStore());
9599
/*
96100
if (false) {
97101
final String dotFileName = segment + "_" + fieldInfo.name + ".dot";

lucene/core/src/java/org/apache/lucene/util/fst/FST.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -402,34 +402,23 @@ private static boolean flag(int flags, int bit) {
402402
* Load a previously saved FST with a DataInput for metdata using an {@link OnHeapFSTStore} with
403403
* maxBlockBits set to {@link #DEFAULT_MAX_BLOCK_BITS}
404404
*/
405-
public FST(DataInput metaIn, DataInput in, Outputs<T> outputs) throws IOException {
406-
this(metaIn, in, outputs, new OnHeapFSTStore(DEFAULT_MAX_BLOCK_BITS));
407-
}
408-
409-
/**
410-
* Load a previously saved FST with a DataInput for metdata and a FSTStore. If using {@link
411-
* OnHeapFSTStore}, setting maxBlockBits allows you to control the size of the byte[] pages used
412-
* to hold the FST bytes.
413-
*/
414-
public FST(DataInput metaIn, DataInput in, Outputs<T> outputs, FSTStore fstStore)
415-
throws IOException {
416-
this(readMetadata(metaIn, outputs), in, outputs, fstStore);
405+
public FST(FSTMetadata<T> metadata, DataInput in) throws IOException {
406+
this(metadata, in, new OnHeapFSTStore(DEFAULT_MAX_BLOCK_BITS));
417407
}
418408

419409
/**
420410
* Load a previously saved FST with a metdata object and a FSTStore. If using {@link
421411
* OnHeapFSTStore}, setting maxBlockBits allows you to control the size of the byte[] pages used
422412
* to hold the FST bytes.
423413
*/
424-
public FST(FSTMetadata<T> metadata, DataInput in, Outputs<T> outputs, FSTStore fstStore)
425-
throws IOException {
426-
this(metadata, outputs, fstStore.init(in, metadata.numBytes));
414+
public FST(FSTMetadata<T> metadata, DataInput in, FSTStore fstStore) throws IOException {
415+
this(metadata, fstStore.init(in, metadata.numBytes));
427416
}
428417

429418
/** Create the FST with a metadata object and a FSTReader. */
430-
FST(FSTMetadata<T> metadata, Outputs<T> outputs, FSTReader fstReader) {
419+
FST(FSTMetadata<T> metadata, FSTReader fstReader) {
431420
this.metadata = metadata;
432-
this.outputs = outputs;
421+
this.outputs = metadata.outputs;
433422
this.fstReader = fstReader;
434423
}
435424

@@ -491,7 +480,7 @@ public static <T> FSTMetadata<T> readMetadata(DataInput metaIn, Outputs<T> outpu
491480
}
492481
long startNode = metaIn.readVLong();
493482
long numBytes = metaIn.readVLong();
494-
return new FSTMetadata<>(inputType, emptyOutput, startNode, version, numBytes);
483+
return new FSTMetadata<>(inputType, outputs, emptyOutput, startNode, version, numBytes);
495484
}
496485

497486
@Override
@@ -594,7 +583,7 @@ public void save(final Path path) throws IOException {
594583
public static <T> FST<T> read(Path path, Outputs<T> outputs) throws IOException {
595584
try (InputStream is = Files.newInputStream(path)) {
596585
DataInput in = new InputStreamDataInput(new BufferedInputStream(is));
597-
return new FST<>(in, in, outputs);
586+
return new FST<>(readMetadata(in, outputs), in);
598587
}
599588
}
600589

@@ -1230,6 +1219,7 @@ public abstract static class BytesReader extends DataInput {
12301219
*/
12311220
public static final class FSTMetadata<T> {
12321221
final INPUT_TYPE inputType;
1222+
final Outputs<T> outputs;
12331223
final int version;
12341224
// if non-null, this FST accepts the empty string and
12351225
// produces this output
@@ -1238,8 +1228,14 @@ public static final class FSTMetadata<T> {
12381228
long numBytes;
12391229

12401230
public FSTMetadata(
1241-
INPUT_TYPE inputType, T emptyOutput, long startNode, int version, long numBytes) {
1231+
INPUT_TYPE inputType,
1232+
Outputs<T> outputs,
1233+
T emptyOutput,
1234+
long startNode,
1235+
int version,
1236+
long numBytes) {
12421237
this.inputType = inputType;
1238+
this.outputs = outputs;
12431239
this.emptyOutput = emptyOutput;
12441240
this.startNode = startNode;
12451241
this.version = version;

lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ private FSTCompiler(
156156
this.dataOutput = dataOutput;
157157
fst =
158158
new FST<>(
159-
new FST.FSTMetadata<>(inputType, null, -1, VERSION_CURRENT, 0),
160-
outputs,
159+
new FST.FSTMetadata<>(inputType, outputs, null, -1, VERSION_CURRENT, 0),
161160
toFSTReader(dataOutput));
162161
if (suffixRAMLimitMB < 0) {
163162
throw new IllegalArgumentException("ramLimitMB must be >= 0; got: " + suffixRAMLimitMB);
@@ -774,21 +773,6 @@ private void freezeTail(int prefixLenPlus1) throws IOException {
774773
* IntSequenceOutputs}) then you cannot reuse across calls.
775774
*/
776775
public void add(IntsRef input, T output) throws IOException {
777-
/*
778-
if (DEBUG) {
779-
BytesRef b = new BytesRef(input.length);
780-
for(int x=0;x<input.length;x++) {
781-
b.bytes[x] = (byte) input.ints[x];
782-
}
783-
b.length = input.length;
784-
if (output == NO_OUTPUT) {
785-
System.out.println("\nFST ADD: input=" + toString(b) + " " + b);
786-
} else {
787-
System.out.println("\nFST ADD: input=" + toString(b) + " " + b + " output=" + fst.outputs.outputToString(output));
788-
}
789-
}
790-
*/
791-
792776
// De-dup NO_OUTPUT since it must be a singleton:
793777
if (output.equals(NO_OUTPUT)) {
794778
output = NO_OUTPUT;

0 commit comments

Comments
 (0)