diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/Builder.java b/lucene/core/src/java/org/apache/lucene/util/fst/Builder.java index 19ee5412943..812b3e74706 100644 --- a/lucene/core/src/java/org/apache/lucene/util/fst/Builder.java +++ b/lucene/core/src/java/org/apache/lucene/util/fst/Builder.java @@ -160,7 +160,7 @@ public class Builder { this.acceptableOverheadRatio = acceptableOverheadRatio; fst = new FST(inputType, outputs, doPackFST, acceptableOverheadRatio, allowArrayArcs); if (doShareSuffix) { - dedupHash = new NodeHash(fst); + dedupHash = new NodeHash(fst, fst.bytes.getReverseReader(false)); } else { dedupHash = null; } diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java b/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java index 1c4415fd9d7..6a3d104d178 100644 --- a/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java +++ b/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java @@ -374,7 +374,11 @@ class BytesStore extends DataOutput { } public FST.BytesReader getReverseReader() { - if (blocks.size() == 1) { + return getReverseReader(true); + } + + FST.BytesReader getReverseReader(boolean allowSingle) { + if (allowSingle && blocks.size() == 1) { return new ReverseBytesReader(blocks.get(0)); } return new FST.BytesReader() { diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/FST.java b/lucene/core/src/java/org/apache/lucene/util/fst/FST.java index a47398fe22c..54a9ec3643c 100644 --- a/lucene/core/src/java/org/apache/lucene/util/fst/FST.java +++ b/lucene/core/src/java/org/apache/lucene/util/fst/FST.java @@ -146,7 +146,7 @@ public final class FST { // produces this output T emptyOutput; - private final BytesStore bytes; + final BytesStore bytes; private int startNode = -1; diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/NodeHash.java b/lucene/core/src/java/org/apache/lucene/util/fst/NodeHash.java index 3c01dfc0ea2..d469288ef71 100644 --- a/lucene/core/src/java/org/apache/lucene/util/fst/NodeHash.java +++ b/lucene/core/src/java/org/apache/lucene/util/fst/NodeHash.java @@ -27,14 +27,16 @@ final class NodeHash { private int mask; private final FST fst; private final FST.Arc scratchArc = new FST.Arc(); + private final FST.BytesReader in; - public NodeHash(FST fst) { + public NodeHash(FST fst, FST.BytesReader in) { table = new int[16]; mask = 15; this.fst = fst; + this.in = in; } - private boolean nodesEqual(Builder.UnCompiledNode node, int address, FST.BytesReader in) throws IOException { + private boolean nodesEqual(Builder.UnCompiledNode node, int address) throws IOException { fst.readFirstRealTargetArc(address, scratchArc, in); if (scratchArc.bytesPerArc != 0 && node.numArcs != scratchArc.numArcs) { return false; @@ -87,7 +89,6 @@ final class NodeHash { // hash code for a frozen node private int hash(int node) throws IOException { final int PRIME = 31; - final FST.BytesReader in = fst.getBytesReader(0); //System.out.println("hash frozen node=" + node); int h = 0; fst.readFirstRealTargetArc(node, scratchArc, in); @@ -111,7 +112,6 @@ final class NodeHash { public int add(Builder.UnCompiledNode nodeIn) throws IOException { // System.out.println("hash: add count=" + count + " vs " + table.length); - final FST.BytesReader in = fst.getBytesReader(0); final int h = hash(nodeIn); int pos = h & mask; int c = 0; @@ -128,7 +128,7 @@ final class NodeHash { rehash(); } return node; - } else if (nodesEqual(nodeIn, v, in)) { + } else if (nodesEqual(nodeIn, v)) { // same node is already here return v; }