本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
514B

  1. // +build !go1.9
  2. package roaring
  3. // bit population count, take from
  4. // https://code.google.com/p/go/issues/detail?id=4988#c11
  5. // credit: https://code.google.com/u/arnehormann/
  6. // credit: https://play.golang.org/p/U7SogJ7psJ
  7. // credit: http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
  8. func popcount(x uint64) uint64 {
  9. x -= (x >> 1) & 0x5555555555555555
  10. x = (x>>2)&0x3333333333333333 + x&0x3333333333333333
  11. x += x >> 4
  12. x &= 0x0f0f0f0f0f0f0f0f
  13. x *= 0x0101010101010101
  14. return x >> 56
  15. }
上海开阖软件有限公司 沪ICP备12045867号-1