@woosh/meep-engine 2.119.109 → 2.119.110
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.
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitcount.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/bitcount.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,8BAHW,MAAM,GACJ,MAAM,CAWlB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} i32
|
|
4
|
+
* @returns {number} number of set bits
|
|
5
|
+
*/
|
|
6
|
+
export function bitcount(i32){
|
|
7
|
+
// see https://stackoverflow.com/a/109025/3973586
|
|
8
|
+
// see https://graphics.stanford.edu/%7Eseander/bithacks.html#CountBitsSetParallel
|
|
9
|
+
|
|
10
|
+
let i = (i32|0) - ((i32 >> 1) & 0x55555555); // add pairs of bits
|
|
11
|
+
i = (i & 0x33333333) + ((i >> 2) & 0x33333333); // quads
|
|
12
|
+
i = (i + (i >> 4)) & 0x0F0F0F0F; // groups of 8
|
|
13
|
+
i *= 0x01010101; // horizontal sum of bytes
|
|
14
|
+
return i >> 24; // return just that top byte (after truncating to 32-bit even when int is wider than uint32_t)
|
|
15
|
+
}
|