Skip to content

Commit

Permalink
support for 1.9 bit counts
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Fitzgerald committed Aug 28, 2017
1 parent 988f4f2 commit 30284c1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions popcnt_19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// +build go1.9

package bitset

import "math/bits"

func popcntSlice(s []uint64) uint64 {
var cnt int
for _, x := range s {
cnt += bits.OnesCount64(x)
}
return uint64(cnt)
}

func popcntMaskSlice(s, m []uint64) uint64 {
var cnt int
for i := range s {
cnt += bits.OnesCount64(s[i] &^ m[i])
}
return uint64(cnt)
}

func popcntAndSlice(s, m []uint64) uint64 {
var cnt int
for i := range s {
cnt += bits.OnesCount64(s[i] & m[i])
}
return uint64(cnt)
}

func popcntOrSlice(s, m []uint64) uint64 {
var cnt int
for i := range s {
cnt += bits.OnesCount64(s[i] | m[i])
}
return uint64(cnt)
}

func popcntXorSlice(s, m []uint64) uint64 {
var cnt int
for i := range s {
cnt += bits.OnesCount64(s[i] ^ m[i])
}
return uint64(cnt)
}
File renamed without changes.

0 comments on commit 30284c1

Please sign in to comment.