Skip to content

Commit 196800c

Browse files
dungba88mikemccand
authored andcommitted
Remove direct dependency of NodeHash to FST (#12690)
* Remove direct dependency of NodeHash to FST * tidy
1 parent 2ca906d commit 196800c

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private FSTCompiler(
143143
if (suffixRAMLimitMB < 0) {
144144
throw new IllegalArgumentException("ramLimitMB must be >= 0; got: " + suffixRAMLimitMB);
145145
} else if (suffixRAMLimitMB > 0) {
146-
dedupHash = new NodeHash<>(fst, suffixRAMLimitMB, bytes.getReverseReader(false));
146+
dedupHash = new NodeHash<>(this, suffixRAMLimitMB, bytes.getReverseReader(false));
147147
} else {
148148
dedupHash = null;
149149
}
@@ -293,7 +293,7 @@ private CompiledNode compileNode(UnCompiledNode<T> nodeIn, int tailLength) throw
293293
node = addNode(nodeIn);
294294
lastFrozenNode = node;
295295
} else {
296-
node = dedupHash.add(this, nodeIn);
296+
node = dedupHash.add(nodeIn);
297297
}
298298
} else {
299299
node = addNode(nodeIn);

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class NodeHash<T> {
4747
// (compared to e.g. LinkedHashMap) LRU behaviour. fallbackTable is read-only.
4848
private PagedGrowableHash fallbackTable;
4949

50-
private final FST<T> fst;
50+
private final FSTCompiler<T> fstCompiler;
5151
private final FST.Arc<T> scratchArc = new FST.Arc<>();
5252
private final FST.BytesReader in;
5353

@@ -56,7 +56,7 @@ final class NodeHash<T> {
5656
* recently used suffixes are discarded, and the FST is no longer minimalI. Still, larger
5757
* ramLimitMB will make the FST smaller (closer to minimal).
5858
*/
59-
public NodeHash(FST<T> fst, double ramLimitMB, FST.BytesReader in) {
59+
public NodeHash(FSTCompiler<T> fstCompiler, double ramLimitMB, FST.BytesReader in) {
6060
if (ramLimitMB <= 0) {
6161
throw new IllegalArgumentException("ramLimitMB must be > 0; got: " + ramLimitMB);
6262
}
@@ -69,7 +69,7 @@ public NodeHash(FST<T> fst, double ramLimitMB, FST.BytesReader in) {
6969
}
7070

7171
primaryTable = new PagedGrowableHash();
72-
this.fst = fst;
72+
this.fstCompiler = fstCompiler;
7373
this.in = in;
7474
}
7575

@@ -95,8 +95,7 @@ private long getFallback(FSTCompiler.UnCompiledNode<T> nodeIn, long hash) throws
9595
}
9696
}
9797

98-
public long add(FSTCompiler<T> fstCompiler, FSTCompiler.UnCompiledNode<T> nodeIn)
99-
throws IOException {
98+
public long add(FSTCompiler.UnCompiledNode<T> nodeIn) throws IOException {
10099

101100
long hash = hash(nodeIn);
102101

@@ -193,7 +192,7 @@ private long hash(long node) throws IOException {
193192
final int PRIME = 31;
194193

195194
long h = 0;
196-
fst.readFirstRealTargetArc(node, scratchArc, in);
195+
fstCompiler.fst.readFirstRealTargetArc(node, scratchArc, in);
197196
while (true) {
198197
h = PRIME * h + scratchArc.label();
199198
h = PRIME * h + (int) (scratchArc.target() ^ (scratchArc.target() >> 32));
@@ -205,7 +204,7 @@ private long hash(long node) throws IOException {
205204
if (scratchArc.isLast()) {
206205
break;
207206
}
208-
fst.readNextRealArc(scratchArc, in);
207+
fstCompiler.fst.readNextRealArc(scratchArc, in);
209208
}
210209

211210
return h;
@@ -216,7 +215,7 @@ private long hash(long node) throws IOException {
216215
* returning true if they are equal.
217216
*/
218217
private boolean nodesEqual(FSTCompiler.UnCompiledNode<T> node, long address) throws IOException {
219-
fst.readFirstRealTargetArc(address, scratchArc, in);
218+
fstCompiler.fst.readFirstRealTargetArc(address, scratchArc, in);
220219

221220
// fail fast for a node with fixed length arcs
222221
if (scratchArc.bytesPerArc() != 0) {
@@ -262,7 +261,7 @@ private boolean nodesEqual(FSTCompiler.UnCompiledNode<T> node, long address) thr
262261
}
263262
}
264263

265-
fst.readNextRealArc(scratchArc, in);
264+
fstCompiler.fst.readNextRealArc(scratchArc, in);
266265
}
267266

268267
// unfrozen node has fewer arcs than frozen node

0 commit comments

Comments
 (0)