Skip to content

Commit 5fb8adc

Browse files
Merge pull request #112 from sdboyer/new-bitcount
Newer version of bitCount()
2 parents e98f2a3 + 1cc1cec commit 5fb8adc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

trie/ctrie/ctrie.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,11 @@ func flagPos(hashcode uint32, lev uint, bmp uint32) (uint32, uint32) {
759759
}
760760

761761
func bitCount(x uint32) uint32 {
762-
x = ((x >> 1) & 0x55555555) + (x & 0x55555555)
762+
x -= (x >> 1) & 0x55555555
763763
x = ((x >> 2) & 0x33333333) + (x & 0x33333333)
764-
x = ((x >> 4) & 0x0f0f0f0f) + (x & 0x0f0f0f0f)
765-
x = ((x >> 8) & 0x00ff00ff) + (x & 0x00ff00ff)
766-
return ((x >> 16) & 0x0000ffff) + (x & 0x0000ffff)
764+
x = ((x >> 4) + x) & 0x0f0f0f0f
765+
x *= 0x01010101
766+
return x >> 24
767767
}
768768

769769
// gcas is a generation-compare-and-swap which has semantics similar to RDCSS,

0 commit comments

Comments
 (0)