mikemccand commented on code in PR #12758: URL: https://github.com/apache/lucene/pull/12758#discussion_r1382420527
########## lucene/core/src/java/org/apache/lucene/util/fst/FST.java: ########## @@ -411,17 +401,42 @@ public FST(DataInput metaIn, DataInput in, Outputs<T> outputs) throws IOExceptio this(metaIn, in, outputs, new OnHeapFSTStore(DEFAULT_MAX_BLOCK_BITS)); } + /** Load a previously saved FST. */ + public FST(DataInput metaIn, DataInput in, Outputs<T> outputs, FSTStore fstStore) + throws IOException { + this(parseMetadata(metaIn, outputs), in, outputs, fstStore); + } + /** * Load a previously saved FST; maxBlockBits allows you to control the size of the byte[] pages * used to hold the FST bytes. */ - public FST(DataInput metaIn, DataInput in, Outputs<T> outputs, FSTStore fstStore) + public FST(FSTMetadata<T> metadata, DataInput in, Outputs<T> outputs, FSTStore fstStore) throws IOException { - this.outputs = outputs; + this(metadata, outputs, initStore(fstStore, metadata.numBytes, in)); + } + + private static FSTReader initStore(FSTStore fstStore, long numBytes, DataInput in) + throws IOException { + fstStore.init(in, numBytes); + return fstStore; + } + /** + * Parse the FST metadata from DataInput + * + * @param metaIn the DataInput of the metadata + * @param outputs the FST outputs + * @return the FST metadata + * @param <T> the output type + * @throws IOException if exception occurred during parsing + */ + public static <T> FSTMetadata<T> parseMetadata(DataInput metaIn, Outputs<T> outputs) Review Comment: Maybe `readMetadata` since it is reading from a previously serialized `DataInput` source? ########## lucene/core/src/java/org/apache/lucene/util/fst/FST.java: ########## @@ -1132,4 +1137,28 @@ public abstract static class BytesReader extends DataInput { /** Returns true if this reader uses reversed bytes under-the-hood. */ public abstract boolean reversed(); } + + /** + * Represent the FST metadata + * + * @param <T> the FST output type + */ + public static class FSTMetadata<T> { + INPUT_TYPE inputType; + // if non-null, this FST accepts the empty string and + // produces this output + T emptyOutput; Review Comment: Can all of these members be `final`? Edit: no they cannot :) ########## lucene/core/src/java/org/apache/lucene/util/fst/FST.java: ########## @@ -1132,4 +1137,28 @@ public abstract static class BytesReader extends DataInput { /** Returns true if this reader uses reversed bytes under-the-hood. */ public abstract boolean reversed(); } + + /** + * Represent the FST metadata + * + * @param <T> the FST output type + */ + public static class FSTMetadata<T> { Review Comment: Can the class be `final`? This is public because callers would need to separately write/read the `FSTMetadata` some their sources? The FST bytes can stream append only to disk, but the end, the compiler produces the final `FSTMetadata` which must then be stored somewhere? ########## lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java: ########## @@ -828,6 +829,26 @@ public void add(IntsRef input, T output) throws IOException { lastInput.copyInts(input); } + void setEmptyOutput(T v) { + if (fst.metadata.emptyOutput != null) { + fst.metadata.emptyOutput = fst.outputs.merge(fst.metadata.emptyOutput, v); Review Comment: Ahh OK `emptyOutput` cannot be final! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org