本站源代码
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.

46 lines
750B

  1. // +build go1.9
  2. package bitset
  3. import "math/bits"
  4. func popcntSlice(s []uint64) uint64 {
  5. var cnt int
  6. for _, x := range s {
  7. cnt += bits.OnesCount64(x)
  8. }
  9. return uint64(cnt)
  10. }
  11. func popcntMaskSlice(s, m []uint64) uint64 {
  12. var cnt int
  13. for i := range s {
  14. cnt += bits.OnesCount64(s[i] &^ m[i])
  15. }
  16. return uint64(cnt)
  17. }
  18. func popcntAndSlice(s, m []uint64) uint64 {
  19. var cnt int
  20. for i := range s {
  21. cnt += bits.OnesCount64(s[i] & m[i])
  22. }
  23. return uint64(cnt)
  24. }
  25. func popcntOrSlice(s, m []uint64) uint64 {
  26. var cnt int
  27. for i := range s {
  28. cnt += bits.OnesCount64(s[i] | m[i])
  29. }
  30. return uint64(cnt)
  31. }
  32. func popcntXorSlice(s, m []uint64) uint64 {
  33. var cnt int
  34. for i := range s {
  35. cnt += bits.OnesCount64(s[i] ^ m[i])
  36. }
  37. return uint64(cnt)
  38. }
上海开阖软件有限公司 沪ICP备12045867号-1