mirror of https://github.com/apache/lucene.git
implement, correct, improve hashcodes: LUCENE-460
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@359078 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9513c471f6
commit
b374f5ffa2
|
@ -65,15 +65,13 @@ public class SpanRegexQuery extends SpanQuery {
|
|||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
if (!(o instanceof TermQuery)) return false;
|
||||
final SpanRegexQuery that = (SpanRegexQuery) o;
|
||||
|
||||
return term.equals(that.term) && getBoost() == that.getBoost();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return term.hashCode();
|
||||
return term.hashCode() ^ Float.floatToRawIntBits(getBoost()) ^ 0x4BCEF3A9;
|
||||
}
|
||||
|
||||
public String toString(String field) {
|
||||
|
|
|
@ -105,4 +105,23 @@ public class SpanFirstQuery extends SpanQuery {
|
|||
return this; // no clauses rewrote
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof SpanFirstQuery)) return false;
|
||||
|
||||
SpanFirstQuery other = (SpanFirstQuery)o;
|
||||
return this.end == other.end
|
||||
&& this.match.equals(other.match)
|
||||
&& this.getBoost() == other.getBoost();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int h = match.hashCode();
|
||||
h ^= (h << 8) | (h >>> 25); // reversible
|
||||
h ^= Float.floatToRawIntBits(getBoost()) ^ end;
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -134,14 +134,13 @@ public class SpanNearQuery extends SpanQuery {
|
|||
/** Returns true iff <code>o</code> is equal to this. */
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!(o instanceof SpanNearQuery)) return false;
|
||||
|
||||
final SpanNearQuery spanNearQuery = (SpanNearQuery) o;
|
||||
|
||||
if (inOrder != spanNearQuery.inOrder) return false;
|
||||
if (slop != spanNearQuery.slop) return false;
|
||||
if (!clauses.equals(spanNearQuery.clauses)) return false;
|
||||
if (!field.equals(spanNearQuery.field)) return false;
|
||||
|
||||
return getBoost() == spanNearQuery.getBoost();
|
||||
}
|
||||
|
@ -149,9 +148,13 @@ public class SpanNearQuery extends SpanQuery {
|
|||
public int hashCode() {
|
||||
int result;
|
||||
result = clauses.hashCode();
|
||||
result += slop * 29;
|
||||
result += (inOrder ? 1 : 0);
|
||||
result ^= field.hashCode();
|
||||
// Mix bits before folding in things like boost, since it could cancel the
|
||||
// last element of clauses. This particular mix also serves to
|
||||
// differentiate SpanNearQuery hashcodes from others.
|
||||
result ^= (result << 14) | (result >>> 19); // reversible
|
||||
result += Float.floatToRawIntBits(getBoost());
|
||||
result += slop;
|
||||
result ^= (inOrder ? 0x99AFD3BD : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,4 +151,24 @@ public class SpanNotQuery extends SpanQuery {
|
|||
}
|
||||
}
|
||||
|
||||
/** Returns true iff <code>o</code> is equal to this. */
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof SpanNotQuery)) return false;
|
||||
|
||||
SpanNotQuery other = (SpanNotQuery)o;
|
||||
return this.include.equals(other.include)
|
||||
&& this.exclude.equals(other.exclude)
|
||||
&& this.getBoost() == other.getBoost();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int h = include.hashCode();
|
||||
h = (h<<1) | (h >>> 31); // rotate left
|
||||
h ^= include.hashCode();
|
||||
h = (h<<1) | (h >>> 31); // rotate left
|
||||
h ^= Float.floatToRawIntBits(getBoost());
|
||||
return h;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -113,10 +113,10 @@ public class SpanOrQuery extends SpanQuery {
|
|||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = clauses.hashCode();
|
||||
result = 29 * result + field.hashCode();
|
||||
return result;
|
||||
int h = clauses.hashCode();
|
||||
h ^= (h << 10) | (h >>> 23);
|
||||
h ^= Float.floatToRawIntBits(getBoost());
|
||||
return h;
|
||||
}
|
||||
|
||||
private class SpanQueue extends PriorityQueue {
|
||||
|
|
|
@ -72,7 +72,7 @@ public class TestBasics extends TestCase {
|
|||
578, 579, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 770, 771,
|
||||
772, 773, 774, 775, 776, 777, 778, 779, 870, 871, 872, 873, 874, 875,
|
||||
876, 877, 878, 879, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979});
|
||||
}
|
||||
}
|
||||
|
||||
public void testTerm2() throws Exception {
|
||||
Query query = new TermQuery(new Term("field", "seventish"));
|
||||
|
@ -120,6 +120,10 @@ public class TestBasics extends TestCase {
|
|||
|
||||
assertTrue(searcher.explain(query, 77).getValue() > 0.0f);
|
||||
assertTrue(searcher.explain(query, 977).getValue() > 0.0f);
|
||||
|
||||
QueryUtils.check(term1);
|
||||
QueryUtils.check(term2);
|
||||
QueryUtils.checkUnequal(term1,term2);
|
||||
}
|
||||
|
||||
public void testSpanNearUnordered() throws Exception {
|
||||
|
@ -264,5 +268,6 @@ public class TestBasics extends TestCase {
|
|||
|
||||
private void checkHits(Query query, int[] results) throws IOException {
|
||||
CheckHits.checkHits(query, "field", searcher, results);
|
||||
QueryUtils.check(query);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue