similie 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/ext/similie.c +10 -10
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/ext/similie.c
CHANGED
@@ -36,16 +36,16 @@
|
|
36
36
|
|
37
37
|
// http://en.wikipedia.org/wiki/Hamming_weight
|
38
38
|
|
39
|
-
const
|
40
|
-
const
|
41
|
-
const
|
42
|
-
const
|
43
|
-
const
|
44
|
-
const
|
45
|
-
const
|
46
|
-
const
|
47
|
-
|
48
|
-
int popcount(
|
39
|
+
const uint64_t m1 = 0x5555555555555555; //binary: 0101...
|
40
|
+
const uint64_t m2 = 0x3333333333333333; //binary: 00110011..
|
41
|
+
const uint64_t m4 = 0x0f0f0f0f0f0f0f0f; //binary: 4 zeros, 4 ones ...
|
42
|
+
const uint64_t m8 = 0x00ff00ff00ff00ff; //binary: 8 zeros, 8 ones ...
|
43
|
+
const uint64_t m16 = 0x0000ffff0000ffff; //binary: 16 zeros, 16 ones ...
|
44
|
+
const uint64_t m32 = 0x00000000ffffffff; //binary: 32 zeros, 32 ones
|
45
|
+
const uint64_t hff = 0xffffffffffffffff; //binary: all ones
|
46
|
+
const uint64_t h01 = 0x0101010101010101; //the sum of 256 to the power of 0,1,2,3...
|
47
|
+
|
48
|
+
int popcount(uint64_t x) {
|
49
49
|
x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits
|
50
50
|
x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
|
51
51
|
x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits
|