Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ public void compileIndex(
.suffixRAMLimitMB(0d)
.dataOutput(getOnHeapReaderWriter(pageBits))
.setVersion(fstVersion)
.setInitLength(prefix.length + 1)
.build();
// if (DEBUG) {
// System.out.println(" compile index for prefix=" + prefix);
Expand Down
14 changes: 11 additions & 3 deletions lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ private FSTCompiler(
boolean allowFixedLengthArcs,
DataOutput dataOutput,
float directAddressingMaxOversizingFactor,
int version) {
int version,
int initLength) {
this.allowFixedLengthArcs = allowFixedLengthArcs;
this.directAddressingMaxOversizingFactor = directAddressingMaxOversizingFactor;
this.version = version;
Expand All @@ -185,7 +186,7 @@ private FSTCompiler(
NO_OUTPUT = outputs.getNoOutput();

@SuppressWarnings({"rawtypes", "unchecked"})
final UnCompiledNode<T>[] f = (UnCompiledNode<T>[]) new UnCompiledNode[10];
final UnCompiledNode<T>[] f = (UnCompiledNode<T>[]) new UnCompiledNode[initLength];
frontier = f;
for (int idx = 0; idx < frontier.length; idx++) {
frontier[idx] = new UnCompiledNode<>(this, idx);
Expand Down Expand Up @@ -247,6 +248,7 @@ public static class Builder<T> {
private DataOutput dataOutput;
private float directAddressingMaxOversizingFactor = DIRECT_ADDRESSING_MAX_OVERSIZING_FACTOR;
private int version = FST.VERSION_CURRENT;
private int initLength = 10;

/**
* @param inputType The input type (transition labels). Can be anything from {@link INPUT_TYPE}
Expand Down Expand Up @@ -346,6 +348,11 @@ public Builder<T> setVersion(int version) {
return this;
}

public Builder<T> setInitLength(int initLength) {
this.initLength = initLength;
return this;
}

/** Creates a new {@link FSTCompiler}. */
public FSTCompiler<T> build() {
// create a default DataOutput if not specified
Expand All @@ -359,7 +366,8 @@ public FSTCompiler<T> build() {
allowFixedLengthArcs,
dataOutput,
directAddressingMaxOversizingFactor,
version);
version,
initLength);
}
}

Expand Down