Lucene.Net.Core.Search.Spans.SpanOrQuery: Changed clauses from IList<SpanQuery> to ValueList<SpanQuery> to ensure Equals() and GetHashCode() consider all clauses when comparing.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/fc22adbb Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/fc22adbb Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/fc22adbb Branch: refs/heads/api-work Commit: fc22adbbb16c651eb91ca1b767f9b2a424f98400 Parents: beab698 Author: Shad Storhaug <[email protected]> Authored: Thu Mar 2 00:15:17 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Mar 2 08:08:52 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Search/Spans/SpanOrQuery.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fc22adbb/src/Lucene.Net.Core/Search/Spans/SpanOrQuery.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Search/Spans/SpanOrQuery.cs b/src/Lucene.Net.Core/Search/Spans/SpanOrQuery.cs index 5e1e005..886e8ab 100644 --- a/src/Lucene.Net.Core/Search/Spans/SpanOrQuery.cs +++ b/src/Lucene.Net.Core/Search/Spans/SpanOrQuery.cs @@ -33,7 +33,9 @@ namespace Lucene.Net.Search.Spans /// Matches the union of its clauses. </summary> public class SpanOrQuery : SpanQuery { - private readonly IList<SpanQuery> clauses; + // LUCENENET NOTE: The hash code needs to be made from the hash codes of all elements. + // So, we force all subclasses to use ValueList<SpanQuery> instead of IList<SpanQuery> to ensure that logic is in place. + private readonly ValueList<SpanQuery> clauses; private string field; /// <summary> @@ -41,7 +43,7 @@ namespace Lucene.Net.Search.Spans public SpanOrQuery(params SpanQuery[] clauses) { // copy clauses array into an ArrayList - this.clauses = new List<SpanQuery>(clauses.Length); + this.clauses = new ValueList<SpanQuery>(clauses.Length); for (int i = 0; i < clauses.Length; i++) { AddClause(clauses[i]); @@ -157,7 +159,7 @@ namespace Lucene.Net.Search.Spans SpanOrQuery that = (SpanOrQuery)o; - if (!clauses.SequenceEqual(that.clauses)) + if (!clauses.Equals(that.clauses)) { return false; } @@ -168,7 +170,7 @@ namespace Lucene.Net.Search.Spans public override int GetHashCode() { //If this doesn't work, hash all elemnts together instead. This version was used to reduce time complexity - int h = clauses.Count == 0 ? 0 : HashHelpers.CombineHashCodes(clauses.First().GetHashCode(), clauses.Last().GetHashCode(), clauses.Count); + int h = clauses.GetHashCode(); h ^= (h << 10) | ((int)(((uint)h) >> 23)); h ^= Number.SingleToRawInt32Bits(Boost); return h;
