NightOwl888 commented on code in PR #1068:
URL: https://github.com/apache/lucenenet/pull/1068#discussion_r1890412653


##########
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) + unchecked((int)0x98761234);

Review Comment:
   We can remove the unchecked cast to `int` from `uint` here.



##########
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) + unchecked((int)0x98761234);

Review Comment:
   We can remove the unchecked cast to `int` from `uint` here.



##########
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) + unchecked((int)0x98761234);

Review Comment:
   We can remove the unchecked cast to `int` from `uint` here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to