Skip to content

Commit 4f85e19

Browse files
committed
Move Outputs to FSTMetadata
1 parent 730e934 commit 4f85e19

File tree

21 files changed

+79
-73
lines changed

21 files changed

+79
-73
lines changed

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

Lines changed: 3 additions & 2 deletions
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,8 +105,7 @@ private TokenInfoDictionary(
103105
FST<Long> fst;
104106
try (InputStream is = new BufferedInputStream(fstResource.get())) {
105107
DataInput in = new InputStreamDataInput(is);
106-
FST.FSTMetadata<Long> metadata = FST.readMetadata(in, PositiveIntOutputs.getSingleton());
107-
fst = new FST<>(metadata, in, PositiveIntOutputs.getSingleton());
108+
fst = new FST<>(readMetadata(in, PositiveIntOutputs.getSingleton()), in);
108109
}
109110
// TODO: some way to configure?
110111
this.fst = new TokenInfoFST(fst, true);

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

Lines changed: 3 additions & 2 deletions
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,8 +104,7 @@ private TokenInfoDictionary(
102104
FST<Long> fst;
103105
try (InputStream is = new BufferedInputStream(fstResource.get())) {
104106
DataInput in = new InputStreamDataInput(is);
105-
FST.FSTMetadata<Long> metadata = FST.readMetadata(in, PositiveIntOutputs.getSingleton());
106-
fst = new FST<>(metadata, in, PositiveIntOutputs.getSingleton());
107+
fst = new FST<>(readMetadata(in, PositiveIntOutputs.getSingleton()), in);
107108
}
108109
this.fst = new TokenInfoFST(fst);
109110
}

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

Lines changed: 12 additions & 6 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,13 +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-
FST.FSTMetadata<BytesRef> metadata =
93-
FST.readMetadata(clone, ByteSequenceOutputs.getSingleton());
94-
index = new FST<>(metadata, clone, ByteSequenceOutputs.getSingleton(), new OffHeapFSTStore());
94+
index =
95+
new FST<>(
96+
readMetadata(clone, ByteSequenceOutputs.getSingleton()),
97+
clone,
98+
new OffHeapFSTStore());
9599
} else {
96-
FST.FSTMetadata<BytesRef> metadata =
97-
FST.readMetadata(metaIn, ByteSequenceOutputs.getSingleton());
98-
index = new FST<>(metadata, clone, ByteSequenceOutputs.getSingleton(), new OffHeapFSTStore());
100+
index =
101+
new FST<>(
102+
readMetadata(metaIn, ByteSequenceOutputs.getSingleton()),
103+
clone,
104+
new OffHeapFSTStore());
99105
}
100106
/*
101107
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<>(FST.readMetadata(clone, fstOutputs), 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 & 3 deletions
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,9 +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-
FST.FSTMetadata<Output> metadata =
89-
FST.readMetadata(clone, OrdsBlockTreeTermsWriter.FST_OUTPUTS);
90-
index = new FST<>(metadata, clone, OrdsBlockTreeTermsWriter.FST_OUTPUTS);
90+
index = new FST<>(readMetadata(clone, OrdsBlockTreeTermsWriter.FST_OUTPUTS), clone);
9191

9292
/*
9393
if (true) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ final class TermsReader extends Terms {
195195
this.docCount = docCount;
196196
OffHeapFSTStore offHeapFSTStore = new OffHeapFSTStore();
197197
FSTTermOutputs outputs = new FSTTermOutputs(fieldInfo);
198-
this.dict = new FST<>(FST.readMetadata(in, outputs), in, outputs, offHeapFSTStore);
198+
this.dict = new FST<>(FST.readMetadata(in, outputs), in, offHeapFSTStore);
199199
in.skipBytes(offHeapFSTStore.size());
200200
}
201201

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ protected static FSTDictionary read(
9292
FST.FSTMetadata<Long> metadata = FST.readMetadata(fstDataInput, fstOutputs);
9393
FST<Long> fst =
9494
isFSTOnHeap
95-
? new FST<>(metadata, fstDataInput, fstOutputs)
96-
: new FST<>(metadata, fstDataInput, fstOutputs, new OffHeapFSTStore());
95+
? new FST<>(metadata, fstDataInput)
96+
: new FST<>(metadata, fstDataInput, new OffHeapFSTStore());
9797
return new FSTDictionary(fst);
9898
}
9999

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +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-
FST.FSTMetadata<BytesRef> metadata =
95-
FST.readMetadata(metaIn, ByteSequenceOutputs.getSingleton());
96-
index = new FST<>(metadata, clone, ByteSequenceOutputs.getSingleton(), new OffHeapFSTStore());
94+
index =
95+
new FST<>(
96+
FST.readMetadata(metaIn, ByteSequenceOutputs.getSingleton()),
97+
clone,
98+
new OffHeapFSTStore());
9799
/*
98100
if (false) {
99101
final String dotFileName = segment + "_" + fieldInfo.name + ".dot";

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -404,24 +404,23 @@ private static boolean flag(int flags, int bit) {
404404
* Load a previously saved FST with a DataInput for metdata using an {@link OnHeapFSTStore} with
405405
* maxBlockBits set to {@link #DEFAULT_MAX_BLOCK_BITS}
406406
*/
407-
public FST(FSTMetadata<T> metadata, DataInput in, Outputs<T> outputs) throws IOException {
408-
this(metadata, in, outputs, new OnHeapFSTStore(DEFAULT_MAX_BLOCK_BITS));
407+
public FST(FSTMetadata<T> metadata, DataInput in) throws IOException {
408+
this(metadata, in, new OnHeapFSTStore(DEFAULT_MAX_BLOCK_BITS));
409409
}
410410

411411
/**
412412
* Load a previously saved FST with a metdata object and a FSTStore. If using {@link
413413
* OnHeapFSTStore}, setting maxBlockBits allows you to control the size of the byte[] pages used
414414
* to hold the FST bytes.
415415
*/
416-
public FST(FSTMetadata<T> metadata, DataInput in, Outputs<T> outputs, FSTStore fstStore)
417-
throws IOException {
418-
this(metadata, outputs, fstStore.init(in, metadata.numBytes));
416+
public FST(FSTMetadata<T> metadata, DataInput in, FSTStore fstStore) throws IOException {
417+
this(metadata, fstStore.init(in, metadata.numBytes));
419418
}
420419

421420
/** Create the FST with a metadata object and a FSTReader. */
422-
FST(FSTMetadata<T> metadata, Outputs<T> outputs, FSTReader fstReader) {
421+
FST(FSTMetadata<T> metadata, FSTReader fstReader) {
423422
this.metadata = metadata;
424-
this.outputs = outputs;
423+
this.outputs = metadata.outputs;
425424
this.fstReader = fstReader;
426425
}
427426

@@ -476,7 +475,7 @@ public static <T> FSTMetadata<T> readMetadata(DataInput metaIn, Outputs<T> outpu
476475
}
477476
long startNode = metaIn.readVLong();
478477
long numBytes = metaIn.readVLong();
479-
return new FSTMetadata<>(inputType, emptyOutput, startNode, version, numBytes);
478+
return new FSTMetadata<>(inputType, outputs, emptyOutput, startNode, version, numBytes);
480479
}
481480

482481
@Override
@@ -564,7 +563,7 @@ public void save(final Path path) throws IOException {
564563
public static <T> FST<T> read(Path path, Outputs<T> outputs) throws IOException {
565564
try (InputStream is = Files.newInputStream(path)) {
566565
DataInput in = new InputStreamDataInput(new BufferedInputStream(is));
567-
return new FST<>(readMetadata(in, outputs), in, outputs);
566+
return new FST<>(readMetadata(in, outputs), in);
568567
}
569568
}
570569

@@ -1192,6 +1191,7 @@ public abstract static class BytesReader extends DataInput {
11921191
*/
11931192
public static final class FSTMetadata<T> {
11941193
final INPUT_TYPE inputType;
1194+
final Outputs<T> outputs;
11951195
final int version;
11961196
// if non-null, this FST accepts the empty string and
11971197
// produces this output
@@ -1200,8 +1200,14 @@ public static final class FSTMetadata<T> {
12001200
long numBytes;
12011201

12021202
public FSTMetadata(
1203-
INPUT_TYPE inputType, T emptyOutput, long startNode, int version, long numBytes) {
1203+
INPUT_TYPE inputType,
1204+
Outputs<T> outputs,
1205+
T emptyOutput,
1206+
long startNode,
1207+
int version,
1208+
long numBytes) {
12041209
this.inputType = inputType;
1210+
this.outputs = outputs;
12051211
this.emptyOutput = emptyOutput;
12061212
this.startNode = startNode;
12071213
this.version = version;

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private FSTCompiler(
144144
// pad: ensure no node gets address 0 which is reserved to mean
145145
// the stop state w/ no arcs
146146
bytes.writeByte((byte) 0);
147-
fst = new FST<>(new FST.FSTMetadata<>(inputType, null, -1, VERSION_CURRENT, 0), outputs, bytes);
147+
fst = new FST<>(new FST.FSTMetadata<>(inputType, outputs, null, -1, VERSION_CURRENT, 0), bytes);
148148
if (suffixRAMLimitMB < 0) {
149149
throw new IllegalArgumentException("ramLimitMB must be >= 0; got: " + suffixRAMLimitMB);
150150
} else if (suffixRAMLimitMB > 0) {
@@ -726,21 +726,6 @@ private void freezeTail(int prefixLenPlus1) throws IOException {
726726
* IntSequenceOutputs}) then you cannot reuse across calls.
727727
*/
728728
public void add(IntsRef input, T output) throws IOException {
729-
/*
730-
if (DEBUG) {
731-
BytesRef b = new BytesRef(input.length);
732-
for(int x=0;x<input.length;x++) {
733-
b.bytes[x] = (byte) input.ints[x];
734-
}
735-
b.length = input.length;
736-
if (output == NO_OUTPUT) {
737-
System.out.println("\nFST ADD: input=" + toString(b) + " " + b);
738-
} else {
739-
System.out.println("\nFST ADD: input=" + toString(b) + " " + b + " output=" + fst.outputs.outputToString(output));
740-
}
741-
}
742-
*/
743-
744729
// De-dup NO_OUTPUT since it must be a singleton:
745730
if (output.equals(NO_OUTPUT)) {
746731
output = NO_OUTPUT;

0 commit comments

Comments
 (0)