diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs index 8ae425af4e..8b119acc76 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs @@ -277,12 +277,15 @@ public override int GetHashCode() return 1303507063; } - int h = 1; - h = 31 * h + pattern.ToString().GetHashCode(); - h = 31 * h + (int)pattern.Options; - h = 31 * h + (toLowerCase ? 1231 : 1237); - h = 31 * h + (stopWords != null ? stopWords.GetHashCode() : 0); - return h; + unchecked + { + int h = 1; + h = 31 * h + pattern.ToString().GetHashCode(); + h = 31 * h + (int)pattern.Options; + h = 31 * h + (toLowerCase ? 1231 : 1237); + h = 31 * h + (stopWords != null ? stopWords.GetHashCode() : 0); + return h; + } } /// diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayMap.cs b/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayMap.cs index d5c6d9a655..5e03aff805 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayMap.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayMap.cs @@ -1800,18 +1800,23 @@ public override bool Equals(object? obj) /// public override int GetHashCode() { - const int PRIME = 31; // arbitrary prime - int hash = PRIME; - using (var iter = GetEnumerator()) + unchecked { - while (iter.MoveNext()) + const int PRIME = 31; // arbitrary prime + int hash = PRIME; + using (var iter = GetEnumerator()) { - hash = (hash * PRIME) ^ iter.CurrentKeyString.GetHashCode(); - TValue? value = iter.CurrentValue; - hash = (hash * PRIME) ^ (value is null ? 0 : JCG.EqualityComparer.Default.GetHashCode(value)); + while (iter.MoveNext()) + { + hash = (hash * PRIME) ^ iter.CurrentKeyString.GetHashCode(); + TValue? value = iter.CurrentValue; + hash = (hash * PRIME) ^ + (value is null ? 0 : JCG.EqualityComparer.Default.GetHashCode(value)); + } } + + return hash; } - return hash; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1832,16 +1837,22 @@ private int GetHashCode(char[] text, int startIndex, int length) { for (int i = startIndex; i < stop;) { - int codePointAt = charUtils.CodePointAt(text, i, stop); - code = code * 31 + Character.ToLower(codePointAt, CultureInfo.InvariantCulture); // LUCENENET specific - need to use invariant culture to match Java - i += Character.CharCount(codePointAt); + unchecked + { + int codePointAt = charUtils.CodePointAt(text, i, stop); + code = code * 31 + Character.ToLower(codePointAt, CultureInfo.InvariantCulture); // LUCENENET specific - need to use invariant culture to match Java + i += Character.CharCount(codePointAt); + } } } else { for (int i = startIndex; i < stop; i++) { - code = code * 31 + text[i]; + unchecked + { + code = code * 31 + text[i]; + } } } return code; @@ -1859,16 +1870,22 @@ private int GetHashCode(ICharSequence text) { for (int i = 0; i < length;) { - int codePointAt = charUtils.CodePointAt(text, i); - code = code * 31 + Character.ToLower(codePointAt, CultureInfo.InvariantCulture); // LUCENENET specific - need to use invariant culture to match Java - i += Character.CharCount(codePointAt); + unchecked + { + int codePointAt = charUtils.CodePointAt(text, i); + code = code * 31 + Character.ToLower(codePointAt, CultureInfo.InvariantCulture); // LUCENENET specific - need to use invariant culture to match Java + i += Character.CharCount(codePointAt); + } } } else { for (int i = 0; i < length; i++) { - code = code * 31 + text[i]; + unchecked + { + code = code * 31 + text[i]; + } } } return code; @@ -1886,16 +1903,22 @@ private int GetHashCode(string text) { for (int i = 0; i < length;) { - int codePointAt = charUtils.CodePointAt(text, i); - code = code * 31 + Character.ToLower(codePointAt, CultureInfo.InvariantCulture); // LUCENENET specific - need to use invariant culture to match Java - i += Character.CharCount(codePointAt); + unchecked + { + int codePointAt = charUtils.CodePointAt(text, i); + code = code * 31 + Character.ToLower(codePointAt, CultureInfo.InvariantCulture); // LUCENENET specific - need to use invariant culture to match Java + i += Character.CharCount(codePointAt); + } } } else { for (int i = 0; i < length; i++) { - code = code * 31 + text[i]; + unchecked + { + code = code * 31 + text[i]; + } } } return code; diff --git a/src/Lucene.Net.Analysis.SmartCn/Hhmm/PathNode.cs b/src/Lucene.Net.Analysis.SmartCn/Hhmm/PathNode.cs index 35d7aa1996..0a14b3de2a 100644 --- a/src/Lucene.Net.Analysis.SmartCn/Hhmm/PathNode.cs +++ b/src/Lucene.Net.Analysis.SmartCn/Hhmm/PathNode.cs @@ -48,13 +48,16 @@ public virtual int CompareTo(PathNode pn) /// public override int GetHashCode() { - int prime = 31; - int result = 1; - result = prime * result + PreNode; - long temp; - temp = J2N.BitConversion.DoubleToInt64Bits(Weight); - result = prime * result + (int)(temp ^ (temp >>> 32)); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + PreNode; + long temp; + temp = J2N.BitConversion.DoubleToInt64Bits(Weight); + result = prime * result + (int)(temp ^ (temp >>> 32)); + return result; + } } /// diff --git a/src/Lucene.Net.Analysis.SmartCn/Hhmm/SegToken.cs b/src/Lucene.Net.Analysis.SmartCn/Hhmm/SegToken.cs index 35f27e0f0e..9a0baf46ad 100644 --- a/src/Lucene.Net.Analysis.SmartCn/Hhmm/SegToken.cs +++ b/src/Lucene.Net.Analysis.SmartCn/Hhmm/SegToken.cs @@ -83,18 +83,21 @@ public SegToken(char[] idArray, int start, int end, WordType wordType, int weigh /// public override int GetHashCode() { - int prime = 31; - int result = 1; - for (int i = 0; i < CharArray.Length; i++) + unchecked { - result = prime * result + CharArray[i]; + const int prime = 31; + int result = 1; + for (int i = 0; i < CharArray.Length; i++) + { + result = prime * result + CharArray[i]; + } + result = prime * result + EndOffset; + result = prime * result + Index; + result = prime * result + StartOffset; + result = prime * result + Weight; + result = prime * result + (int)WordType; + return result; } - result = prime * result + EndOffset; - result = prime * result + Index; - result = prime * result + StartOffset; - result = prime * result + Weight; - result = prime * result + (int)WordType; - return result; } /// diff --git a/src/Lucene.Net.Analysis.SmartCn/Hhmm/SegTokenPair.cs b/src/Lucene.Net.Analysis.SmartCn/Hhmm/SegTokenPair.cs index 4365b7e9c5..3f3d7cabe7 100644 --- a/src/Lucene.Net.Analysis.SmartCn/Hhmm/SegTokenPair.cs +++ b/src/Lucene.Net.Analysis.SmartCn/Hhmm/SegTokenPair.cs @@ -55,18 +55,21 @@ public SegTokenPair(char[] idArray, int from, int to, double weight) /// public override int GetHashCode() { - int prime = 31; - int result = 1; - for (int i = 0; i < CharArray.Length; i++) + unchecked { - result = prime * result + CharArray[i]; + const int prime = 31; + int result = 1; + for (int i = 0; i < CharArray.Length; i++) + { + result = prime * result + CharArray[i]; + } + result = prime * result + From; + result = prime * result + To; + long temp; + temp = J2N.BitConversion.DoubleToInt64Bits(Weight); + result = prime * result + (int)(temp ^ (temp >>> 32)); + return result; } - result = prime * result + From; - result = prime * result + To; - long temp; - temp = J2N.BitConversion.DoubleToInt64Bits(Weight); - result = prime * result + (int)(temp ^ (temp >>> 32)); - return result; } /// diff --git a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs index c18fdbf97c..ca467e8143 100644 --- a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs +++ b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs @@ -28,7 +28,7 @@ namespace Lucene.Net.Codecs.BlockTerms /// /// Handles a terms dict, but decouples all details of - /// doc/freqs/positions reading to an instance of + /// doc/freqs/positions reading to an instance of /// . This class is reusable for /// codecs that use a different format for /// docs/freqs/positions (though codecs are also free to @@ -36,7 +36,7 @@ namespace Lucene.Net.Codecs.BlockTerms /// /// This class also interacts with an instance of /// , to abstract away the specific - /// implementation of the terms dict index. + /// implementation of the terms dict index. /// /// @lucene.experimental /// @@ -90,7 +90,10 @@ public override object Clone() public override int GetHashCode() { - return Field.GetHashCode() * 31 + Term.GetHashCode(); + unchecked + { + return Field.GetHashCode() * 31 + Term.GetHashCode(); + } } } @@ -372,7 +375,7 @@ public SegmentTermsEnum(FieldReader outerInstance) /// the terms data from that"; eg FuzzyTermsEnum will /// (usually) just immediately call seek again if we /// return NOT_FOUND so it's a waste for us to fill in - /// the term that was actually NOT_FOUND + /// the term that was actually NOT_FOUND /// public override SeekStatus SeekCeil(BytesRef target) { @@ -876,7 +879,7 @@ public override long Ord // Does initial decode of next block of terms; this // doesn't actually decode the docFreq, totalTermFreq, // postings details (frq/prx offset, etc.) metadata; - // it just loads them as byte[] blobs which are then + // it just loads them as byte[] blobs which are then // decoded on-demand if the metadata is ever requested // for any term in this block. This enables terms-only // intensive consumes (eg certain MTQs, respelling) to @@ -1014,4 +1017,4 @@ public override void CheckIntegrity() postingsReader.CheckIntegrity(); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs b/src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs index 3bf101a588..e1c158472d 100644 --- a/src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs +++ b/src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs @@ -73,26 +73,29 @@ internal TermData(long[] longs, byte[] bytes, int docFreq, long totalTermFreq) // aren't NO_OUTPUTs. public override int GetHashCode() { - var hash = 0; - if (longs != null) + unchecked { - var end = longs.Length; - for (var i = 0; i < end; i++) + var hash = 0; + if (longs != null) { - hash -= (int) longs[i]; + var end = longs.Length; + for (var i = 0; i < end; i++) + { + hash -= (int) longs[i]; + } } - } - if (bytes != null) - { - hash = -hash; - var end = bytes.Length; - for (var i = 0; i < end; i++) + if (bytes != null) { - hash += bytes[i]; + hash = -hash; + var end = bytes.Length; + for (var i = 0; i < end; i++) + { + hash += bytes[i]; + } } + hash += (int) (docFreq + totalTermFreq); + return hash; } - hash += (int) (docFreq + totalTermFreq); - return hash; } public override bool Equals(object other) diff --git a/src/Lucene.Net.Expressions/ExpressionSortField.cs b/src/Lucene.Net.Expressions/ExpressionSortField.cs index 6fba291a58..8afc33639f 100644 --- a/src/Lucene.Net.Expressions/ExpressionSortField.cs +++ b/src/Lucene.Net.Expressions/ExpressionSortField.cs @@ -27,7 +27,7 @@ internal class ExpressionSortField : SortField { private readonly ExpressionValueSource source; - internal ExpressionSortField(string name, ExpressionValueSource source, bool reverse) + internal ExpressionSortField(string name, ExpressionValueSource source, bool reverse) : base(name, SortFieldType.CUSTOM, reverse) { this.source = source; @@ -40,10 +40,13 @@ public override FieldComparer GetComparer(int numHits, int sortPos) public override int GetHashCode() { - int prime = 31; - int result = base.GetHashCode(); - result = prime * result + ((source is null) ? 0 : source.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (source is null ? 0 : source.GetHashCode()); + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.Expressions/ExpressionValueSource.cs b/src/Lucene.Net.Expressions/ExpressionValueSource.cs index ca47c9e35b..c8b02f8d90 100644 --- a/src/Lucene.Net.Expressions/ExpressionValueSource.cs +++ b/src/Lucene.Net.Expressions/ExpressionValueSource.cs @@ -120,12 +120,15 @@ public override string GetDescription() public override int GetHashCode() { - int prime = 31; - int result = 1; - result = prime * result + ((expression is null) ? 0 : expression.GetHashCode()); - result = prime * result + (needsScores ? 1231 : 1237); - result = prime * result + Arrays.GetHashCode(variables); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + (expression is null ? 0 : expression.GetHashCode()); + result = prime * result + (needsScores ? 1231 : 1237); + result = prime * result + Arrays.GetHashCode(variables); + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.Facet/DrillDownQuery.cs b/src/Lucene.Net.Facet/DrillDownQuery.cs index fecfb48988..9b300043f5 100644 --- a/src/Lucene.Net.Facet/DrillDownQuery.cs +++ b/src/Lucene.Net.Facet/DrillDownQuery.cs @@ -50,7 +50,7 @@ namespace Lucene.Net.Facet /// /// Collection initializer note: To create and populate a /// in a single statement, you can use the following example as a guide: - /// + /// /// /// var drillDownQuery = new DrillDownQuery(config) /// { @@ -129,9 +129,9 @@ internal DrillDownQuery(FacetsConfig config, Query baseQuery, IList claus } /// - /// Creates a new without a base query, + /// Creates a new without a base query, /// to perform a pure browsing query (equivalent to using - /// as base). + /// as base). /// public DrillDownQuery(FacetsConfig config) : this(config, null) @@ -142,7 +142,7 @@ public DrillDownQuery(FacetsConfig config) /// Creates a new over the given base query. Can be /// null, in which case the result from /// will be a pure browsing query, filtering on - /// the added categories only. + /// the added categories only. /// public DrillDownQuery(FacetsConfig config, Query baseQuery) { @@ -156,7 +156,7 @@ public DrillDownQuery(FacetsConfig config, Query baseQuery) /// /// Merges (ORs) a new path into an existing AND'd - /// clause. + /// clause. /// [MethodImpl(MethodImplOptions.NoInlining)] private void Merge(string dim, string[] path) @@ -188,7 +188,7 @@ private void Merge(string dim, string[] path) /// Adds one dimension of drill downs; if you pass the same /// dimension more than once it is OR'd with the previous /// cofnstraints on that dimension, and all dimensions are - /// AND'd against each other and the base query. + /// AND'd against each other and the base query. /// public void Add(string dim, params string[] path) { @@ -210,7 +210,7 @@ public void Add(string dim, params string[] path) /// /// Expert: add a custom drill-down subQuery. Use this /// when you have a separate way to drill-down on the - /// dimension than the indexed facet ordinals. + /// dimension than the indexed facet ordinals. /// public void Add(string dim, Query subQuery) { @@ -232,7 +232,7 @@ public void Add(string dim, Query subQuery) /// /// Expert: add a custom drill-down Filter, e.g. when - /// drilling down after range faceting. + /// drilling down after range faceting. /// public void Add(string dim, Filter subFilter) { @@ -281,9 +281,12 @@ public override object Clone() public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - return prime * result + query.GetHashCode(); + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + return prime * result + query.GetHashCode(); + } } public override bool Equals(object obj) @@ -406,4 +409,4 @@ public override string ToString(string field) /// IEnumerator> IEnumerable>.GetEnumerator() => drillDownDims.GetEnumerator(); } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Facet/DrillSidewaysQuery.cs b/src/Lucene.Net.Facet/DrillSidewaysQuery.cs index a66ea965dd..40c6aabead 100644 --- a/src/Lucene.Net.Facet/DrillSidewaysQuery.cs +++ b/src/Lucene.Net.Facet/DrillSidewaysQuery.cs @@ -37,7 +37,7 @@ namespace Lucene.Net.Facet /// /// Only purpose is to punch through and return a - /// + /// /// internal class DrillSidewaysQuery : Query { @@ -243,13 +243,16 @@ public override BulkScorer GetBulkScorer(AtomicReaderContext context, bool score public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + ((baseQuery is null) ? 0 : baseQuery.GetHashCode()); - result = prime * result + ((drillDownCollector is null) ? 0 : drillDownCollector.GetHashCode()); - result = prime * result + Arrays.GetHashCode(drillDownQueries); - result = prime * result + Arrays.GetHashCode(drillSidewaysCollectors); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (baseQuery is null ? 0 : baseQuery.GetHashCode()); + result = prime * result + (drillDownCollector is null ? 0 : drillDownCollector.GetHashCode()); + result = prime * result + Arrays.GetHashCode(drillDownQueries); + result = prime * result + Arrays.GetHashCode(drillSidewaysCollectors); + return result; + } } public override bool Equals(object obj) @@ -300,4 +303,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Facet/FacetResult.cs b/src/Lucene.Net.Facet/FacetResult.cs index 0293c0088b..06fbd37907 100644 --- a/src/Lucene.Net.Facet/FacetResult.cs +++ b/src/Lucene.Net.Facet/FacetResult.cs @@ -40,12 +40,12 @@ public sealed class FacetResult : IFormattable /// [WritableArray] [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")] - public string[] Path { get; private set; } + public string[] Path { get; private set; } /// /// Total value for this path (sum of all child counts, or /// sum of all child values), even those not included in - /// the topN. + /// the topN. /// public float Value { get; private set; } @@ -67,7 +67,7 @@ public sealed class FacetResult : IFormattable public Type TypeOfValue { get; private set; } /// - /// Constructor for . Makes the method + /// Constructor for . Makes the method /// print the as a with at least 1 number after the decimal. /// public FacetResult(string dim, string[] path, float value, LabelAndValue[] labelValues, int childCount) @@ -81,7 +81,7 @@ public FacetResult(string dim, string[] path, float value, LabelAndValue[] label } /// - /// Constructor for . Makes the method + /// Constructor for . Makes the method /// print the as an with no decimal. /// public FacetResult(string dim, string[] path, int value, LabelAndValue[] labelValues, int childCount) @@ -151,12 +151,15 @@ public override bool Equals(object? other) public override int GetHashCode() { - int hashCode = Value.GetHashCode() + 31 * ChildCount; - foreach (LabelAndValue labelValue in LabelValues) + unchecked { - hashCode = labelValue.GetHashCode() + 31 * hashCode; + int hashCode = Value.GetHashCode() + 31 * ChildCount; + foreach (LabelAndValue labelValue in LabelValues) + { + hashCode = labelValue.GetHashCode() + 31 * hashCode; + } + return hashCode; } - return hashCode; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Facet/LabelAndValue.cs b/src/Lucene.Net.Facet/LabelAndValue.cs index ab99a9cfdf..97951512c3 100644 --- a/src/Lucene.Net.Facet/LabelAndValue.cs +++ b/src/Lucene.Net.Facet/LabelAndValue.cs @@ -24,7 +24,7 @@ namespace Lucene.Net.Facet /// /// Single label and its value, usually contained in a - /// . + /// . /// public sealed class LabelAndValue : IFormattable { @@ -42,7 +42,7 @@ public sealed class LabelAndValue : IFormattable public Type TypeOfValue { get; private set; } /// - /// Constructor for . Makes the method + /// Constructor for . Makes the method /// print the as a with at least 1 number after the decimal. /// public LabelAndValue(string label, float value) @@ -53,7 +53,7 @@ public LabelAndValue(string label, float value) } /// - /// Constructor for . Makes the method + /// Constructor for . Makes the method /// print the as an with no decimal. /// public LabelAndValue(string label, int value) @@ -101,7 +101,10 @@ public override bool Equals(object? other) public override int GetHashCode() { - return Label.GetHashCode() + 1439 * Value.GetHashCode(); + unchecked + { + return Label.GetHashCode() + 1439 * Value.GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs index 4ef6105051..e2543ec2b2 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs @@ -29,7 +29,7 @@ namespace Lucene.Net.Facet.Taxonomy /// /// Holds a sequence of string components, specifying the hierarchical name of a /// category. - /// + /// /// @lucene.experimental /// public class CategoryPath : IComparable @@ -185,7 +185,7 @@ private static void NoDelimiter(char[] buf, int offset, int len, char delimiter) /// Copies the path components to the given , starting at index /// . is copied between the path components. /// Returns the number of chars copied. - /// + /// /// /// NOTE: this method relies on the array being large enough to hold the /// components and separators - the amount of needed space can be calculated @@ -250,7 +250,10 @@ public override int GetHashCode() int hash = Length; for (int i = 0; i < Length; i++) { - hash = hash * 31 + Components[i].GetHashCode(); + unchecked + { + hash = hash * 31 + Components[i].GetHashCode(); + } } return hash; } @@ -366,4 +369,4 @@ public virtual string ToString(char delimiter) } #endregion } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs index 97b316cbad..2f6fce09e6 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs @@ -31,7 +31,7 @@ namespace Lucene.Net.Facet.Taxonomy /// /// Holds a sequence of string components, specifying the hierarchical name of a /// category. - /// + /// /// @lucene.internal /// public class FacetLabel : IComparable @@ -174,8 +174,11 @@ public override int GetHashCode() int hash = Length; for (int i = 0; i < Length; i++) { - // LUCENENET specific: Use CharSequenceComparer to get the same value as StringCharSequence.GetHashCode() - hash = hash * 31 + CharSequenceComparer.Ordinal.GetHashCode(Components[i]); + unchecked + { + // LUCENENET specific: Use CharSequenceComparer to get the same value as StringCharSequence.GetHashCode() + hash = hash * 31 + CharSequenceComparer.Ordinal.GetHashCode(Components[i]); + } } return hash; } @@ -183,7 +186,7 @@ public override int GetHashCode() /// /// Calculate a 64-bit hash function for this path. This /// is necessary for (the - /// default cache impl for ) + /// default cache impl for ) /// to reduce the chance of "silent but deadly" collisions. /// /// NOTE: This was longHashCode() in Lucene @@ -269,4 +272,4 @@ public override string ToString() } #endregion } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs index 7a253a0bd7..6459db7808 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs @@ -599,8 +599,11 @@ internal int GetHashCode(int startIndex, int length) var chars = b.chars; for (int i = indexInBlock; i < end; i++) { - // Hash code calculation from J2N/Apache Harmony - hash = chars[i] + ((hash << 5) - hash); + unchecked + { + // Hash code calculation from J2N/Apache Harmony + hash = chars[i] + ((hash << 5) - hash); + } } remaining -= numToCheck; indexInBlock = 0; // 2nd+ iterations read from start of the block diff --git a/src/Lucene.Net.Grouping/AbstractGroupFacetCollector.cs b/src/Lucene.Net.Grouping/AbstractGroupFacetCollector.cs index 8abb12520e..9777237e40 100644 --- a/src/Lucene.Net.Grouping/AbstractGroupFacetCollector.cs +++ b/src/Lucene.Net.Grouping/AbstractGroupFacetCollector.cs @@ -267,9 +267,12 @@ public override bool Equals(object o) public override int GetHashCode() { - int result = value.GetHashCode(); - result = 31 * result + count; - return result; + unchecked + { + int result = value.GetHashCode(); + result = 31 * result + count; + return result; + } } public override string ToString() diff --git a/src/Lucene.Net.Highlighter/VectorHighlight/FieldPhraseList.cs b/src/Lucene.Net.Highlighter/VectorHighlight/FieldPhraseList.cs index 7ece6682d8..122ecd8dfe 100644 --- a/src/Lucene.Net.Highlighter/VectorHighlight/FieldPhraseList.cs +++ b/src/Lucene.Net.Highlighter/VectorHighlight/FieldPhraseList.cs @@ -431,13 +431,16 @@ public virtual int CompareTo(WeightedPhraseInfo other) public override int GetHashCode() { - int prime = 31; - int result = 1; - result = prime * result + StartOffset; - result = prime * result + EndOffset; - long b = J2N.BitConversion.DoubleToInt64Bits(Boost); - result = prime * result + (int)(b ^ (b >>> 32)); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + StartOffset; + result = prime * result + EndOffset; + long b = J2N.BitConversion.DoubleToInt64Bits(Boost); + result = prime * result + (int)(b ^ (b >>> 32)); + return result; + } } public override bool Equals(object obj) @@ -528,11 +531,14 @@ public virtual int CompareTo(Toffs other) public override int GetHashCode() { - int prime = 31; - int result = 1; - result = prime * result + StartOffset; - result = prime * result + EndOffset; - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + StartOffset; + result = prime * result + EndOffset; + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.Highlighter/VectorHighlight/FieldTermStack.cs b/src/Lucene.Net.Highlighter/VectorHighlight/FieldTermStack.cs index b8230ba33c..a8a0e3b3b3 100644 --- a/src/Lucene.Net.Highlighter/VectorHighlight/FieldTermStack.cs +++ b/src/Lucene.Net.Highlighter/VectorHighlight/FieldTermStack.cs @@ -257,10 +257,13 @@ public virtual int CompareTo(TermInfo o) public override int GetHashCode() { - int prime = 31; - int result = 1; - result = prime * result + position; - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + position; + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.Join/TermsQuery.cs b/src/Lucene.Net.Join/TermsQuery.cs index 0ecd8f66b6..04354ab9a2 100644 --- a/src/Lucene.Net.Join/TermsQuery.cs +++ b/src/Lucene.Net.Join/TermsQuery.cs @@ -25,7 +25,7 @@ namespace Lucene.Net.Search.Join /// /// A query that has an array of terms from a specific field. This query will match documents have one or more terms in /// the specified field that match with the terms specified in the array. - /// + /// /// @lucene.experimental /// internal class TermsQuery : MultiTermQuery @@ -35,12 +35,12 @@ internal class TermsQuery : MultiTermQuery private readonly Query _fromQuery; // Used for equals() only /// - /// + /// /// /// The field that should contain terms that are specified in the previous parameter. /// /// The terms that matching documents should have. The terms must be sorted by natural order. - internal TermsQuery(string field, Query fromQuery, BytesRefHash terms) + internal TermsQuery(string field, Query fromQuery, BytesRefHash terms) : base(field) { _fromQuery = fromQuery; @@ -89,10 +89,13 @@ public override bool Equals(object obj) public override int GetHashCode() { - int prime = 31; - int result = base.GetHashCode(); - result += prime * _fromQuery.GetHashCode(); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result += prime * _fromQuery.GetHashCode(); + return result; + } } private class SeekingTermSetTermsEnum : FilteredTermsEnum @@ -108,7 +111,7 @@ private class SeekingTermSetTermsEnum : FilteredTermsEnum private BytesRef _seekTerm; private int _upto; - internal SeekingTermSetTermsEnum(TermsEnum tenum, BytesRefHash terms, int[] ords) + internal SeekingTermSetTermsEnum(TermsEnum tenum, BytesRefHash terms, int[] ords) : base(tenum) { this.terms = terms; @@ -125,7 +128,7 @@ protected override BytesRef NextSeekTerm(BytesRef currentTerm) _seekTerm = null; return temp; } - + protected override AcceptStatus Accept(BytesRef term) { if (_comparer.Compare(term, _lastTerm) > 0) @@ -175,4 +178,4 @@ protected override AcceptStatus Accept(BytesRef term) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Misc/Util/Fst/UpToTwoPositiveIntOutputs.cs b/src/Lucene.Net.Misc/Util/Fst/UpToTwoPositiveIntOutputs.cs index cf97d1cdd5..5436f8af14 100644 --- a/src/Lucene.Net.Misc/Util/Fst/UpToTwoPositiveIntOutputs.cs +++ b/src/Lucene.Net.Misc/Util/Fst/UpToTwoPositiveIntOutputs.cs @@ -96,7 +96,10 @@ public override bool Equals(object other) public override int GetHashCode() { - return (int)((first ^ (first >>> 32)) ^ (second ^ (second >> 32))); + unchecked + { + return (int)((first ^ (first >>> 32)) ^ (second ^ (second >> 32))); + } } } diff --git a/src/Lucene.Net.Queries/BoostingQuery.cs b/src/Lucene.Net.Queries/BoostingQuery.cs index 503d2a5f41..f933a8a80a 100644 --- a/src/Lucene.Net.Queries/BoostingQuery.cs +++ b/src/Lucene.Net.Queries/BoostingQuery.cs @@ -23,18 +23,18 @@ namespace Lucene.Net.Queries /// - /// The class can be used to effectively demote results that match a given query. - /// Unlike the "NOT" clause, this still selects documents that contain undesirable terms, + /// The class can be used to effectively demote results that match a given query. + /// Unlike the "NOT" clause, this still selects documents that contain undesirable terms, /// but reduces their overall score: /// /// Query balancedQuery = new BoostingQuery(positiveQuery, negativeQuery, 0.01f); /// - /// In this scenario the positiveQuery contains the mandatory, desirable criteria which is used to - /// select all matching documents, and the negativeQuery contains the undesirable elements which - /// are simply used to lessen the scores. Documents that match the negativeQuery have their score - /// multiplied by the supplied "boost" parameter, so this should be less than 1 to achieve a + /// In this scenario the positiveQuery contains the mandatory, desirable criteria which is used to + /// select all matching documents, and the negativeQuery contains the undesirable elements which + /// are simply used to lessen the scores. Documents that match the negativeQuery have their score + /// multiplied by the supplied "boost" parameter, so this should be less than 1 to achieve a /// demoting effect - /// + /// /// This code was originally made available here: [WWW] http://marc.theaimsgroup.com/?l=lucene-user&m=108058407130459&w=2 /// and is documented here: http://wiki.apache.org/lucene-java/CommunityContributions /// @@ -106,12 +106,15 @@ public override float Coord(int overlap, int max) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + J2N.BitConversion.SingleToInt32Bits(boost); - result = prime * result + ((context is null) ? 0 : context.GetHashCode()); - result = prime * result + ((match is null) ? 0 : match.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + J2N.BitConversion.SingleToInt32Bits(boost); + result = prime * result + ((context is null) ? 0 : context.GetHashCode()); + result = prime * result + ((match is null) ? 0 : match.GetHashCode()); + return result; + } } public override bool Equals(object obj) @@ -171,4 +174,4 @@ public override string ToString(string field) return match.ToString(field) + "/" + context.ToString(field); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/CommonTermsQuery.cs b/src/Lucene.Net.Queries/CommonTermsQuery.cs index ba7ec2c672..378a6f751e 100644 --- a/src/Lucene.Net.Queries/CommonTermsQuery.cs +++ b/src/Lucene.Net.Queries/CommonTermsQuery.cs @@ -58,10 +58,10 @@ namespace Lucene.Net.Queries /// /// Collection initializer note: To create and populate a /// in a single statement, you can use the following example as a guide: - /// + /// /// /// var query = new CommonTermsQuery() { - /// new Term("field", "microsoft"), + /// new Term("field", "microsoft"), /// new Term("field", "office") /// }; /// @@ -316,7 +316,7 @@ public virtual void CollectTermContext(IndexReader reader, IList>=1 as an absolut number of clauses that need to match. - /// + /// /// /// By default no optional clauses are necessary for a match (unless there are /// no required clauses). If this method is used, then the specified number of @@ -336,7 +336,7 @@ public virtual float LowFreqMinimumNumberShouldMatch /// part. This method accepts a float value in the range [0..1) as a fraction /// of the actual query terms in the low frequent clause or a number /// >=1 as an absolut number of clauses that need to match. - /// + /// /// /// By default no optional clauses are necessary for a match (unless there are /// no required clauses). If this method is used, then the specified number of @@ -394,19 +394,22 @@ public override string ToString(string field) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + (m_disableCoord ? 1231 : 1237); - result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_highFreqBoost); - result = prime * result + /*((highFreqOccur is null) ? 0 :*/ m_highFreqOccur.GetHashCode()/*)*/; - result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_lowFreqBoost); - result = prime * result + /*((lowFreqOccur is null) ? 0 :*/ m_lowFreqOccur.GetHashCode()/*)*/; - result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_maxTermFrequency); - result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_lowFreqMinNrShouldMatch); - result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_highFreqMinNrShouldMatch); - // LUCENENET specific: use structural equality comparison - result = prime * result + ((m_terms is null) ? 0 : JCG.ListEqualityComparer.Default.GetHashCode(m_terms)); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (m_disableCoord ? 1231 : 1237); + result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_highFreqBoost); + result = prime * result + /*((highFreqOccur is null) ? 0 :*/ m_highFreqOccur.GetHashCode()/*)*/; + result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_lowFreqBoost); + result = prime * result + /*((lowFreqOccur is null) ? 0 :*/ m_lowFreqOccur.GetHashCode()/*)*/; + result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_maxTermFrequency); + result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_lowFreqMinNrShouldMatch); + result = prime * result + J2N.BitConversion.SingleToInt32Bits(m_highFreqMinNrShouldMatch); + // LUCENENET specific: use structural equality comparison + result = prime * result + (m_terms is null ? 0 : JCG.ListEqualityComparer.Default.GetHashCode(m_terms)); + return result; + } } public override bool Equals(object obj) @@ -502,4 +505,4 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/CustomScoreQuery.cs b/src/Lucene.Net.Queries/CustomScoreQuery.cs index 4b1cd5eb0d..0a261237c5 100644 --- a/src/Lucene.Net.Queries/CustomScoreQuery.cs +++ b/src/Lucene.Net.Queries/CustomScoreQuery.cs @@ -1,4 +1,5 @@ // Lucene version compatibility level 4.8.1 + using Lucene.Net.Index; using Lucene.Net.Queries.Function; using Lucene.Net.Search; @@ -181,8 +182,11 @@ public override bool Equals(object o) /// Returns a hash code value for this object. public override int GetHashCode() { - return (this.GetType().GetHashCode() + subQuery.GetHashCode() + Arrays.GetHashCode(scoringQueries)) ^ - J2N.BitConversion.SingleToInt32Bits(Boost) ^ (strict ? 1234 : 4321); + unchecked + { + return (this.GetType().GetHashCode() + subQuery.GetHashCode() + Arrays.GetHashCode(scoringQueries)) ^ + J2N.BitConversion.SingleToInt32Bits(Boost) ^ (strict ? 1234 : 4321); + } } /// diff --git a/src/Lucene.Net.Queries/Function/BoostedQuery.cs b/src/Lucene.Net.Queries/Function/BoostedQuery.cs index 560ede6ee6..1266aca8e1 100644 --- a/src/Lucene.Net.Queries/Function/BoostedQuery.cs +++ b/src/Lucene.Net.Queries/Function/BoostedQuery.cs @@ -217,12 +217,15 @@ public override bool Equals(object o) public override int GetHashCode() { - int h = q.GetHashCode(); - h ^= (h << 17) | (h >>> 16); - h += boostVal.GetHashCode(); - h ^= (h << 8) | (h >>> 25); - h += J2N.BitConversion.SingleToInt32Bits(Boost); - return h; + unchecked + { + int h = q.GetHashCode(); + h ^= (h << 17) | (h >>> 16); + h += boostVal.GetHashCode(); + h ^= (h << 8) | (h >>> 25); + h += J2N.BitConversion.SingleToInt32Bits(Boost); + return h; + } } } } diff --git a/src/Lucene.Net.Queries/Function/FunctionQuery.cs b/src/Lucene.Net.Queries/Function/FunctionQuery.cs index 6e4035f5f4..8d0dd73b2c 100644 --- a/src/Lucene.Net.Queries/Function/FunctionQuery.cs +++ b/src/Lucene.Net.Queries/Function/FunctionQuery.cs @@ -28,7 +28,7 @@ namespace Lucene.Net.Queries.Function /// /// Returns a score for each document based on a , /// often some function of the value of a field. - /// + /// /// Note: This API is experimental and may change in non backward-compatible ways in the future /// public class FunctionQuery : Query @@ -203,7 +203,7 @@ public override bool Equals(object o) { if (o is null) return false; if (!(o is FunctionQuery other)) return false; - return Boost == other.Boost + return Boost == other.Boost && func.Equals(other.func); } @@ -212,7 +212,10 @@ public override bool Equals(object o) /// public override int GetHashCode() { - return func.GetHashCode() * 31 + J2N.BitConversion.SingleToInt32Bits(Boost); + unchecked + { + return func.GetHashCode() * 31 + J2N.BitConversion.SingleToInt32Bits(Boost); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs index 2655342d68..1f102439c7 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs @@ -23,7 +23,7 @@ namespace Lucene.Net.Queries.Function.ValueSources * See the License for the specific language governing permissions and * limitations under the License. */ - + /// /// Obtains field values from the /// using @@ -137,9 +137,12 @@ public override bool Equals(object o) public override int GetHashCode() { - int h = parser is null ? typeof(sbyte?).GetHashCode() : parser.GetType().GetHashCode(); - h += base.GetHashCode(); - return h; + unchecked + { + int h = parser is null ? typeof(sbyte?).GetHashCode() : parser.GetType().GetHashCode(); + h += base.GetHashCode(); + return h; + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ConstValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ConstValueSource.cs index 73927f240c..d5573e38ae 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/ConstValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/ConstValueSource.cs @@ -99,7 +99,10 @@ public override bool BoolVal(int doc) public override int GetHashCode() { - return J2N.BitConversion.SingleToInt32Bits(constant) * 31; + unchecked + { + return J2N.BitConversion.SingleToInt32Bits(constant) * 31; + } } public override bool Equals(object o) @@ -132,4 +135,4 @@ public override bool Equals(object o) public override bool Bool => constant != 0.0f; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs index 756d150926..054e5db4d7 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs @@ -184,7 +184,10 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) public override int GetHashCode() { - return this.GetType().GetHashCode() + m_indexedField.GetHashCode() * 29 + m_indexedBytes.GetHashCode(); + unchecked + { + return this.GetType().GetHashCode() + m_indexedField.GetHashCode() * 29 + m_indexedBytes.GetHashCode(); + } } public override bool Equals(object o) @@ -197,4 +200,4 @@ public override bool Equals(object o) return this.m_indexedField.Equals(other.m_indexedField, StringComparison.Ordinal) && this.m_indexedBytes.Equals(other.m_indexedBytes); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs index 67f926f7cc..1a85857cfe 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs @@ -100,9 +100,12 @@ public override bool Equals(object o) public override int GetHashCode() { - int h = m_parser is null ? typeof(double).GetHashCode() : m_parser.GetType().GetHashCode(); - h += base.GetHashCode(); - return h; + unchecked + { + int h = m_parser is null ? typeof(double).GetHashCode() : m_parser.GetType().GetHashCode(); + h += base.GetHashCode(); + return h; + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DualFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/DualFloatFunction.cs index 280809161c..b451271773 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/DualFloatFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/DualFloatFunction.cs @@ -94,12 +94,15 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) public override int GetHashCode() { - int h = m_a.GetHashCode(); - h ^= (h << 13) | (h >>> 20); - h += m_b.GetHashCode(); - h ^= (h << 23) | (h >>> 10); - h += Name.GetHashCode(); - return h; + unchecked + { + int h = m_a.GetHashCode(); + h ^= (h << 13) | (h >>> 20); + h += m_b.GetHashCode(); + h ^= (h << 23) | (h >>> 10); + h += Name.GetHashCode(); + return h; + } } public override bool Equals(object o) diff --git a/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs index a96bee74f0..091518718b 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs @@ -267,13 +267,16 @@ public override bool Equals(object o) public override int GetHashCode() { - int result = base.GetHashCode(); - result = 31 * result + parser.GetHashCode(); - // LUCENENET specific: must use DictionaryEqualityComparer.GetHashCode() to ensure values - // contained within the dictionaries are compared for equality - result = 31 * result + JCG.DictionaryEqualityComparer.Default.GetHashCode(enumIntToStringMap); - result = 31 * result + JCG.DictionaryEqualityComparer.Default.GetHashCode(enumStringToIntMap); - return result; + unchecked + { + int result = base.GetHashCode(); + result = 31 * result + parser.GetHashCode(); + // LUCENENET specific: must use DictionaryEqualityComparer.GetHashCode() to ensure values + // contained within the dictionaries are compared for equality + result = 31 * result + JCG.DictionaryEqualityComparer.Default.GetHashCode(enumIntToStringMap); + result = 31 * result + JCG.DictionaryEqualityComparer.Default.GetHashCode(enumStringToIntMap); + return result; + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/FieldCacheSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/FieldCacheSource.cs index e9ce82c4da..2b2f4f1a4a 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/FieldCacheSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/FieldCacheSource.cs @@ -53,7 +53,10 @@ public override bool Equals(object o) public override int GetHashCode() { - return m_cache.GetHashCode() + m_field.GetHashCode(); + unchecked + { + return m_cache.GetHashCode() + m_field.GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs index 0021740590..a8f97da57e 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs @@ -107,9 +107,12 @@ public override bool Equals(object o) public override int GetHashCode() { - int h = m_parser is null ? typeof(float).GetHashCode() : m_parser.GetType().GetHashCode(); - h += base.GetHashCode(); - return h; + unchecked + { + int h = m_parser is null ? typeof(float).GetHashCode() : m_parser.GetType().GetHashCode(); + h += base.GetHashCode(); + return h; + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs index 51653f2412..3430db09bb 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs @@ -149,10 +149,13 @@ public override string GetDescription() public override int GetHashCode() { - int h = ifSource.GetHashCode(); - h = h * 31 + trueSource.GetHashCode(); - h = h * 31 + falseSource.GetHashCode(); - return h; + unchecked + { + int h = ifSource.GetHashCode(); + h = h * 31 + trueSource.GetHashCode(); + h = h * 31 + falseSource.GetHashCode(); + return h; + } } public override bool Equals(object o) @@ -169,4 +172,4 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) falseSource.CreateWeight(context, searcher); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs index b51a1c63e7..8483d1c45f 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs @@ -147,9 +147,12 @@ public override bool Equals(object o) public override int GetHashCode() { - int h = parser is null ? typeof(int).GetHashCode() : parser.GetType().GetHashCode(); - h += base.GetHashCode(); - return h; + unchecked + { + int h = parser is null ? typeof(int).GetHashCode() : parser.GetType().GetHashCode(); + h += base.GetHashCode(); + return h; + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs index 0a22cf4ab2..0dc91011f5 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs @@ -28,7 +28,7 @@ namespace Lucene.Net.Queries.Function.ValueSources /// /// Use a field value and find the Document Frequency within another field. - /// + /// /// @since solr 4.0 /// public class JoinDocFreqValueSource : FieldCacheSource @@ -113,7 +113,10 @@ public override bool Equals(object o) public override int GetHashCode() { - return m_qfield.GetHashCode() + base.GetHashCode(); + unchecked + { + return m_qfield.GetHashCode() + base.GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs index 5969ee8ed2..e18fa2a745 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs @@ -92,11 +92,14 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) public override int GetHashCode() { - int h = J2N.BitConversion.SingleToInt32Bits(m_slope); - h = (h >>> 2) | (h << 30); - h += J2N.BitConversion.SingleToInt32Bits(m_intercept); - h ^= (h << 14) | (h >>> 19); - return h + m_source.GetHashCode(); + unchecked + { + int h = J2N.BitConversion.SingleToInt32Bits(m_slope); + h = (h >>> 2) | (h << 30); + h += J2N.BitConversion.SingleToInt32Bits(m_intercept); + h ^= (h << 14) | (h >>> 19); + return h + m_source.GetHashCode(); + } } public override bool Equals(object o) diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs index 10f6cf8a97..f556e7e5ba 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs @@ -95,7 +95,10 @@ public override bool Equals(object o) public static readonly int hash = typeof(LiteralValueSource).GetHashCode(); public override int GetHashCode() { - return hash + m_str.GetHashCode(); + unchecked + { + return hash + m_str.GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs index cdae2d76bc..e37dae0b4b 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs @@ -167,9 +167,12 @@ public override bool Equals(object o) public override int GetHashCode() { - int h = m_parser is null ? this.GetType().GetHashCode() : m_parser.GetType().GetHashCode(); - h += base.GetHashCode(); - return h; + unchecked + { + int h = m_parser is null ? this.GetType().GetHashCode() : m_parser.GetType().GetHashCode(); + h += base.GetHashCode(); + return h; + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs index fd83dde922..bf83bf8858 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs @@ -116,8 +116,11 @@ public override string GetDescription() public override int GetHashCode() { - // LUCENENET specific: use structural equality comparison - return JCG.ListEqualityComparer.Default.GetHashCode(m_sources) + Name.GetHashCode(); + unchecked + { + // LUCENENET specific: use structural equality comparison + return JCG.ListEqualityComparer.Default.GetHashCode(m_sources) + Name.GetHashCode(); + } } public override bool Equals(object o) @@ -141,4 +144,4 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs index 15d92f5044..add2ac08ea 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs @@ -129,7 +129,10 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) public override int GetHashCode() { - return Arrays.GetHashCode(m_sources) + Name.GetHashCode(); + unchecked + { + return Arrays.GetHashCode(m_sources) + Name.GetHashCode(); + } } public override bool Equals(object o) @@ -143,4 +146,4 @@ public override bool Equals(object o) return Name.Equals(other.Name, StringComparison.Ordinal) && Arrays.Equals(this.m_sources, other.m_sources); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs index 623e101690..f316016da9 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs @@ -127,8 +127,11 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) public override int GetHashCode() { - // LUCENENET specific: use structural equality comparison - return JCG.ListEqualityComparer.Default.GetHashCode(m_sources) + Name.GetHashCode(); + unchecked + { + // LUCENENET specific: use structural equality comparison + return JCG.ListEqualityComparer.Default.GetHashCode(m_sources) + Name.GetHashCode(); + } } public override bool Equals(object o) @@ -143,4 +146,4 @@ public override bool Equals(object o) return JCG.ListEqualityComparer.Default.Equals(this.m_sources, other.m_sources); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs index affe0f3471..1f7d4c1c80 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs @@ -31,7 +31,7 @@ namespace Lucene.Net.Queries.Function.ValueSources /// /// Note that the configured Similarity for the field must be /// a subclass of - /// @lucene.internal + /// @lucene.internal /// public class NormValueSource : ValueSource { @@ -104,7 +104,10 @@ public override bool Equals(object o) public override int GetHashCode() { - return this.GetType().GetHashCode() + m_field.GetHashCode(); + unchecked + { + return this.GetType().GetHashCode() + m_field.GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs index 69fcf33cf1..c5657578f6 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs @@ -124,7 +124,10 @@ public override bool Equals(object o) public override int GetHashCode() { - return hcode + m_field.GetHashCode(); + unchecked + { + return hcode + m_field.GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs index 7870aa7a3e..185f013156 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs @@ -58,7 +58,10 @@ public override FunctionValues GetValues(IDictionary fcontext, AtomicReaderConte public override int GetHashCode() { - return q.GetHashCode() * 29; + unchecked + { + return q.GetHashCode() * 29; + } } public override bool Equals(object o) @@ -280,4 +283,4 @@ public override string ToString(int doc) return "query(" + q + ",def=" + defVal + ")=" + SingleVal(doc); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs index e86862d68f..bbc575aaa7 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs @@ -110,17 +110,20 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) public override int GetHashCode() { - int h = m_source.GetHashCode(); - h ^= (h << 10) | (h >>> 23); - h += J2N.BitConversion.SingleToInt32Bits(m_min); - h ^= (h << 14) | (h >>> 19); - h += J2N.BitConversion.SingleToInt32Bits(m_max); - h += m_target.GetHashCode(); - if (m_defaultVal != null) + unchecked { - h += m_defaultVal.GetHashCode(); + int h = m_source.GetHashCode(); + h ^= (h << 10) | (h >>> 23); + h += J2N.BitConversion.SingleToInt32Bits(m_min); + h ^= (h << 14) | (h >>> 19); + h += J2N.BitConversion.SingleToInt32Bits(m_max); + h += m_target.GetHashCode(); + if (m_defaultVal != null) + { + h += m_defaultVal.GetHashCode(); + } + return h; } - return h; } public override bool Equals(object o) diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs index 27985440e4..dd331c5912 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs @@ -109,9 +109,12 @@ public override string GetDescription() public override int GetHashCode() { - int h = J2N.BitConversion.SingleToInt32Bits(m_a) + J2N.BitConversion.SingleToInt32Bits(m_m); - h ^= (h << 13) | (h >>> 20); - return h + (J2N.BitConversion.SingleToInt32Bits(m_b)) + m_source.GetHashCode(); + unchecked + { + int h = J2N.BitConversion.SingleToInt32Bits(m_a) + J2N.BitConversion.SingleToInt32Bits(m_m); + h ^= (h << 13) | (h >>> 20); + return h + (J2N.BitConversion.SingleToInt32Bits(m_b)) + m_source.GetHashCode(); + } } public override bool Equals(object o) diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs index 58cdf77387..efd2dacbd1 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs @@ -106,7 +106,10 @@ public override bool Equals(object o) private static readonly int hcode = typeof(ReverseOrdFieldSource).GetHashCode(); public override int GetHashCode() { - return hcode + field.GetHashCode(); + unchecked + { + return hcode + field.GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs index b6305b2c61..4495e37d35 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs @@ -151,7 +151,7 @@ public override float SingleVal(int doc) public override string ToString(int doc) { // LUCENENET specific - changed formatting to ensure the same culture is used for each value. - return string.Format(CultureInfo.InvariantCulture, "scale({0},toMin={1},toMax={2},fromMin={3})", + return string.Format(CultureInfo.InvariantCulture, "scale({0},toMin={1},toMax={2},fromMin={3})", vals.ToString(doc), outerInstance.m_min, outerInstance.m_max, @@ -166,12 +166,15 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) public override int GetHashCode() { - int h = J2N.BitConversion.SingleToInt32Bits(m_min); - h = h * 29; - h += J2N.BitConversion.SingleToInt32Bits(m_max); - h = h * 29; - h += m_source.GetHashCode(); - return h; + unchecked + { + int h = J2N.BitConversion.SingleToInt32Bits(m_min); + h = h * 29; + h += J2N.BitConversion.SingleToInt32Bits(m_max); + h = h * 29; + h += m_source.GetHashCode(); + return h; + } } public override bool Equals(object o) @@ -179,8 +182,8 @@ public override bool Equals(object o) if (!(o is ScaleSingleFunction other)) return false; return J2N.BitConversion.SingleToInt32Bits(this.m_min) == J2N.BitConversion.SingleToInt32Bits(other.m_min) - && J2N.BitConversion.SingleToInt32Bits(this.m_max) == J2N.BitConversion.SingleToInt32Bits(other.m_max) + && J2N.BitConversion.SingleToInt32Bits(this.m_max) == J2N.BitConversion.SingleToInt32Bits(other.m_max) && this.m_source.Equals(other.m_source); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs index 8587f87d76..96a1c78c7f 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs @@ -126,16 +126,19 @@ public override bool Equals(object o) { if (!(o is Int16FieldSource other)) return false; - return base.Equals(other) - && (parser is null ? other.parser is null : + return base.Equals(other) + && (parser is null ? other.parser is null : parser.GetType() == other.parser.GetType()); } public override int GetHashCode() { - var h = parser is null ? typeof(short).GetHashCode() : parser.GetType().GetHashCode(); - h += base.GetHashCode(); - return h; + unchecked + { + var h = parser is null ? typeof(short).GetHashCode() : parser.GetType().GetHashCode(); + h += base.GetHashCode(); + return h; + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/SimpleBoolFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/SimpleBoolFunction.cs index 81003987de..3435474fcf 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/SimpleBoolFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/SimpleBoolFunction.cs @@ -26,7 +26,7 @@ namespace Lucene.Net.Queries.Function.ValueSources /// /// implementation which applies an extendible /// function to the values of a single wrapped . - /// + /// /// Functions this can be used for include whether a field has a value or not, /// or inverting the value of the wrapped . /// @@ -79,7 +79,10 @@ public override string GetDescription() public override int GetHashCode() { - return m_source.GetHashCode() + Name.GetHashCode(); + unchecked + { + return m_source.GetHashCode() + Name.GetHashCode(); + } } public override bool Equals(object o) @@ -94,4 +97,4 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) m_source.CreateWeight(context, searcher); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/SingleFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/SingleFunction.cs index a06fd4ae52..c9eb96a6c2 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/SingleFunction.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/SingleFunction.cs @@ -45,14 +45,17 @@ public override string GetDescription() public override int GetHashCode() { - return m_source.GetHashCode() + Name.GetHashCode(); + unchecked + { + return m_source.GetHashCode() + Name.GetHashCode(); + } } public override bool Equals(object o) { if (!(o is SingularFunction other)) return false; - return Name.Equals(other.Name, StringComparison.Ordinal) + return Name.Equals(other.Name, StringComparison.Ordinal) && m_source.Equals(other.m_source); } @@ -61,4 +64,4 @@ public override void CreateWeight(IDictionary context, IndexSearcher searcher) m_source.CreateWeight(context, searcher); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/SumTotalTermFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/SumTotalTermFreqValueSource.cs index 0225ff94e3..a25111f2a2 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/SumTotalTermFreqValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/SumTotalTermFreqValueSource.cs @@ -27,7 +27,7 @@ namespace Lucene.Net.Queries.Function.ValueSources /// /// returns the number of tokens. /// (sum of term freqs across all documents, across all terms). - /// Returns -1 if frequencies were omitted for the field, or if + /// Returns -1 if frequencies were omitted for the field, or if /// the codec doesn't support this statistic. /// @lucene.internal /// @@ -103,7 +103,10 @@ public override long Int64Val(int doc) public override int GetHashCode() { - return this.GetType().GetHashCode() + m_indexedField.GetHashCode(); + unchecked + { + return this.GetType().GetHashCode() + m_indexedField.GetHashCode(); + } } public override bool Equals(object o) @@ -113,4 +116,4 @@ public override bool Equals(object o) return this.m_indexedField.Equals(other.m_indexedField, StringComparison.Ordinal); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Function/ValueSources/TotalTermFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/TotalTermFreqValueSource.cs index 21899ce820..c62023ce38 100644 --- a/src/Lucene.Net.Queries/Function/ValueSources/TotalTermFreqValueSource.cs +++ b/src/Lucene.Net.Queries/Function/ValueSources/TotalTermFreqValueSource.cs @@ -26,9 +26,9 @@ namespace Lucene.Net.Queries.Function.ValueSources */ /// - /// returns the total term freq + /// returns the total term freq /// (sum of term freqs across all documents). - /// Returns -1 if frequencies were omitted for the field, or if + /// Returns -1 if frequencies were omitted for the field, or if /// the codec doesn't support this statistic. /// @lucene.internal /// @@ -100,7 +100,10 @@ public override long Int64Val(int doc) public override int GetHashCode() { - return this.GetType().GetHashCode() + m_indexedField.GetHashCode() * 29 + m_indexedBytes.GetHashCode(); + unchecked + { + return this.GetType().GetHashCode() + m_indexedField.GetHashCode() * 29 + m_indexedBytes.GetHashCode(); + } } public override bool Equals(object o) @@ -110,4 +113,4 @@ public override bool Equals(object o) return this.m_indexedField.Equals(other.m_indexedField, StringComparison.Ordinal) && this.m_indexedBytes.Equals(other.m_indexedBytes); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/Mlt/MoreLikeThisQuery.cs b/src/Lucene.Net.Queries/Mlt/MoreLikeThisQuery.cs index 275ed25e41..e8a9e0ec64 100644 --- a/src/Lucene.Net.Queries/Mlt/MoreLikeThisQuery.cs +++ b/src/Lucene.Net.Queries/Mlt/MoreLikeThisQuery.cs @@ -139,19 +139,22 @@ public virtual int MinDocFreq public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + ((analyzer is null) ? 0 : analyzer.GetHashCode()); - result = prime * result + ((fieldName is null) ? 0 : fieldName.GetHashCode()); - result = prime * result + ((likeText is null) ? 0 : likeText.GetHashCode()); - result = prime * result + maxQueryTerms; - result = prime * result + minDocFreq; - result = prime * result + minTermFrequency; - result = prime * result + Arrays.GetHashCode(moreLikeFields); - result = prime * result + J2N.BitConversion.SingleToInt32Bits(percentTermsToMatch); - // LUCENENET specific: use structural equality comparison - result = prime * result + ((stopWords is null) ? 0 : JCG.SetEqualityComparer.Default.GetHashCode(stopWords)); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (analyzer is null ? 0 : analyzer.GetHashCode()); + result = prime * result + (fieldName is null ? 0 : fieldName.GetHashCode()); + result = prime * result + (likeText is null ? 0 : likeText.GetHashCode()); + result = prime * result + maxQueryTerms; + result = prime * result + minDocFreq; + result = prime * result + minTermFrequency; + result = prime * result + Arrays.GetHashCode(moreLikeFields); + result = prime * result + J2N.BitConversion.SingleToInt32Bits(percentTermsToMatch); + // LUCENENET specific: use structural equality comparison + result = prime * result + (stopWords is null ? 0 : JCG.SetEqualityComparer.Default.GetHashCode(stopWords)); + return result; + } } public override bool Equals(object obj) @@ -237,4 +240,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Queries/TermsFilter.cs b/src/Lucene.Net.Queries/TermsFilter.cs index 3aae8295f3..d3ccb685e8 100644 --- a/src/Lucene.Net.Queries/TermsFilter.cs +++ b/src/Lucene.Net.Queries/TermsFilter.cs @@ -343,12 +343,15 @@ internal TermsAndField(int start, int end, string field) public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + ((field is null) ? 0 : field.GetHashCode()); - result = prime * result + end; - result = prime * result + start; - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + ((field is null) ? 0 : field.GetHashCode()); + result = prime * result + end; + result = prime * result + start; + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.QueryParser/ComplexPhrase/ComplexPhraseQueryParser.cs b/src/Lucene.Net.QueryParser/ComplexPhrase/ComplexPhraseQueryParser.cs index 8c42c3891f..a846a5c532 100644 --- a/src/Lucene.Net.QueryParser/ComplexPhrase/ComplexPhraseQueryParser.cs +++ b/src/Lucene.Net.QueryParser/ComplexPhrase/ComplexPhraseQueryParser.cs @@ -419,16 +419,19 @@ public override string ToString(string field) public override int GetHashCode() { - int prime = 31; - int result = base.GetHashCode(); - result = prime * result + ((field is null) ? 0 : field.GetHashCode()); - result = prime - * result - + ((phrasedQueryStringContents is null) ? 0 - : phrasedQueryStringContents.GetHashCode()); - result = prime * result + slopFactor; - result = prime * result + (inOrder ? 1 : 0); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (field is null ? 0 : field.GetHashCode()); + result = prime + * result + + (phrasedQueryStringContents is null ? 0 + : phrasedQueryStringContents.GetHashCode()); + result = prime * result + slopFactor; + result = prime * result + (inOrder ? 1 : 0); + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs index a59a2134a7..ed66a56b74 100644 --- a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs +++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs @@ -103,12 +103,15 @@ public override bool Equals(object obj) /// public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + this.precisionStep.GetHashCode(); - result = prime * result + this.type.GetHashCode(); - result = prime * result + this.format.GetHashCode(); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + this.precisionStep.GetHashCode(); + result = prime * result + this.type.GetHashCode(); + result = prime * result + this.format.GetHashCode(); + return result; + } } } } diff --git a/src/Lucene.Net.Sandbox/Queries/DuplicateFilter.cs b/src/Lucene.Net.Sandbox/Queries/DuplicateFilter.cs index 73931a0533..7566657f52 100644 --- a/src/Lucene.Net.Sandbox/Queries/DuplicateFilter.cs +++ b/src/Lucene.Net.Sandbox/Queries/DuplicateFilter.cs @@ -195,11 +195,14 @@ public override bool Equals(object obj) public override int GetHashCode() { - int hash = 217; - hash = 31 * hash + keepMode.GetHashCode(); - hash = 31 * hash + processingMode.GetHashCode(); - hash = 31 * hash + fieldName.GetHashCode(); - return hash; + unchecked + { + int hash = 217; + hash = 31 * hash + keepMode.GetHashCode(); + hash = 31 * hash + processingMode.GetHashCode(); + hash = 31 * hash + fieldName.GetHashCode(); + return hash; + } } public ProcessingMode ProcessingMode diff --git a/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs b/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs index 3c5da3287c..9fd5d3ceac 100644 --- a/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs +++ b/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs @@ -61,14 +61,17 @@ public class FuzzyLikeThisQuery : Query public override int GetHashCode() { - int prime = 31; - int result = base.GetHashCode(); - result = prime * result + ((analyzer is null) ? 0 : analyzer.GetHashCode()); - result = prime * result - + ((fieldVals is null) ? 0 : fieldVals.GetHashCode()); - result = prime * result + (ignoreTF ? 1231 : 1237); - result = prime * result + maxNumTerms; - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (analyzer is null ? 0 : analyzer.GetHashCode()); + result = prime * result + + (fieldVals is null ? 0 : fieldVals.GetHashCode()); + result = prime * result + (ignoreTF ? 1231 : 1237); + result = prime * result + maxNumTerms; + return result; + } } public override bool Equals(object obj) @@ -133,15 +136,18 @@ public FieldVals(string name, float similarity, int length, string queryString) public override int GetHashCode() { - int prime = 31; - int result = 1; - result = prime * result - + ((fieldName is null) ? 0 : fieldName.GetHashCode()); - result = prime * result + J2N.BitConversion.SingleToInt32Bits(minSimilarity); - result = prime * result + prefixLength; - result = prime * result - + ((queryString is null) ? 0 : queryString.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + + (fieldName is null ? 0 : fieldName.GetHashCode()); + result = prime * result + J2N.BitConversion.SingleToInt32Bits(minSimilarity); + result = prime * result + prefixLength; + result = prime * result + + (queryString is null ? 0 : queryString.GetHashCode()); + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.Sandbox/Queries/SlowFuzzyQuery.cs b/src/Lucene.Net.Sandbox/Queries/SlowFuzzyQuery.cs index 2548f32189..19f3e0bb62 100644 --- a/src/Lucene.Net.Sandbox/Queries/SlowFuzzyQuery.cs +++ b/src/Lucene.Net.Sandbox/Queries/SlowFuzzyQuery.cs @@ -49,7 +49,7 @@ public class SlowFuzzyQuery : MultiTermQuery protected Term m_term; /// - /// Create a new that will match terms with a similarity + /// Create a new that will match terms with a similarity /// of at least to . /// If a > 0 is specified, a common prefix /// of that length is also required. @@ -173,12 +173,15 @@ public override string ToString(string field) public override int GetHashCode() { - int prime = 31; - int result = base.GetHashCode(); - result = prime * result + J2N.BitConversion.SingleToInt32Bits(minimumSimilarity); - result = prime * result + prefixLength; - result = prime * result + ((m_term is null) ? 0 : m_term.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + J2N.BitConversion.SingleToInt32Bits(minimumSimilarity); + result = prime * result + prefixLength; + result = prime * result + (m_term is null ? 0 : m_term.GetHashCode()); + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.Sandbox/Queries/SortedSetSortField.cs b/src/Lucene.Net.Sandbox/Queries/SortedSetSortField.cs index 578aef3e50..3fc86f04c8 100644 --- a/src/Lucene.Net.Sandbox/Queries/SortedSetSortField.cs +++ b/src/Lucene.Net.Sandbox/Queries/SortedSetSortField.cs @@ -94,7 +94,10 @@ public SortedSetSortField(string field, bool reverse, Selector selector) public override int GetHashCode() { - return 31 * base.GetHashCode() + selector.GetHashCode(); + unchecked + { + return 31 * base.GetHashCode() + selector.GetHashCode(); + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs b/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs index 88156bcf74..36a85dd3da 100644 --- a/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs +++ b/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs @@ -89,9 +89,12 @@ public override bool Equals(object? o) public override int GetHashCode() { - int result = field is null ? 0 : field.GetHashCode(); - result = 31 * result + intersectsFilter.GetHashCode(); - return result; + unchecked + { + int result = field is null ? 0 : field.GetHashCode(); + result = 31 * result + intersectsFilter.GetHashCode(); + return result; + } } /// @@ -129,10 +132,10 @@ public override int GetHashCode() docsWithField = null;//all docs } } - + //not so much a chain but a way to conveniently invert the Filter DocIdSet docIdSet = new ChainedFilter(new Filter[] { intersectsFilter }, ChainedFilter.ANDNOT).GetDocIdSet(context, acceptDocs); return BitsFilteredDocIdSet.Wrap(docIdSet, docsWithField); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Spatial/Prefix/AbstractPrefixTreeFilter.cs b/src/Lucene.Net.Spatial/Prefix/AbstractPrefixTreeFilter.cs index 40dbb43f4d..4c8c3d5a8f 100644 --- a/src/Lucene.Net.Spatial/Prefix/AbstractPrefixTreeFilter.cs +++ b/src/Lucene.Net.Spatial/Prefix/AbstractPrefixTreeFilter.cs @@ -73,10 +73,13 @@ public override bool Equals(object? o) public override int GetHashCode() { - int result = m_queryShape.GetHashCode(); - result = 31 * result + m_fieldName.GetHashCode(); - result = 31 * result + m_detailLevel; - return result; + unchecked + { + int result = m_queryShape.GetHashCode(); + result = 31 * result + m_fieldName.GetHashCode(); + result = 31 * result + m_detailLevel; + return result; + } } // LUCENENET specific - de-nested BaseTermsEnumTraverser @@ -144,4 +147,4 @@ protected virtual void CollectDocs(FixedBitSet bitSet) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Spatial/Prefix/ContainsPrefixTreeFilter.cs b/src/Lucene.Net.Spatial/Prefix/ContainsPrefixTreeFilter.cs index f8d46a035c..34b8fd4445 100644 --- a/src/Lucene.Net.Spatial/Prefix/ContainsPrefixTreeFilter.cs +++ b/src/Lucene.Net.Spatial/Prefix/ContainsPrefixTreeFilter.cs @@ -62,7 +62,10 @@ public override bool Equals(object? o) public override int GetHashCode() { - return base.GetHashCode() + (m_multiOverlappingIndexedShapes ? 1 : 0); + unchecked + { + return base.GetHashCode() + (m_multiOverlappingIndexedShapes ? 1 : 0); + } } public override DocIdSet? GetDocIdSet(AtomicReaderContext context, IBits acceptDocs) diff --git a/src/Lucene.Net.Spatial/Prefix/IntersectsPrefixTreeFilter.cs b/src/Lucene.Net.Spatial/Prefix/IntersectsPrefixTreeFilter.cs index c5ecf29698..8cd63357d7 100644 --- a/src/Lucene.Net.Spatial/Prefix/IntersectsPrefixTreeFilter.cs +++ b/src/Lucene.Net.Spatial/Prefix/IntersectsPrefixTreeFilter.cs @@ -28,14 +28,14 @@ namespace Lucene.Net.Spatial.Prefix /// /// A Filter matching documents that have an /// (i.e. not DISTINCT) relationship with a provided query shape. - /// + /// /// @lucene.internal /// public class IntersectsPrefixTreeFilter : AbstractVisitingPrefixTreeFilter { private readonly bool hasIndexedLeaves; - public IntersectsPrefixTreeFilter(IShape queryShape, string fieldName, + public IntersectsPrefixTreeFilter(IShape queryShape, string fieldName, SpatialPrefixTree grid, int detailLevel, int prefixGridScanLevel, bool hasIndexedLeaves) : base(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel) @@ -49,7 +49,7 @@ public override bool Equals(object? o) } /// - /// LUCENENET specific: need to override GetHashCode to + /// LUCENENET specific: need to override GetHashCode to /// prevent a compiler warning and realistically, the hash code /// should work similarly to Equals. /// @@ -125,4 +125,4 @@ protected override void VisitScanned(Cell cell) #endregion } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Spatial/Util/DistanceToShapeValueSource.cs b/src/Lucene.Net.Spatial/Util/DistanceToShapeValueSource.cs index e95a846f76..6e53373d83 100644 --- a/src/Lucene.Net.Spatial/Util/DistanceToShapeValueSource.cs +++ b/src/Lucene.Net.Spatial/Util/DistanceToShapeValueSource.cs @@ -127,13 +127,16 @@ public override bool Equals(object? o) public override int GetHashCode() { - int result; - long temp; - result = shapeValueSource.GetHashCode(); - result = 31 * result + queryPoint.GetHashCode(); - temp = J2N.BitConversion.DoubleToInt64Bits(multiplier); - result = 31 * result + (int)(temp ^ (temp >>> 32)); - return result; + unchecked + { + int result; + long temp; + result = shapeValueSource.GetHashCode(); + result = 31 * result + queryPoint.GetHashCode(); + temp = J2N.BitConversion.DoubleToInt64Bits(multiplier); + result = 31 * result + (int)(temp ^ (temp >>> 32)); + return result; + } } } } diff --git a/src/Lucene.Net.Spatial/Util/ShapePredicateValueSource.cs b/src/Lucene.Net.Spatial/Util/ShapePredicateValueSource.cs index 01fb98d607..2ec85c1201 100644 --- a/src/Lucene.Net.Spatial/Util/ShapePredicateValueSource.cs +++ b/src/Lucene.Net.Spatial/Util/ShapePredicateValueSource.cs @@ -39,7 +39,7 @@ public class ShapePredicateValueSource : ValueSource private readonly IShape queryShape;//the right hand side (constant) /// - /// + /// /// /// /// Must yield instances from it's ObjectVal(doc). If null @@ -119,10 +119,13 @@ public override bool Equals(object? o) public override int GetHashCode() { - int result = shapeValueSource.GetHashCode(); - result = 31 * result + op.GetHashCode(); - result = 31 * result + queryShape.GetHashCode(); - return result; + unchecked + { + int result = shapeValueSource.GetHashCode(); + result = 31 * result + op.GetHashCode(); + result = 31 * result + queryShape.GetHashCode(); + return result; + } } } } diff --git a/src/Lucene.Net.Suggest/Spell/DirectSpellChecker.cs b/src/Lucene.Net.Suggest/Spell/DirectSpellChecker.cs index ff3a185ca1..c9f4f490c3 100644 --- a/src/Lucene.Net.Suggest/Spell/DirectSpellChecker.cs +++ b/src/Lucene.Net.Suggest/Spell/DirectSpellChecker.cs @@ -553,10 +553,13 @@ public virtual int CompareTo(ScoreTerm other) public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + ((Term is null) ? 0 : Term.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + ((Term is null) ? 0 : Term.GetHashCode()); + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net.Suggest/Spell/JaroWinklerDistance.cs b/src/Lucene.Net.Suggest/Spell/JaroWinklerDistance.cs index cde1b7a907..439ed4a34e 100644 --- a/src/Lucene.Net.Suggest/Spell/JaroWinklerDistance.cs +++ b/src/Lucene.Net.Suggest/Spell/JaroWinklerDistance.cs @@ -125,7 +125,7 @@ public virtual float GetDistance(string s1, string s2) /// /// Gets or sets the threshold used to determine when Winkler bonus should be used. - /// The default value is 0.7. Set to a negative value to get the Jaro distance. + /// The default value is 0.7. Set to a negative value to get the Jaro distance. /// public virtual float Threshold { @@ -136,7 +136,10 @@ public virtual float Threshold public override int GetHashCode() { - return 113 * J2N.BitConversion.SingleToInt32Bits(threshold) * this.GetType().GetHashCode(); + unchecked + { + return 113 * J2N.BitConversion.SingleToInt32Bits(threshold) * this.GetType().GetHashCode(); + } } public override bool Equals(object obj) @@ -159,4 +162,4 @@ public override string ToString() return "jarowinkler(" + threshold + ")"; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Suggest/Spell/LevensteinDistance.cs b/src/Lucene.Net.Suggest/Spell/LevensteinDistance.cs index 86ffbec094..0c83131cca 100644 --- a/src/Lucene.Net.Suggest/Spell/LevensteinDistance.cs +++ b/src/Lucene.Net.Suggest/Spell/LevensteinDistance.cs @@ -58,7 +58,7 @@ allows us to retain the previous cost counts as required by the algorithm (takin of the current cost count being calculated). (Note that the arrays aren't really copied anymore, just switched...this is clearly much better than cloning an array or doing a System.arraycopy() each time through the outer loop.) - + Effectively, the difference between the two implementations is this one does not cause an out of memory condition when calculating the LD over two very large strings. */ @@ -120,7 +120,10 @@ cause an out of memory condition when calculating the LD over two very large str public override int GetHashCode() { - return 163 * this.GetType().GetHashCode(); + unchecked + { + return 163 * this.GetType().GetHashCode(); + } } public override bool Equals(object obj) @@ -141,4 +144,4 @@ public override string ToString() return "levenstein"; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Suggest/Spell/NGramDistance.cs b/src/Lucene.Net.Suggest/Spell/NGramDistance.cs index 49ffd4809c..d97cdd81dc 100644 --- a/src/Lucene.Net.Suggest/Spell/NGramDistance.cs +++ b/src/Lucene.Net.Suggest/Spell/NGramDistance.cs @@ -20,16 +20,16 @@ namespace Lucene.Net.Search.Spell */ /// - /// N-Gram version of edit distance based on paper by Grzegorz Kondrak, - /// "N-gram similarity and distance". Proceedings of the Twelfth International - /// Conference on String Processing and Information Retrieval (SPIRE 2005), pp. 115-126, - /// Buenos Aires, Argentina, November 2005. + /// N-Gram version of edit distance based on paper by Grzegorz Kondrak, + /// "N-gram similarity and distance". Proceedings of the Twelfth International + /// Conference on String Processing and Information Retrieval (SPIRE 2005), pp. 115-126, + /// Buenos Aires, Argentina, November 2005. /// http://www.cs.ualberta.ca/~kondrak/papers/spire05.pdf - /// + /// /// This implementation uses the position-based optimization to compute partial - /// matches of n-gram sub-strings and adds a null-character prefix of size n-1 - /// so that the first character is contained in the same number of n-grams as - /// a middle character. Null-character prefix matches are discounted so that + /// matches of n-gram sub-strings and adds a null-character prefix of size n-1 + /// so that the first character is contained in the same number of n-grams as + /// a middle character. Null-character prefix matches are discounted so that /// strings with no matching characters will return a distance of 0. /// public class NGramDistance : IStringDistance @@ -115,7 +115,7 @@ public virtual float GetDistance(string source, string target) for (j = 1; j <= tl; j++) { - //construct t_j n-gram + //construct t_j n-gram if (j < n) { for (int ti = 0; ti < n - j; ti++) @@ -165,7 +165,10 @@ public virtual float GetDistance(string source, string target) public override int GetHashCode() { - return 1427 * n * this.GetType().GetHashCode(); + unchecked + { + return 1427 * n * this.GetType().GetHashCode(); + } } public override bool Equals(object obj) @@ -188,4 +191,4 @@ public override string ToString() return "ngram(" + n + ")"; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.TestFramework/Index/BaseTermVectorsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BaseTermVectorsFormatTestCase.cs index 4e99b00efa..689579ab29 100644 --- a/src/Lucene.Net.TestFramework/Index/BaseTermVectorsFormatTestCase.cs +++ b/src/Lucene.Net.TestFramework/Index/BaseTermVectorsFormatTestCase.cs @@ -216,7 +216,10 @@ public override bool Equals(object other) public override int GetHashCode() { - return start + 31 * end; + unchecked + { + return start + 31 * end; + } } public override void CopyTo(IAttribute target) // LUCENENET specific - intentionally expanding target to use IAttribute rather than Attribute diff --git a/src/Lucene.Net.TestFramework/Search/ShardSearchingTestBase.cs b/src/Lucene.Net.TestFramework/Search/ShardSearchingTestBase.cs index 17a9701237..72986281bd 100644 --- a/src/Lucene.Net.TestFramework/Search/ShardSearchingTestBase.cs +++ b/src/Lucene.Net.TestFramework/Search/ShardSearchingTestBase.cs @@ -41,7 +41,7 @@ namespace Lucene.Net.Search /// /// Thrown when the lease for a searcher has expired. /// - // LUCENENET: It is no longer good practice to use binary serialization. + // LUCENENET: It is no longer good practice to use binary serialization. // See: https://github.com/dotnet/corefx/issues/23584#issuecomment-325724568 #if FEATURE_SERIALIZABLE_EXCEPTIONS [Serializable] @@ -96,7 +96,10 @@ public FieldAndShardVersion(int nodeID, long version, string field) public override int GetHashCode() { - return (int)(version * nodeID + field.GetHashCode()); + unchecked + { + return (int)(version * nodeID + field.GetHashCode()); + } } public override bool Equals(object other) @@ -132,7 +135,10 @@ public TermAndShardVersion(int nodeID, long version, Term term) public override int GetHashCode() { - return (int)(version * nodeID + term.GetHashCode()); + unchecked + { + return (int)(version * nodeID + term.GetHashCode()); + } } public override bool Equals(object other) diff --git a/src/Lucene.Net/Analysis/Token.cs b/src/Lucene.Net/Analysis/Token.cs index e4b5f4ecaa..961d91d223 100644 --- a/src/Lucene.Net/Analysis/Token.cs +++ b/src/Lucene.Net/Analysis/Token.cs @@ -417,20 +417,23 @@ public override bool Equals(object obj) public override int GetHashCode() { - int code = base.GetHashCode(); - code = code * 31 + startOffset; - code = code * 31 + endOffset; - code = code * 31 + flags; - code = code * 31 + positionIncrement; - if (type != null) + unchecked { - code = code * 31 + type.GetHashCode(); - } - if (payload != null) - { - code = code * 31 + payload.GetHashCode(); + int code = base.GetHashCode(); + code = code * 31 + startOffset; + code = code * 31 + endOffset; + code = code * 31 + flags; + code = code * 31 + positionIncrement; + if (type != null) + { + code = code * 31 + type.GetHashCode(); + } + if (payload != null) + { + code = code * 31 + payload.GetHashCode(); + } + return code; } - return code; } // like clear() but doesn't clear termBuffer/text diff --git a/src/Lucene.Net/Analysis/TokenAttributes/CharTermAttributeImpl.cs b/src/Lucene.Net/Analysis/TokenAttributes/CharTermAttributeImpl.cs index c8762e7d88..5172965732 100644 --- a/src/Lucene.Net/Analysis/TokenAttributes/CharTermAttributeImpl.cs +++ b/src/Lucene.Net/Analysis/TokenAttributes/CharTermAttributeImpl.cs @@ -380,9 +380,12 @@ private static char[] CreateBuffer(int length) public override int GetHashCode() { - int code = termLength; - code = code * 31 + ArrayUtil.GetHashCode(termBuffer, 0, termLength); - return code; + unchecked + { + int code = termLength; + code = code * 31 + ArrayUtil.GetHashCode(termBuffer, 0, termLength); + return code; + } } public override void Clear() diff --git a/src/Lucene.Net/Analysis/TokenAttributes/OffsetAttributeImpl.cs b/src/Lucene.Net/Analysis/TokenAttributes/OffsetAttributeImpl.cs index 4a16d31817..11ea1ce3a3 100644 --- a/src/Lucene.Net/Analysis/TokenAttributes/OffsetAttributeImpl.cs +++ b/src/Lucene.Net/Analysis/TokenAttributes/OffsetAttributeImpl.cs @@ -81,9 +81,12 @@ public override bool Equals(object other) public override int GetHashCode() { - int code = startOffset; - code = code * 31 + endOffset; - return code; + unchecked + { + int code = startOffset; + code = code * 31 + endOffset; + return code; + } } public override void CopyTo(IAttribute target) // LUCENENET specific - intentionally expanding target to use IAttribute rather than Attribute @@ -96,4 +99,4 @@ public override void CopyTo(IAttribute target) // LUCENENET specific - intention t.SetOffset(startOffset, endOffset); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/IndexCommit.cs b/src/Lucene.Net/Index/IndexCommit.cs index 303aa328ec..ddd11483a8 100644 --- a/src/Lucene.Net/Index/IndexCommit.cs +++ b/src/Lucene.Net/Index/IndexCommit.cs @@ -107,7 +107,10 @@ public override bool Equals(object other) public override int GetHashCode() { - return Directory.GetHashCode() + Generation.GetHashCode(); + unchecked + { + return Directory.GetHashCode() + Generation.GetHashCode(); + } } /// diff --git a/src/Lucene.Net/Index/SegmentInfo.cs b/src/Lucene.Net/Index/SegmentInfo.cs index 5a7f206d45..c643694076 100644 --- a/src/Lucene.Net/Index/SegmentInfo.cs +++ b/src/Lucene.Net/Index/SegmentInfo.cs @@ -238,7 +238,10 @@ public override bool Equals(object obj) public override int GetHashCode() { - return Dir.GetHashCode() + Name.GetHashCode(); + unchecked + { + return Dir.GetHashCode() + Name.GetHashCode(); + } } /// @@ -343,4 +346,4 @@ public string PutAttribute(string key, string value) [Obsolete("no longer supported")] public IDictionary Attributes => attributes; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/Term.cs b/src/Lucene.Net/Index/Term.cs index 6e76a79517..6e245af2a6 100644 --- a/src/Lucene.Net/Index/Term.cs +++ b/src/Lucene.Net/Index/Term.cs @@ -115,11 +115,14 @@ public override bool Equals(object obj) public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + ((Field is null) ? 0 : Field.GetHashCode()); - result = prime * result + ((Bytes is null) ? 0 : Bytes.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + (Field is null ? 0 : Field.GetHashCode()); + result = prime * result + (Bytes is null ? 0 : Bytes.GetHashCode()); + return result; + } } /// diff --git a/src/Lucene.Net/Search/AutomatonQuery.cs b/src/Lucene.Net/Search/AutomatonQuery.cs index 0a4fc5ea84..29031c8ee5 100644 --- a/src/Lucene.Net/Search/AutomatonQuery.cs +++ b/src/Lucene.Net/Search/AutomatonQuery.cs @@ -80,11 +80,14 @@ protected override TermsEnum GetTermsEnum(Terms terms, AttributeSource atts) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + m_compiled.GetHashCode(); - result = prime * result + ((m_term is null) ? 0 : m_term.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + m_compiled.GetHashCode(); + result = prime * result + ((m_term is null) ? 0 : m_term.GetHashCode()); + return result; + } } public override bool Equals(object obj) @@ -141,4 +144,4 @@ public override string ToString(string field) /// Returns the automaton used to create this query public virtual Automaton Automaton => m_automaton; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/BooleanQuery.cs b/src/Lucene.Net/Search/BooleanQuery.cs index c1b9c73718..ce02367358 100644 --- a/src/Lucene.Net/Search/BooleanQuery.cs +++ b/src/Lucene.Net/Search/BooleanQuery.cs @@ -46,22 +46,22 @@ namespace Lucene.Net.Search /// /// Collection initializer note: To create and populate a /// in a single statement, you can use the following example as a guide: - /// + /// /// /// var booleanQuery = new BooleanQuery() { /// { new WildcardQuery(new Term("field2", "foobar")), Occur.SHOULD }, /// { new MultiPhraseQuery() { - /// new Term("field", "microsoft"), + /// new Term("field", "microsoft"), /// new Term("field", "office") /// }, Occur.SHOULD } /// }; - /// + /// /// // or - /// + /// /// var booleanQuery = new BooleanQuery() { /// new BooleanClause(new WildcardQuery(new Term("field2", "foobar")), Occur.SHOULD), /// new BooleanClause(new MultiPhraseQuery() { - /// new Term("field", "microsoft"), + /// new Term("field", "microsoft"), /// new Term("field", "office") /// }, Occur.SHOULD) /// }; @@ -72,12 +72,12 @@ public class BooleanQuery : Query, IEnumerable private static int maxClauseCount = 1024; /// - /// Thrown when an attempt is made to add more than + /// Thrown when an attempt is made to add more than /// clauses. This typically happens if /// a , , , or /// is expanded to many terms during search. /// - // LUCENENET: It is no longer good practice to use binary serialization. + // LUCENENET: It is no longer good practice to use binary serialization. // See: https://github.com/dotnet/corefx/issues/23584#issuecomment-325724568 #if FEATURE_SERIALIZABLE_EXCEPTIONS [Serializable] @@ -107,7 +107,7 @@ protected TooManyClausesException(SerializationInfo info, StreamingContext conte /// /// Return the maximum number of clauses permitted, 1024 by default. - /// Attempts to add more than the permitted number of clauses cause + /// Attempts to add more than the permitted number of clauses cause /// to be thrown. public static int MaxClauseCount { @@ -137,7 +137,7 @@ public BooleanQuery() /// /// may be disabled in scoring, as /// appropriate. For example, this score factor does not make sense for most - /// automatically generated queries, like and + /// automatically generated queries, like and /// . /// /// Disables in scoring. @@ -694,8 +694,11 @@ public override bool Equals(object o) /// Returns a hash code value for this object. public override int GetHashCode() { - return BitConversion.SingleToInt32Bits(Boost) ^ clauses.GetHashCode() - + MinimumNumberShouldMatch + (disableCoord ? 17 : 0); + unchecked + { + return BitConversion.SingleToInt32Bits(Boost) ^ clauses.GetHashCode() + + MinimumNumberShouldMatch + (disableCoord ? 17 : 0); + } } } } diff --git a/src/Lucene.Net/Search/ConstantScoreAutoRewrite.cs b/src/Lucene.Net/Search/ConstantScoreAutoRewrite.cs index 3495bbc5fd..083c9d3b60 100644 --- a/src/Lucene.Net/Search/ConstantScoreAutoRewrite.cs +++ b/src/Lucene.Net/Search/ConstantScoreAutoRewrite.cs @@ -36,13 +36,13 @@ namespace Lucene.Net.Search /// A rewrite method that tries to pick the best /// constant-score rewrite method based on term and /// document counts from the query. If both the number of - /// terms and documents is small enough, then + /// terms and documents is small enough, then /// is used. /// Otherwise, is /// used. /// - // LUCENENET specific: made this class public. In Lucene there was a derived class - // with the same name that was nested within MultiTermQuery, but in .NET it is + // LUCENENET specific: made this class public. In Lucene there was a derived class + // with the same name that was nested within MultiTermQuery, but in .NET it is // more intuitive if our classes are not nested. public class ConstantScoreAutoRewrite : TermCollectingRewrite { @@ -64,7 +64,7 @@ public class ConstantScoreAutoRewrite : TermCollectingRewrite /// /// If the number of terms in this query is equal to or - /// larger than this setting then + /// larger than this setting then /// is used. /// public virtual int TermCountCutoff @@ -77,7 +77,7 @@ public virtual int TermCountCutoff /// If the number of documents to be visited in the /// postings exceeds this specified percentage of the /// for the index, then - /// is used. + /// is used. /// Value may be 0.0 to 100.0. /// public virtual double DocCountPercent @@ -183,8 +183,11 @@ public override bool Collect(BytesRef bytes) public override int GetHashCode() { - const int prime = 1279; - return (int)(prime * termCountCutoff + J2N.BitConversion.DoubleToInt64Bits(docCountPercent)); + unchecked + { + const int prime = 1279; + return (int)(prime * termCountCutoff + J2N.BitConversion.DoubleToInt64Bits(docCountPercent)); + } } public override bool Equals(object obj) @@ -255,4 +258,4 @@ public override int[] Clear() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/ConstantScoreQuery.cs b/src/Lucene.Net/Search/ConstantScoreQuery.cs index dd07a0f4da..c12caa140f 100644 --- a/src/Lucene.Net/Search/ConstantScoreQuery.cs +++ b/src/Lucene.Net/Search/ConstantScoreQuery.cs @@ -267,7 +267,7 @@ public CollectorAnonymousClass(ConstantBulkScorer outerInstance, ICollector coll this.outerInstance = outerInstance; this.collector = collector; } - + public void SetScorer(Scorer scorer) { // we must wrap again here, but using the value passed in as parameter: @@ -371,7 +371,10 @@ public override bool Equals(object o) public override int GetHashCode() { - return 31 * base.GetHashCode() + (m_query ?? (object)m_filter).GetHashCode(); + unchecked + { + return 31 * base.GetHashCode() + (m_query ?? (object)m_filter).GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/DisjunctionMaxQuery.cs b/src/Lucene.Net/Search/DisjunctionMaxQuery.cs index 327492ff62..9bd483df6c 100644 --- a/src/Lucene.Net/Search/DisjunctionMaxQuery.cs +++ b/src/Lucene.Net/Search/DisjunctionMaxQuery.cs @@ -48,10 +48,10 @@ namespace Lucene.Net.Search /// /// Collection initializer note: To create and populate a /// in a single statement, you can use the following example as a guide: - /// + /// /// /// var disjunctionMaxQuery = new DisjunctionMaxQuery(0.1f) { - /// new TermQuery(new Term("field1", "albino")), + /// new TermQuery(new Term("field1", "albino")), /// new TermQuery(new Term("field2", "elephant")) /// }; /// @@ -99,9 +99,9 @@ public virtual void Add(Query query) /// /// Add a collection of disjuncts to this disjunction - /// via + /// via /// - /// NOTE: When overriding this method, be aware that the constructor of this class calls + /// NOTE: When overriding this method, be aware that the constructor of this class calls /// a private method and not this virtual method. So if you need to override /// the behavior during the initialization, call your own private method from the constructor /// with whatever custom behavior you need. @@ -377,9 +377,12 @@ public override bool Equals(object o) /// the hash code public override int GetHashCode() { - return J2N.BitConversion.SingleToInt32Bits(Boost) - + J2N.BitConversion.SingleToInt32Bits(tieBreakerMultiplier) - + disjuncts.GetHashCode(); + unchecked + { + return J2N.BitConversion.SingleToInt32Bits(Boost) + + J2N.BitConversion.SingleToInt32Bits(tieBreakerMultiplier) + + disjuncts.GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/FieldValueFilter.cs b/src/Lucene.Net/Search/FieldValueFilter.cs index e820ab6725..d316c363b8 100644 --- a/src/Lucene.Net/Search/FieldValueFilter.cs +++ b/src/Lucene.Net/Search/FieldValueFilter.cs @@ -99,11 +99,14 @@ public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDo public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + ((field is null) ? 0 : field.GetHashCode()); - result = prime * result + (negate ? 1231 : 1237); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + (field is null ? 0 : field.GetHashCode()); + result = prime * result + (negate ? 1231 : 1237); + return result; + } } public override bool Equals(object obj) @@ -144,4 +147,4 @@ public override string ToString() return "FieldValueFilter [field=" + field + ", negate=" + negate + "]"; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/FilteredQuery.cs b/src/Lucene.Net/Search/FilteredQuery.cs index 7e445970d9..39726947fa 100644 --- a/src/Lucene.Net/Search/FilteredQuery.cs +++ b/src/Lucene.Net/Search/FilteredQuery.cs @@ -452,11 +452,14 @@ public override bool Equals(object o) /// Returns a hash code value for this object. public override int GetHashCode() { - int hash = base.GetHashCode(); - hash = hash * 31 + strategy.GetHashCode(); - hash = hash * 31 + query.GetHashCode(); - hash = hash * 31 + filter.GetHashCode(); - return hash; + unchecked + { + int hash = base.GetHashCode(); + hash = hash * 31 + strategy.GetHashCode(); + hash = hash * 31 + query.GetHashCode(); + hash = hash * 31 + filter.GetHashCode(); + return hash; + } } /// @@ -693,4 +696,4 @@ public override BulkScorer FilteredBulkScorer(AtomicReaderContext context, Weigh } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/FuzzyQuery.cs b/src/Lucene.Net/Search/FuzzyQuery.cs index a9f8cdf574..13557673e7 100644 --- a/src/Lucene.Net/Search/FuzzyQuery.cs +++ b/src/Lucene.Net/Search/FuzzyQuery.cs @@ -178,14 +178,17 @@ public override string ToString(string field) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + maxEdits; - result = prime * result + prefixLength; - result = prime * result + maxExpansions; - result = prime * result + (transpositions ? 0 : 1); - result = prime * result + ((term is null) ? 0 : term.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + maxEdits; + result = prime * result + prefixLength; + result = prime * result + maxExpansions; + result = prime * result + (transpositions ? 0 : 1); + result = prime * result + ((term is null) ? 0 : term.GetHashCode()); + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net/Search/MultiTermQuery.cs b/src/Lucene.Net/Search/MultiTermQuery.cs index f0878d47cc..316be824e6 100644 --- a/src/Lucene.Net/Search/MultiTermQuery.cs +++ b/src/Lucene.Net/Search/MultiTermQuery.cs @@ -319,15 +319,18 @@ public virtual RewriteMethod MultiTermRewriteMethod public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + J2N.BitConversion.SingleToInt32Bits(Boost); - result = prime * result + m_rewriteMethod.GetHashCode(); - if (m_field != null) + unchecked { - result = prime * result + m_field.GetHashCode(); + const int prime = 31; + int result = 1; + result = prime * result + J2N.BitConversion.SingleToInt32Bits(Boost); + result = prime * result + m_rewriteMethod.GetHashCode(); + if (m_field != null) + { + result = prime * result + m_field.GetHashCode(); + } + return result; } - return result; } public override bool Equals(object obj) diff --git a/src/Lucene.Net/Search/NumericRangeQuery.cs b/src/Lucene.Net/Search/NumericRangeQuery.cs index 043fa071dc..e0c330aad1 100644 --- a/src/Lucene.Net/Search/NumericRangeQuery.cs +++ b/src/Lucene.Net/Search/NumericRangeQuery.cs @@ -249,17 +249,20 @@ public override bool Equals(object o) public override int GetHashCode() { - int hash = base.GetHashCode(); - hash += precisionStep ^ 0x64365465; - if (min != null) + unchecked { - hash += min.GetHashCode() ^ 0x14fa55fb; - } - if (max != null) - { - hash += max.GetHashCode() ^ 0x733fa5fe; + int hash = base.GetHashCode(); + hash += precisionStep ^ 0x64365465; + if (min != null) + { + hash += min.GetHashCode() ^ 0x14fa55fb; + } + if (max != null) + { + hash += max.GetHashCode() ^ 0x733fa5fe; + } + return hash + (minInclusive.GetHashCode() ^ 0x14fa55fb) + (maxInclusive.GetHashCode() ^ 0x733fa5fe); } - return hash + (minInclusive.GetHashCode() ^ 0x14fa55fb) + (maxInclusive.GetHashCode() ^ 0x733fa5fe); } // members (package private, to be also fast accessible by NumericRangeTermEnum) diff --git a/src/Lucene.Net/Search/Payloads/AveragePayloadFunction.cs b/src/Lucene.Net/Search/Payloads/AveragePayloadFunction.cs index 859300e8d7..59df2e0ec6 100644 --- a/src/Lucene.Net/Search/Payloads/AveragePayloadFunction.cs +++ b/src/Lucene.Net/Search/Payloads/AveragePayloadFunction.cs @@ -36,10 +36,13 @@ public override float DocScore(int docId, string field, int numPayloadsSeen, flo public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + this.GetType().GetHashCode(); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + this.GetType().GetHashCode(); + return result; + } } public override bool Equals(object obj) @@ -59,4 +62,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/Payloads/MaxPayloadFunction.cs b/src/Lucene.Net/Search/Payloads/MaxPayloadFunction.cs index 4d5a908a84..6c71ed821f 100644 --- a/src/Lucene.Net/Search/Payloads/MaxPayloadFunction.cs +++ b/src/Lucene.Net/Search/Payloads/MaxPayloadFunction.cs @@ -45,10 +45,13 @@ public override float DocScore(int docId, string field, int numPayloadsSeen, flo public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + this.GetType().GetHashCode(); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + this.GetType().GetHashCode(); + return result; + } } public override bool Equals(object obj) @@ -68,4 +71,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/Payloads/MinPayloadFunction.cs b/src/Lucene.Net/Search/Payloads/MinPayloadFunction.cs index d052318a9d..b7f262b426 100644 --- a/src/Lucene.Net/Search/Payloads/MinPayloadFunction.cs +++ b/src/Lucene.Net/Search/Payloads/MinPayloadFunction.cs @@ -43,10 +43,13 @@ public override float DocScore(int docId, string field, int numPayloadsSeen, flo public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + this.GetType().GetHashCode(); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + this.GetType().GetHashCode(); + return result; + } } public override bool Equals(object obj) @@ -66,4 +69,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/Payloads/PayloadNearQuery.cs b/src/Lucene.Net/Search/Payloads/PayloadNearQuery.cs index 00a2ba1a8b..816dc404dd 100644 --- a/src/Lucene.Net/Search/Payloads/PayloadNearQuery.cs +++ b/src/Lucene.Net/Search/Payloads/PayloadNearQuery.cs @@ -109,11 +109,14 @@ public override string ToString(string field) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + ((m_fieldName is null) ? 0 : m_fieldName.GetHashCode()); - result = prime * result + ((m_function is null) ? 0 : m_function.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (m_fieldName is null ? 0 : m_fieldName.GetHashCode()); + result = prime * result + (m_function is null ? 0 : m_function.GetHashCode()); + return result; + } } public override bool Equals(object obj) @@ -300,4 +303,4 @@ public override float GetScore() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/Payloads/PayloadTermQuery.cs b/src/Lucene.Net/Search/Payloads/PayloadTermQuery.cs index b9f9d82e3f..db77c5788a 100644 --- a/src/Lucene.Net/Search/Payloads/PayloadTermQuery.cs +++ b/src/Lucene.Net/Search/Payloads/PayloadTermQuery.cs @@ -225,11 +225,14 @@ public override Explanation Explain(AtomicReaderContext context, int doc) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + ((m_function is null) ? 0 : m_function.GetHashCode()); - result = prime * result + (includeSpanScore ? 1231 : 1237); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (m_function is null ? 0 : m_function.GetHashCode()); + result = prime * result + (includeSpanScore ? 1231 : 1237); + return result; + } } public override bool Equals(object obj) @@ -265,4 +268,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/PhraseQuery.cs b/src/Lucene.Net/Search/PhraseQuery.cs index b0fe262ce0..200b6bf936 100644 --- a/src/Lucene.Net/Search/PhraseQuery.cs +++ b/src/Lucene.Net/Search/PhraseQuery.cs @@ -52,10 +52,10 @@ namespace Lucene.Net.Search /// /// Collection initializer note: To create and populate a /// in a single statement, you can use the following example as a guide: - /// + /// /// /// var phraseQuery = new PhraseQuery() { - /// new Term("field", "microsoft"), + /// new Term("field", "microsoft"), /// new Term("field", "office") /// }; /// @@ -251,15 +251,18 @@ public virtual int CompareTo(PostingsAndFreq other) public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + docFreq; - result = prime * result + position; - for (int i = 0; i < nTerms; i++) + unchecked { - result = prime * result + terms[i].GetHashCode(); + const int prime = 31; + int result = 1; + result = prime * result + docFreq; + result = prime * result + position; + for (int i = 0; i < nTerms; i++) + { + result = prime * result + terms[i].GetHashCode(); + } + return result; } - return result; } public override bool Equals(object obj) @@ -300,7 +303,7 @@ private class PhraseWeight : Weight internal readonly Similarity similarity; internal readonly Similarity.SimWeight stats; - + internal TermContext[] states; public PhraseWeight(PhraseQuery outerInstance, IndexSearcher searcher) @@ -506,9 +509,9 @@ public override bool Equals(object o) } PhraseQuery other = (PhraseQuery)o; // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled - return (NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost)) - && (this.slop == other.slop) - && this.terms.Equals(other.terms) + return (NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost)) + && (this.slop == other.slop) + && this.terms.Equals(other.terms) && this.positions.Equals(other.positions); } @@ -516,9 +519,9 @@ public override bool Equals(object o) /// Returns a hash code value for this object. public override int GetHashCode() { - return J2N.BitConversion.SingleToInt32Bits(Boost) - ^ slop - ^ terms.GetHashCode() + return J2N.BitConversion.SingleToInt32Bits(Boost) + ^ slop + ^ terms.GetHashCode() ^ positions.GetHashCode(); } @@ -542,4 +545,4 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/PrefixQuery.cs b/src/Lucene.Net/Search/PrefixQuery.cs index b0728f3d8e..dde43d4d62 100644 --- a/src/Lucene.Net/Search/PrefixQuery.cs +++ b/src/Lucene.Net/Search/PrefixQuery.cs @@ -80,10 +80,13 @@ public override string ToString(string field) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + ((_prefix is null) ? 0 : _prefix.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (_prefix is null ? 0 : _prefix.GetHashCode()); + return result; + } } public override bool Equals(object obj) @@ -115,4 +118,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/Query.cs b/src/Lucene.Net/Search/Query.cs index b9a37b821b..edf283de45 100644 --- a/src/Lucene.Net/Search/Query.cs +++ b/src/Lucene.Net/Search/Query.cs @@ -116,10 +116,13 @@ public virtual object Clone() public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + J2N.BitConversion.SingleToInt32Bits(Boost); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + J2N.BitConversion.SingleToInt32Bits(Boost); + return result; + } } public override bool Equals(object obj) @@ -148,4 +151,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/Sort.cs b/src/Lucene.Net/Search/Sort.cs index db18a29ab8..133bc18101 100644 --- a/src/Lucene.Net/Search/Sort.cs +++ b/src/Lucene.Net/Search/Sort.cs @@ -142,7 +142,7 @@ public Sort(params SortField[] fields) /// /// Sets the sort to the given criteria. /// - /// NOTE: When overriding this method, be aware that the constructor of this class calls + /// NOTE: When overriding this method, be aware that the constructor of this class calls /// a private method and not this virtual method. So if you need to override /// the behavior during the initialization, call your own private method from the constructor /// with whatever custom behavior you need. @@ -152,7 +152,7 @@ public Sort(params SortField[] fields) /// /// Sets the sort to the given criteria in succession. /// - /// NOTE: When overriding this method, be aware that the constructor of this class calls + /// NOTE: When overriding this method, be aware that the constructor of this class calls /// a private method and not this virtual method. So if you need to override /// the behavior during the initialization, call your own private method from the constructor /// with whatever custom behavior you need. @@ -233,7 +233,10 @@ public override bool Equals(object o) /// Returns a hash code value for this object. public override int GetHashCode() { - return 0x45aaf665 + Arrays.GetHashCode(fields); + unchecked + { + return 0x45aaf665 + Arrays.GetHashCode(fields); + } } /// @@ -253,4 +256,4 @@ public virtual bool NeedsScores } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/SortField.cs b/src/Lucene.Net/Search/SortField.cs index af8951da42..0674b7a33a 100644 --- a/src/Lucene.Net/Search/SortField.cs +++ b/src/Lucene.Net/Search/SortField.cs @@ -406,16 +406,19 @@ public override bool Equals(object o) /// public override int GetHashCode() { - int hash = (int)(type.GetHashCode() ^ 0x346565dd + reverse.GetHashCode() ^ 0xaf5998bb); - if (field != null) + unchecked { - hash += (int)(field.GetHashCode() ^ 0xff5685dd); - } - if (comparerSource != null) - { - hash += comparerSource.GetHashCode(); + int hash = (int)(type.GetHashCode() ^ 0x346565dd + reverse.GetHashCode() ^ 0xaf5998bb); + if (field != null) + { + hash += (int)(field.GetHashCode() ^ 0xff5685dd); + } + if (comparerSource != null) + { + hash += comparerSource.GetHashCode(); + } + return hash; } - return hash; } private IComparer bytesComparer = BytesRef.UTF8SortedAsUnicodeComparer; diff --git a/src/Lucene.Net/Search/Spans/SpanMultiTermQueryWrapper.cs b/src/Lucene.Net/Search/Spans/SpanMultiTermQueryWrapper.cs index d0fb363ee6..9b0f8c6a70 100644 --- a/src/Lucene.Net/Search/Spans/SpanMultiTermQueryWrapper.cs +++ b/src/Lucene.Net/Search/Spans/SpanMultiTermQueryWrapper.cs @@ -125,10 +125,13 @@ public override Query Rewrite(IndexReader reader) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + m_query.GetHashCode(); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + m_query.GetHashCode(); + return result; + } } public override bool Equals(object obj) @@ -255,7 +258,10 @@ public override Query Rewrite(IndexReader reader, MultiTermQuery query) public override int GetHashCode() { - return 31 * @delegate.GetHashCode(); + unchecked + { + return 31 * @delegate.GetHashCode(); + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net/Search/Spans/SpanNearQuery.cs b/src/Lucene.Net/Search/Spans/SpanNearQuery.cs index f14e8c5f5e..bceb272c84 100644 --- a/src/Lucene.Net/Search/Spans/SpanNearQuery.cs +++ b/src/Lucene.Net/Search/Spans/SpanNearQuery.cs @@ -215,16 +215,19 @@ public override bool Equals(object o) public override int GetHashCode() { - int result; - result = JCG.ListEqualityComparer.Default.GetHashCode(m_clauses); - // 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 += J2N.BitConversion.SingleToRawInt32Bits(Boost); - result += m_slop; - result ^= (m_inOrder ? unchecked((int)0x99AFD3BD) : 0); - return result; + unchecked + { + int result; + result = JCG.ListEqualityComparer.Default.GetHashCode(m_clauses); + // 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 += J2N.BitConversion.SingleToRawInt32Bits(Boost); + result += m_slop; + result ^= (m_inOrder ? unchecked((int)0x99AFD3BD) : 0); + return result; + } } } } diff --git a/src/Lucene.Net/Search/Spans/SpanTermQuery.cs b/src/Lucene.Net/Search/Spans/SpanTermQuery.cs index b888bc014f..0ee78daff5 100644 --- a/src/Lucene.Net/Search/Spans/SpanTermQuery.cs +++ b/src/Lucene.Net/Search/Spans/SpanTermQuery.cs @@ -74,10 +74,13 @@ public override string ToString(string field) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + ((m_term is null) ? 0 : m_term.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (m_term is null ? 0 : m_term.GetHashCode()); + return result; + } } public override bool Equals(object obj) @@ -168,4 +171,4 @@ public override Spans GetSpans(AtomicReaderContext context, IBits acceptDocs, ID } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/TermRangeQuery.cs b/src/Lucene.Net/Search/TermRangeQuery.cs index 0c97855a26..55908753ff 100644 --- a/src/Lucene.Net/Search/TermRangeQuery.cs +++ b/src/Lucene.Net/Search/TermRangeQuery.cs @@ -31,7 +31,7 @@ namespace Lucene.Net.Search /// A that matches documents within an range of terms. /// /// This query matches the documents looking for terms that fall into the - /// supplied range according to + /// supplied range according to /// . It is not intended /// for numerical ranges; use instead. /// @@ -143,13 +143,16 @@ public override string ToString(string field) public override int GetHashCode() { - const int prime = 31; - int result = base.GetHashCode(); - result = prime * result + (includeLower ? 1231 : 1237); - result = prime * result + (includeUpper ? 1231 : 1237); - result = prime * result + ((lowerTerm is null) ? 0 : lowerTerm.GetHashCode()); - result = prime * result + ((upperTerm is null) ? 0 : upperTerm.GetHashCode()); - return result; + unchecked + { + const int prime = 31; + int result = base.GetHashCode(); + result = prime * result + (includeLower ? 1231 : 1237); + result = prime * result + (includeUpper ? 1231 : 1237); + result = prime * result + ((lowerTerm is null) ? 0 : lowerTerm.GetHashCode()); + result = prime * result + ((upperTerm is null) ? 0 : upperTerm.GetHashCode()); + return result; + } } public override bool Equals(object obj) @@ -200,4 +203,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/TopTermsRewrite.cs b/src/Lucene.Net/Search/TopTermsRewrite.cs index d7c85f588e..5c5afecff3 100644 --- a/src/Lucene.Net/Search/TopTermsRewrite.cs +++ b/src/Lucene.Net/Search/TopTermsRewrite.cs @@ -218,7 +218,10 @@ public override bool Collect(BytesRef bytes) public override int GetHashCode() { - return 31 * size; + unchecked + { + return 31 * size; + } } public override bool Equals(object obj) @@ -251,7 +254,7 @@ public override bool Equals(object obj) if (Debugging.AssertsEnabled) Debugging.Assert(st1.TermComp == st2.TermComp, "term comparer should not change between segments"); return st1.TermComp.Compare(st1.Bytes, st2.Bytes); }); - + internal sealed class ScoreTerm : IComparable { public IComparer TermComp { get; private set; } @@ -280,4 +283,4 @@ public int CompareTo(ScoreTerm other) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Store/FlushInfo.cs b/src/Lucene.Net/Store/FlushInfo.cs index 7835b7cb63..779e2e1d2c 100644 --- a/src/Lucene.Net/Store/FlushInfo.cs +++ b/src/Lucene.Net/Store/FlushInfo.cs @@ -41,11 +41,14 @@ public FlushInfo(int numDocs, long estimatedSegmentSize) public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + (int)(EstimatedSegmentSize ^ (EstimatedSegmentSize >>> 32)); - result = prime * result + NumDocs; - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + (int)(EstimatedSegmentSize ^ (EstimatedSegmentSize >>> 32)); + result = prime * result + NumDocs; + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net/Store/IOContext.cs b/src/Lucene.Net/Store/IOContext.cs index 9d94a8c8cc..073109f581 100644 --- a/src/Lucene.Net/Store/IOContext.cs +++ b/src/Lucene.Net/Store/IOContext.cs @@ -119,13 +119,16 @@ public IOContext(IOContext ctxt, bool readOnce) public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + /*((Context is null) ? 0 :*/ Context.GetHashCode()/*)*/; // LUCENENET NOTE: Enum can never be null in .NET - result = prime * result + ((FlushInfo is null) ? 0 : FlushInfo.GetHashCode()); - result = prime * result + ((MergeInfo is null) ? 0 : MergeInfo.GetHashCode()); - result = prime * result + (ReadOnce ? 1231 : 1237); - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + /*((Context is null) ? 0 :*/ Context.GetHashCode()/*)*/; // LUCENENET NOTE: Enum can never be null in .NET + result = prime * result + (FlushInfo is null ? 0 : FlushInfo.GetHashCode()); + result = prime * result + (MergeInfo is null ? 0 : MergeInfo.GetHashCode()); + result = prime * result + (ReadOnce ? 1231 : 1237); + return result; + } } public override bool Equals(object obj) @@ -181,4 +184,4 @@ public override string ToString() return "IOContext [context=" + Context + ", mergeInfo=" + MergeInfo + ", flushInfo=" + FlushInfo + ", readOnce=" + ReadOnce + "]"; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Store/MergeInfo.cs b/src/Lucene.Net/Store/MergeInfo.cs index 5d95aca276..716085e47d 100644 --- a/src/Lucene.Net/Store/MergeInfo.cs +++ b/src/Lucene.Net/Store/MergeInfo.cs @@ -47,14 +47,17 @@ public MergeInfo(int totalDocCount, long estimatedMergeBytes, bool isExternal, i public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result - + (int)(EstimatedMergeBytes ^ (EstimatedMergeBytes >>> 32)); - result = prime * result + (IsExternal ? 1231 : 1237); - result = prime * result + MergeMaxNumSegments; - result = prime * result + TotalDocCount; - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + + (int)(EstimatedMergeBytes ^ (EstimatedMergeBytes >>> 32)); + result = prime * result + (IsExternal ? 1231 : 1237); + result = prime * result + MergeMaxNumSegments; + result = prime * result + TotalDocCount; + return result; + } } public override bool Equals(object obj) diff --git a/src/Lucene.Net/Util/ArrayUtil.cs b/src/Lucene.Net/Util/ArrayUtil.cs index 2694f189dc..0c7759bde7 100644 --- a/src/Lucene.Net/Util/ArrayUtil.cs +++ b/src/Lucene.Net/Util/ArrayUtil.cs @@ -64,7 +64,7 @@ public static int ParseInt32(char[] chars) } /// - /// Parses a char array into an . + /// Parses a char array into an . /// /// NOTE: This was parseInt() in Lucene /// @@ -638,12 +638,15 @@ public static float[][] Shrink(float[][] array, int targetSize) /// public static int GetHashCode(char[] array, int start, int end) { - int code = 0; - for (int i = end - 1; i >= start; i--) + unchecked { - code = code * 31 + array[i]; + int code = 0; + for (int i = end - 1; i >= start; i--) + { + code = code * 31 + array[i]; + } + return code; } - return code; } /// @@ -652,12 +655,15 @@ public static int GetHashCode(char[] array, int start, int end) /// public static int GetHashCode(byte[] array, int start, int end) { - int code = 0; - for (int i = end - 1; i >= start; i--) + unchecked { - code = code * 31 + array[i]; + int code = 0; + for (int i = end - 1; i >= start; i--) + { + code = code * 31 + array[i]; + } + return code; } - return code; } // Since Arrays.equals doesn't implement offsets for equals @@ -773,7 +779,7 @@ public static bool Equals(int[] left, int offsetLeft, int[] right, int offsetRig return false; } - // LUCENENET: The toIntArray() method was only here to convert Integer[] to int[] in Java, but is not necessary when dealing with + // LUCENENET: The toIntArray() method was only here to convert Integer[] to int[] in Java, but is not necessary when dealing with /// /// NOTE: This was toIntArray() in Lucene @@ -972,4 +978,4 @@ public static void TimSort(T[] a) //where T : IComparable // LUCENENET sp TimSort(a, 0, a.Length); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/AttributeSource.cs b/src/Lucene.Net/Util/AttributeSource.cs index f9dc35a5c2..0c2946a5da 100644 --- a/src/Lucene.Net/Util/AttributeSource.cs +++ b/src/Lucene.Net/Util/AttributeSource.cs @@ -396,9 +396,9 @@ public void AddAttributeImpl(Attribute att) /// /// The caller must pass in an interface type that extends . - /// This method first checks if an instance of the corresponding class is + /// This method first checks if an instance of the corresponding class is /// already in this and returns it. Otherwise a - /// new instance is created, added to this and returned. + /// new instance is created, added to this and returned. /// public T AddAttribute() where T : IAttribute @@ -532,12 +532,15 @@ public void RestoreState(State state) public override int GetHashCode() { - int code = 0; - for (State state = GetCurrentState(); state != null; state = state.next) + unchecked { - code = code * 31 + state.attribute.GetHashCode(); + int code = 0; + for (State state = GetCurrentState(); state != null; state = state.next) + { + code = code * 31 + state.attribute.GetHashCode(); + } + return code; } - return code; } public override bool Equals(object obj) @@ -721,4 +724,4 @@ public override string ToString() return this.GetType().Name + '@' + RuntimeHelpers.GetHashCode(this).ToString("x") + " " + ReflectAsString(false); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/Automaton/Automaton.cs b/src/Lucene.Net/Util/Automaton/Automaton.cs index 784cf24499..2261ae996e 100644 --- a/src/Lucene.Net/Util/Automaton/Automaton.cs +++ b/src/Lucene.Net/Util/Automaton/Automaton.cs @@ -646,7 +646,10 @@ public override int GetHashCode() visited.Add(this.initial); while (worklist.TryDequeue(out State current)) { - hash = 31 * hash + current.accept.GetHashCode(); + unchecked + { + hash = 31 * hash + current.accept.GetHashCode(); + } Transition[] t1 = transitions[current.number]; @@ -654,8 +657,11 @@ public override int GetHashCode() { int min1 = t1[n1].min, max1 = t1[n1].max; - hash = 31 * hash + min1.GetHashCode(); - hash = 31 * hash + max1.GetHashCode(); + unchecked + { + hash = 31 * hash + min1.GetHashCode(); + hash = 31 * hash + max1.GetHashCode(); + } State next = t1[n1].to; if (!visited.Contains(next)) diff --git a/src/Lucene.Net/Util/Automaton/CompiledAutomaton.cs b/src/Lucene.Net/Util/Automaton/CompiledAutomaton.cs index 171942d214..7db8353a88 100644 --- a/src/Lucene.Net/Util/Automaton/CompiledAutomaton.cs +++ b/src/Lucene.Net/Util/Automaton/CompiledAutomaton.cs @@ -452,12 +452,15 @@ public virtual string ToDot() public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + ((RunAutomaton is null) ? 0 : RunAutomaton.GetHashCode()); - result = prime * result + ((Term is null) ? 0 : Term.GetHashCode()); - result = prime * result + Type.GetHashCode(); //((Type is null) ? 0 : Type.GetHashCode()); // LUCENENET NOTE: Enum cannot be null in .NET - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + (RunAutomaton is null ? 0 : RunAutomaton.GetHashCode()); + result = prime * result + (Term is null ? 0 : Term.GetHashCode()); + result = prime * result + Type.GetHashCode(); //((Type is null) ? 0 : Type.GetHashCode()); // LUCENENET NOTE: Enum cannot be null in .NET + return result; + } } public override bool Equals(object obj) @@ -497,4 +500,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/Automaton/DaciukMihovAutomatonBuilder.cs b/src/Lucene.Net/Util/Automaton/DaciukMihovAutomatonBuilder.cs index b3ec75e560..4772f2ba4b 100644 --- a/src/Lucene.Net/Util/Automaton/DaciukMihovAutomatonBuilder.cs +++ b/src/Lucene.Net/Util/Automaton/DaciukMihovAutomatonBuilder.cs @@ -98,26 +98,29 @@ public override bool Equals(object obj) /// public override int GetHashCode() { - int hash = is_final ? 1 : 0; - - hash ^= hash * 31 + this.labels.Length; - foreach (int c in this.labels) + unchecked { - hash ^= hash * 31 + c; - } + int hash = is_final ? 1 : 0; - /* - * Compare the right-language of this state using reference-identity of - * outgoing states. this is possible because states are interned (stored - * in registry) and traversed in post-order, so any outgoing transitions - * are already interned. - */ - foreach (State s in this.states) - { - hash ^= s.GetHashCode(); - } + hash ^= hash * 31 + this.labels.Length; + foreach (int c in this.labels) + { + hash ^= hash * 31 + c; + } - return hash; + /* + * Compare the right-language of this state using reference-identity of + * outgoing states. this is possible because states are interned (stored + * in registry) and traversed in post-order, so any outgoing transitions + * are already interned. + */ + foreach (State s in this.states) + { + hash ^= s.GetHashCode(); + } + + return hash; + } } /// diff --git a/src/Lucene.Net/Util/Automaton/RunAutomaton.cs b/src/Lucene.Net/Util/Automaton/RunAutomaton.cs index 6ed88a033b..bedf227dbd 100644 --- a/src/Lucene.Net/Util/Automaton/RunAutomaton.cs +++ b/src/Lucene.Net/Util/Automaton/RunAutomaton.cs @@ -216,13 +216,16 @@ public int Step(int state, int c) public override int GetHashCode() { - const int prime = 31; - int result = 1; - result = prime * result + m_initial; - result = prime * result + _maxInterval; - result = prime * result + _points.Length; - result = prime * result + _size; - return result; + unchecked + { + const int prime = 31; + int result = 1; + result = prime * result + m_initial; + result = prime * result + _maxInterval; + result = prime * result + _points.Length; + result = prime * result + _size; + return result; + } } public override bool Equals(object obj) @@ -267,4 +270,4 @@ public override bool Equals(object obj) return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/Automaton/StatePair.cs b/src/Lucene.Net/Util/Automaton/StatePair.cs index f6e06c1f3d..79d1e168ff 100644 --- a/src/Lucene.Net/Util/Automaton/StatePair.cs +++ b/src/Lucene.Net/Util/Automaton/StatePair.cs @@ -97,7 +97,10 @@ public override bool Equals(object obj) [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { - return s1.GetHashCode() + s2.GetHashCode(); + unchecked + { + return s1.GetHashCode() + s2.GetHashCode(); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/Automaton/Transition.cs b/src/Lucene.Net/Util/Automaton/Transition.cs index 9ae21a7c4a..f46e9932a5 100644 --- a/src/Lucene.Net/Util/Automaton/Transition.cs +++ b/src/Lucene.Net/Util/Automaton/Transition.cs @@ -128,7 +128,10 @@ public override bool Equals(object obj) [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { - return min * 2 + max * 3; + unchecked + { + return min * 2 + max * 3; + } } /// @@ -252,7 +255,7 @@ public int Compare(Transition t1, Transition t2) return 0; } } - + // LUCENENET NOTE: Renamed to follow convention of static fields/constants public static readonly IComparer COMPARE_BY_DEST_THEN_MIN_MAX = new CompareByDestThenMinMaxSingle(); @@ -295,4 +298,4 @@ public int Compare(Transition t1, Transition t2) // LUCENENET NOTE: Renamed to follow convention of static fields/constants public static readonly IComparer COMPARE_BY_MIN_MAX_THEN_DEST = new CompareByMinMaxThenDestSingle(); } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/CharsRef.cs b/src/Lucene.Net/Util/CharsRef.cs index 48a35debbe..acbae18ebd 100644 --- a/src/Lucene.Net/Util/CharsRef.cs +++ b/src/Lucene.Net/Util/CharsRef.cs @@ -122,14 +122,17 @@ public object Clone() public override int GetHashCode() { - const int prime = 31; - int result = 0; - int end = Offset + Length; - for (int i = Offset; i < end; i++) + unchecked { - result = prime * result + chars[i]; + const int prime = 31; + int result = 0; + int end = Offset + Length; + for (int i = Offset; i < end; i++) + { + result = prime * result + chars[i]; + } + return result; } - return result; } public override bool Equals(object other) diff --git a/src/Lucene.Net/Util/FieldCacheSanityChecker.cs b/src/Lucene.Net/Util/FieldCacheSanityChecker.cs index 6253f8cd51..567fa020cc 100644 --- a/src/Lucene.Net/Util/FieldCacheSanityChecker.cs +++ b/src/Lucene.Net/Util/FieldCacheSanityChecker.cs @@ -343,7 +343,10 @@ public ReaderField(object readerKey, string fieldName) [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { - return RuntimeHelpers.GetHashCode(readerKey) * FieldName.GetHashCode(); + unchecked + { + return RuntimeHelpers.GetHashCode(readerKey) * FieldName.GetHashCode(); + } } public override bool Equals(object that) diff --git a/src/Lucene.Net/Util/FixedBitSet.cs b/src/Lucene.Net/Util/FixedBitSet.cs index 9ae368bd92..e1a7700039 100644 --- a/src/Lucene.Net/Util/FixedBitSet.cs +++ b/src/Lucene.Net/Util/FixedBitSet.cs @@ -724,15 +724,18 @@ public override bool Equals(object o) public override int GetHashCode() { - long h = 0; - for (int i = numWords; --i >= 0; ) + unchecked { - h ^= bits[i]; - h = (h << 1) | (h >>> 63); // rotate left + long h = 0; + for (int i = numWords; --i >= 0; ) + { + h ^= bits[i]; + h = (h << 1) | (h >>> 63); // rotate left + } + // fold leftmost bits into right and add a constant to prevent + // empty sets from returning 0, which is too common. + return (int)((h >> 32) ^ h) + (int)0x98761234; } - // fold leftmost bits into right and add a constant to prevent - // empty sets from returning 0, which is too common. - return (int)((h >> 32) ^ h) + unchecked((int)0x98761234); } } } diff --git a/src/Lucene.Net/Util/Fst/PairOutputs.cs b/src/Lucene.Net/Util/Fst/PairOutputs.cs index 3399c1d63b..273874b140 100644 --- a/src/Lucene.Net/Util/Fst/PairOutputs.cs +++ b/src/Lucene.Net/Util/Fst/PairOutputs.cs @@ -58,7 +58,10 @@ public override bool Equals(object other) public override int GetHashCode() { - return Output1.GetHashCode() + Output2.GetHashCode(); + unchecked + { + return Output1.GetHashCode() + Output2.GetHashCode(); + } } } @@ -186,4 +189,4 @@ public override string ToString() return "PairOutputs<" + outputs1 + "," + outputs2 + ">"; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/IntsRef.cs b/src/Lucene.Net/Util/IntsRef.cs index 901dbcf792..c73c1231e6 100644 --- a/src/Lucene.Net/Util/IntsRef.cs +++ b/src/Lucene.Net/Util/IntsRef.cs @@ -112,14 +112,17 @@ public object Clone() public override int GetHashCode() { - const int prime = 31; - int result = 0; - int end = Offset + Length; - for (int i = Offset; i < end; i++) + unchecked { - result = prime * result + ints[i]; + const int prime = 31; + int result = 0; + int end = Offset + Length; + for (int i = Offset; i < end; i++) + { + result = prime * result + ints[i]; + } + return result; } - return result; } public override bool Equals(object obj) diff --git a/src/Lucene.Net/Util/LongBitSet.cs b/src/Lucene.Net/Util/LongBitSet.cs index d0c01835ac..91722b9656 100644 --- a/src/Lucene.Net/Util/LongBitSet.cs +++ b/src/Lucene.Net/Util/LongBitSet.cs @@ -452,15 +452,18 @@ public override bool Equals(object o) public override int GetHashCode() { - long h = 0; - for (int i = numWords; --i >= 0; ) + unchecked { - h ^= bits[i]; - h = (h << 1) | (h >>> 63); // rotate left + long h = 0; + for (int i = numWords; --i >= 0; ) + { + h ^= bits[i]; + h = (h << 1) | (h >>> 63); // rotate left + } + // fold leftmost bits into right and add a constant to prevent + // empty sets from returning 0, which is too common. + return (int)((h >> 32) ^ h) + (int)0x98761234; } - // fold leftmost bits into right and add a constant to prevent - // empty sets from returning 0, which is too common. - return (int)((h >> 32) ^ h) + unchecked((int)0x98761234); } } } diff --git a/src/Lucene.Net/Util/LongsRef.cs b/src/Lucene.Net/Util/LongsRef.cs index f15578afb4..76ef0d5b3c 100644 --- a/src/Lucene.Net/Util/LongsRef.cs +++ b/src/Lucene.Net/Util/LongsRef.cs @@ -112,14 +112,17 @@ public object Clone() public override int GetHashCode() { - const int prime = 31; - int result = 0; - long end = Offset + Length; - for (int i = Offset; i < end; i++) + unchecked { - result = prime * result + (int)(longs[i] ^ (longs[i] >>> 32)); + const int prime = 31; + int result = 0; + long end = Offset + Length; + for (int i = Offset; i < end; i++) + { + result = prime * result + (int)(longs[i] ^ (longs[i] >>> 32)); + } + return result; } - return result; } public override bool Equals(object obj) diff --git a/src/Lucene.Net/Util/Mutable/MutableValueDouble.cs b/src/Lucene.Net/Util/Mutable/MutableValueDouble.cs index a6c3b555f5..8e027384ea 100644 --- a/src/Lucene.Net/Util/Mutable/MutableValueDouble.cs +++ b/src/Lucene.Net/Util/Mutable/MutableValueDouble.cs @@ -82,8 +82,11 @@ public override int CompareSameType(object other) [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { - long x = J2N.BitConversion.DoubleToInt64Bits(Value); - return (int)x + (int)(x >>> 32); + unchecked + { + long x = J2N.BitConversion.DoubleToInt64Bits(Value); + return (int)x + (int)(x >>> 32); + } } } } diff --git a/src/Lucene.Net/Util/Mutable/MutableValueLong.cs b/src/Lucene.Net/Util/Mutable/MutableValueLong.cs index af09d716d8..c4e1b59810 100644 --- a/src/Lucene.Net/Util/Mutable/MutableValueLong.cs +++ b/src/Lucene.Net/Util/Mutable/MutableValueLong.cs @@ -81,7 +81,10 @@ public override int CompareSameType(object other) [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { - return (int)Value + (int)(Value >> 32); + unchecked + { + return (int)Value + (int)(Value >> 32); + } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/OpenBitSet.cs b/src/Lucene.Net/Util/OpenBitSet.cs index a95c5a6eac..c2d1d684a7 100644 --- a/src/Lucene.Net/Util/OpenBitSet.cs +++ b/src/Lucene.Net/Util/OpenBitSet.cs @@ -1104,17 +1104,20 @@ public override bool Equals(object o) public override int GetHashCode() { - // Start with a zero hash and use a mix that results in zero if the input is zero. - // this effectively truncates trailing zeros without an explicit check. - long h = 0; - for (int i = m_bits.Length; --i >= 0; ) + unchecked { - h ^= m_bits[i]; - h = (h << 1) | (h >>> 63); // rotate left + // Start with a zero hash and use a mix that results in zero if the input is zero. + // this effectively truncates trailing zeros without an explicit check. + long h = 0; + for (int i = m_bits.Length; --i >= 0; ) + { + h ^= m_bits[i]; + h = (h << 1) | (h >>> 63); // rotate left + } + // fold leftmost bits into right and add a constant to prevent + // empty sets from returning 0, which is too common. + return (int)((h >> 32) ^ h) + (int)0x98761234; } - // fold leftmost bits into right and add a constant to prevent - // empty sets from returning 0, which is too common. - return (int)((h >> 32) ^ h) + unchecked((int)0x98761234); } } } diff --git a/src/Lucene.Net/Util/Packed/EliasFanoEncoder.cs b/src/Lucene.Net/Util/Packed/EliasFanoEncoder.cs index c9b14cd577..e5ac35313f 100644 --- a/src/Lucene.Net/Util/Packed/EliasFanoEncoder.cs +++ b/src/Lucene.Net/Util/Packed/EliasFanoEncoder.cs @@ -393,10 +393,13 @@ public override bool Equals(object other) public override int GetHashCode() { - int h = ((int)(31 * (numValues + 7 * (numEncoded + 5 * (numLowBits + 3 * (numIndexEntries + 11 * indexInterval)))))) - ^ Arrays.GetHashCode(upperLongs) - ^ Arrays.GetHashCode(lowerLongs); - return h; + unchecked + { + int h = ((int)(31 * (numValues + 7 * (numEncoded + 5 * (numLowBits + 3 * (numIndexEntries + 11 * indexInterval)))))) + ^ Arrays.GetHashCode(upperLongs) + ^ Arrays.GetHashCode(lowerLongs); + return h; + } } } }