Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions utilities.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,3 @@
/**
* Lookup table for powers of 2
*/
export const log2: Record<number, number> = {
1: 0,
2: 1,
4: 2,
8: 3,
16: 4,
32: 5,
64: 6,
128: 7,
256: 8,
512: 9,
1024: 10,
2048: 11,
4096: 12,
8192: 13,
16384: 14,
32768: 15,
65536: 16,
131072: 17,
262144: 18,
524288: 19,
1048576: 20,
2097152: 21,
4194304: 22,
8388608: 23,
16777216: 24,
33554432: 25,
67108864: 26,
134217728: 27,
268435456: 28,
536870912: 29,
1073741824: 30,
2147483648: 31,
};

/**
* Counts set bits in a given number.
*
Expand All @@ -55,8 +17,7 @@ export function popCount32(value: number): number {
* @return the index of LSB
*/
export function getLSBIndex(value: number): number {
if (value === 2147483648) return 31;
return log2[value & -value];
return 31 - Math.clz32(value & -value);
}

/**
Expand Down