From e70b4f394fa9368ac51413e251c0256d2f0902b8 Mon Sep 17 00:00:00 2001 From: Han Jiang Date: Tue, 16 Jul 2013 16:18:04 +0000 Subject: [PATCH] LUCENE-3069: remove some nocommits, update hashCode() & equal() git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3069@1503781 13f79535-47bb-0310-9956-ffa450edef68 --- .../codecs/temp/TempFSTTermsReader.java | 6 +-- .../codecs/temp/TempFSTTermsWriter.java | 1 - .../lucene/codecs/temp/TempTermOutputs.java | 40 +++++++++++++++---- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsReader.java index 0b40f825f00..feefa860f6d 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsReader.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsReader.java @@ -317,9 +317,8 @@ public class TempFSTTermsReader extends FieldsProducer { public BytesRef next() throws IOException { if (seekPending) { // previously positioned, but termOutputs not fetched seekPending = false; - if (seekCeil(term, false) != SeekStatus.FOUND) { - return term; - } + SeekStatus status = seekCeil(term, false); + assert status == SeekStatus.FOUND; // must positioned on valid term } updateEnum(fstEnum.next()); return term; @@ -331,7 +330,6 @@ public class TempFSTTermsReader extends FieldsProducer { return term != null; } - // nocommit: when will we useCache? @Override public SeekStatus seekCeil(final BytesRef target, final boolean useCache) throws IOException { updateEnum(fstEnum.seekCeil(target)); diff --git a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsWriter.java index 55947be2810..b24ac0b38f9 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsWriter.java @@ -64,7 +64,6 @@ public class TempFSTTermsWriter extends FieldsConsumer { this.fieldInfos = state.fieldInfos; this.out = state.directory.createOutput(termsFileName, state.context); - // nocommit: why try catch here? not catching createOutput? boolean success = false; try { writeHeader(out); diff --git a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempTermOutputs.java b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempTermOutputs.java index 6d3419fef8b..fdcfa483c5e 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempTermOutputs.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempTermOutputs.java @@ -29,14 +29,13 @@ import org.apache.lucene.store.DataOutput; import org.apache.lucene.util.fst.Outputs; import org.apache.lucene.util.LongsRef; - // NOTE: outputs should be per-field, since // longsSize is fixed for each field public class TempTermOutputs extends Outputs { private final static TempMetaData NO_OUTPUT = new TempMetaData(); private static boolean DEBUG = false; - private boolean hasPos; - private int longsSize; + private final boolean hasPos; + private final int longsSize; public static class TempMetaData { long[] longs; @@ -55,6 +54,10 @@ public class TempTermOutputs extends Outputs { this.docFreq = docFreq; this.totalTermFreq = totalTermFreq; } + + // NOTE: actually, FST nodes are seldom + // identical when outputs on their arcs + // aren't NO_OUTPUTs. @Override public int hashCode() { int hash = 0; @@ -71,8 +74,23 @@ public class TempTermOutputs extends Outputs { hash += bytes[i]; } } + hash += docFreq + totalTermFreq; return hash; } + + @Override + public boolean equals(Object other_) { + if (other_ == this) { + return true; + } else if (!(other_ instanceof TempTermOutputs.TempMetaData)) { + return false; + } + TempMetaData other = (TempMetaData) other_; + return statsEqual(this, other) && + longsEqual(this, other) && + bytesEqual(this, other); + + } public String toString() { if (this == NO_OUTPUT) { return "no_output"; @@ -102,9 +120,6 @@ public class TempTermOutputs extends Outputs { } } - private TempTermOutputs() { - } - protected TempTermOutputs(FieldInfo fieldInfo, int longsSize) { this.hasPos = (fieldInfo.getIndexOptions() != IndexOptions.DOCS_ONLY); this.longsSize = longsSize; @@ -149,7 +164,7 @@ public class TempTermOutputs extends Outputs { ret = new TempMetaData(min, null, 0, -1); } } else { // equal long[] - if (statsEqual(t1, t2) && (t1.bytes == null || bytesEqual(t1, t2))) { + if (statsEqual(t1, t2) && bytesEqual(t1, t2)) { ret = t1; } else if (allZero(min)) { ret = NO_OUTPUT; @@ -310,7 +325,16 @@ public class TempTermOutputs extends Outputs { return t1.docFreq == t2.docFreq && t1.totalTermFreq == t2.totalTermFreq; } static boolean bytesEqual(final TempMetaData t1, final TempMetaData t2) { - return Arrays.equals(t1.bytes, t2.bytes); + if (t1.bytes == null && t2.bytes == null) { + return true; + } + return t1.bytes != null && t2.bytes !=null && Arrays.equals(t1.bytes, t2.bytes); + } + static boolean longsEqual(final TempMetaData t1, final TempMetaData t2) { + if (t1.longs == null && t2.longs == null) { + return true; + } + return t1.longs != null && t2.longs !=null && Arrays.equals(t1.longs, t2.longs); } static boolean allZero(final long[] l) { for (int i = 0; i < l.length; i++) {