You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2019/12/15 11:44:52 UTC
[lucenenet] 03/07: BUG: Lucene.Net.Support.Number::BitCount(int)
does not pass Harmony tests. Replaced the implementation with one that
does.
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit de4fd37218525fe3dbcefaa7faed9381daf84e20
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Thu Dec 5 12:29:49 2019 +0700
BUG: Lucene.Net.Support.Number::BitCount(int) does not pass Harmony tests. Replaced the implementation with one that does.
---
src/Lucene.Net/Support/Number.cs | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/Lucene.Net/Support/Number.cs b/src/Lucene.Net/Support/Number.cs
index 73dafa8..0f4b5f1 100644
--- a/src/Lucene.Net/Support/Number.cs
+++ b/src/Lucene.Net/Support/Number.cs
@@ -341,15 +341,14 @@ namespace Lucene.Net.Support
}
// Returns the number of 1-bits in the number
- public static int BitCount(int num)
+ public static int BitCount(int value)
{
- int bitcount = 0;
- while (num > 0)
- {
- bitcount += (num & 1);
- num >>= 1;
- }
- return bitcount;
+ value -= ((value >> 1) & 0x55555555);
+ value = (value & 0x33333333) + ((value >> 2) & 0x33333333);
+ value = (((value >> 4) + value) & 0x0F0F0F0F);
+ value += (value >> 8);
+ value += (value >> 16);
+ return (value & 0x0000003F);
}
public static int RotateLeft(int i, int reps)