reuse a single BytesReader in NodeHash

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1432474 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2013-01-12 17:01:56 +00:00
parent 60b19f2da9
commit f30dd532ec
4 changed files with 12 additions and 8 deletions

View File

@ -160,7 +160,7 @@ public class Builder<T> {
this.acceptableOverheadRatio = acceptableOverheadRatio;
fst = new FST<T>(inputType, outputs, doPackFST, acceptableOverheadRatio, allowArrayArcs);
if (doShareSuffix) {
dedupHash = new NodeHash<T>(fst);
dedupHash = new NodeHash<T>(fst, fst.bytes.getReverseReader(false));
} else {
dedupHash = null;
}

View File

@ -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() {

View File

@ -146,7 +146,7 @@ public final class FST<T> {
// produces this output
T emptyOutput;
private final BytesStore bytes;
final BytesStore bytes;
private int startNode = -1;

View File

@ -27,14 +27,16 @@ final class NodeHash<T> {
private int mask;
private final FST<T> fst;
private final FST.Arc<T> scratchArc = new FST.Arc<T>();
private final FST.BytesReader in;
public NodeHash(FST<T> fst) {
public NodeHash(FST<T> fst, FST.BytesReader in) {
table = new int[16];
mask = 15;
this.fst = fst;
this.in = in;
}
private boolean nodesEqual(Builder.UnCompiledNode<T> node, int address, FST.BytesReader in) throws IOException {
private boolean nodesEqual(Builder.UnCompiledNode<T> 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<T> {
// 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<T> {
public int add(Builder.UnCompiledNode<T> 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<T> {
rehash();
}
return node;
} else if (nodesEqual(nodeIn, v, in)) {
} else if (nodesEqual(nodeIn, v)) {
// same node is already here
return v;
}