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
This commit is contained in:
Han Jiang 2013-07-16 16:18:04 +00:00
parent 9bc7640fd1
commit e70b4f394f
3 changed files with 34 additions and 13 deletions

View File

@ -317,9 +317,8 @@ public class TempFSTTermsReader extends FieldsProducer {
public BytesRef next() throws IOException { public BytesRef next() throws IOException {
if (seekPending) { // previously positioned, but termOutputs not fetched if (seekPending) { // previously positioned, but termOutputs not fetched
seekPending = false; seekPending = false;
if (seekCeil(term, false) != SeekStatus.FOUND) { SeekStatus status = seekCeil(term, false);
return term; assert status == SeekStatus.FOUND; // must positioned on valid term
}
} }
updateEnum(fstEnum.next()); updateEnum(fstEnum.next());
return term; return term;
@ -331,7 +330,6 @@ public class TempFSTTermsReader extends FieldsProducer {
return term != null; return term != null;
} }
// nocommit: when will we useCache?
@Override @Override
public SeekStatus seekCeil(final BytesRef target, final boolean useCache) throws IOException { public SeekStatus seekCeil(final BytesRef target, final boolean useCache) throws IOException {
updateEnum(fstEnum.seekCeil(target)); updateEnum(fstEnum.seekCeil(target));

View File

@ -64,7 +64,6 @@ public class TempFSTTermsWriter extends FieldsConsumer {
this.fieldInfos = state.fieldInfos; this.fieldInfos = state.fieldInfos;
this.out = state.directory.createOutput(termsFileName, state.context); this.out = state.directory.createOutput(termsFileName, state.context);
// nocommit: why try catch here? not catching createOutput?
boolean success = false; boolean success = false;
try { try {
writeHeader(out); writeHeader(out);

View File

@ -29,14 +29,13 @@ import org.apache.lucene.store.DataOutput;
import org.apache.lucene.util.fst.Outputs; import org.apache.lucene.util.fst.Outputs;
import org.apache.lucene.util.LongsRef; import org.apache.lucene.util.LongsRef;
// NOTE: outputs should be per-field, since // NOTE: outputs should be per-field, since
// longsSize is fixed for each field // longsSize is fixed for each field
public class TempTermOutputs extends Outputs<TempTermOutputs.TempMetaData> { public class TempTermOutputs extends Outputs<TempTermOutputs.TempMetaData> {
private final static TempMetaData NO_OUTPUT = new TempMetaData(); private final static TempMetaData NO_OUTPUT = new TempMetaData();
private static boolean DEBUG = false; private static boolean DEBUG = false;
private boolean hasPos; private final boolean hasPos;
private int longsSize; private final int longsSize;
public static class TempMetaData { public static class TempMetaData {
long[] longs; long[] longs;
@ -55,6 +54,10 @@ public class TempTermOutputs extends Outputs<TempTermOutputs.TempMetaData> {
this.docFreq = docFreq; this.docFreq = docFreq;
this.totalTermFreq = totalTermFreq; this.totalTermFreq = totalTermFreq;
} }
// NOTE: actually, FST nodes are seldom
// identical when outputs on their arcs
// aren't NO_OUTPUTs.
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 0; int hash = 0;
@ -71,8 +74,23 @@ public class TempTermOutputs extends Outputs<TempTermOutputs.TempMetaData> {
hash += bytes[i]; hash += bytes[i];
} }
} }
hash += docFreq + totalTermFreq;
return hash; 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() { public String toString() {
if (this == NO_OUTPUT) { if (this == NO_OUTPUT) {
return "no_output"; return "no_output";
@ -102,9 +120,6 @@ public class TempTermOutputs extends Outputs<TempTermOutputs.TempMetaData> {
} }
} }
private TempTermOutputs() {
}
protected TempTermOutputs(FieldInfo fieldInfo, int longsSize) { protected TempTermOutputs(FieldInfo fieldInfo, int longsSize) {
this.hasPos = (fieldInfo.getIndexOptions() != IndexOptions.DOCS_ONLY); this.hasPos = (fieldInfo.getIndexOptions() != IndexOptions.DOCS_ONLY);
this.longsSize = longsSize; this.longsSize = longsSize;
@ -149,7 +164,7 @@ public class TempTermOutputs extends Outputs<TempTermOutputs.TempMetaData> {
ret = new TempMetaData(min, null, 0, -1); ret = new TempMetaData(min, null, 0, -1);
} }
} else { // equal long[] } else { // equal long[]
if (statsEqual(t1, t2) && (t1.bytes == null || bytesEqual(t1, t2))) { if (statsEqual(t1, t2) && bytesEqual(t1, t2)) {
ret = t1; ret = t1;
} else if (allZero(min)) { } else if (allZero(min)) {
ret = NO_OUTPUT; ret = NO_OUTPUT;
@ -310,7 +325,16 @@ public class TempTermOutputs extends Outputs<TempTermOutputs.TempMetaData> {
return t1.docFreq == t2.docFreq && t1.totalTermFreq == t2.totalTermFreq; return t1.docFreq == t2.docFreq && t1.totalTermFreq == t2.totalTermFreq;
} }
static boolean bytesEqual(final TempMetaData t1, final TempMetaData t2) { 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) { static boolean allZero(final long[] l) {
for (int i = 0; i < l.length; i++) { for (int i = 0; i < l.length; i++) {