From c0c5b9c2f058553721b2800dc6242eab4fab8525 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Fri, 27 Nov 2009 21:48:39 +0000 Subject: [PATCH] LUCENE-2075: fix false trip in assert, when comparing two TermInfos git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@885028 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/TermInfo.java | 22 ------------------ .../apache/lucene/index/TermInfosReader.java | 23 +++++++++++++++++-- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/java/org/apache/lucene/index/TermInfo.java b/src/java/org/apache/lucene/index/TermInfo.java index 5fd0b920bbb..475bb09175d 100644 --- a/src/java/org/apache/lucene/index/TermInfo.java +++ b/src/java/org/apache/lucene/index/TermInfo.java @@ -42,28 +42,6 @@ class TermInfo { skipOffset = ti.skipOffset; } - public boolean equals(Object obj) { - if (obj instanceof TermInfo) { - TermInfo other = (TermInfo) obj; - return other.docFreq == docFreq && - other.freqPointer == freqPointer && - other.proxPointer == proxPointer && - other.skipOffset == skipOffset; - } else { - return false; - } - } - - public int hashCode() { - final int PRIME = 17; - int result = 1; - result = PRIME * result + docFreq; - result = (int) (PRIME * result + freqPointer); - result = (int) (PRIME * result + proxPointer); - result = (int) (PRIME * result + skipOffset); - return result; - } - final void set(int docFreq, long freqPointer, long proxPointer, int skipOffset) { this.docFreq = docFreq; diff --git a/src/java/org/apache/lucene/index/TermInfosReader.java b/src/java/org/apache/lucene/index/TermInfosReader.java index 7d90f308c36..4013f511913 100644 --- a/src/java/org/apache/lucene/index/TermInfosReader.java +++ b/src/java/org/apache/lucene/index/TermInfosReader.java @@ -223,7 +223,7 @@ final class TermInfosReader { if (tiOrd == null) { termsCache.put(term, new TermInfoAndOrd(ti, (int) enumerator.position)); } else { - assert ti.equals(tiOrd); + assert sameTermInfo(ti, tiOrd, enumerator); assert (int) enumerator.position == tiOrd.termOrd; } } @@ -252,7 +252,7 @@ final class TermInfosReader { if (tiOrd == null) { termsCache.put(term, new TermInfoAndOrd(ti, (int) enumerator.position)); } else { - assert ti.equals(tiOrd); + assert sameTermInfo(ti, tiOrd, enumerator); assert (int) enumerator.position == tiOrd.termOrd; } } else { @@ -261,6 +261,25 @@ final class TermInfosReader { return ti; } + // called only from asserts + private final boolean sameTermInfo(TermInfo ti1, TermInfo ti2, SegmentTermEnum enumerator) { + if (ti1.docFreq != ti2.docFreq) { + return false; + } + if (ti1.freqPointer != ti2.freqPointer) { + return false; + } + if (ti1.proxPointer != ti2.proxPointer) { + return false; + } + // skipOffset is only valid when docFreq >= skipInterval: + if (ti1.docFreq >= enumerator.skipInterval && + ti1.skipOffset != ti2.skipOffset) { + return false; + } + return true; + } + /** Returns the nth term in the set. */ final Term get(int position) throws IOException { if (size == 0) return null;