Last change
on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
696 bytes
|
Line | |
---|
1 | /*
|
---|
2 | * This is a AssemblyScript port of the original Java version, which was written by
|
---|
3 | * Gil Tene as described in
|
---|
4 | * https://github.com/HdrHistogram/HdrHistogram
|
---|
5 | * and released to the public domain, as explained at
|
---|
6 | * http://creativecommons.org/publicdomain/zero/1.0/
|
---|
7 | */
|
---|
8 |
|
---|
9 | export const bitCount = (n: u64): u8 => {
|
---|
10 | let bits: u8 = 0;
|
---|
11 | while (n !== 0) {
|
---|
12 | const input: u32 = <u32>(n & (<u64>u32.MAX_VALUE));
|
---|
13 | bits += bitCount32(input);
|
---|
14 | n /= 0x100000000;
|
---|
15 | }
|
---|
16 | return bits;
|
---|
17 | };
|
---|
18 |
|
---|
19 | function bitCount32(input: u32): u8 {
|
---|
20 | let n = input;
|
---|
21 | n = n - ((n >> 1) & 0x55555555);
|
---|
22 | n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
|
---|
23 | return <u8>((((n + (n >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24);
|
---|
24 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.