-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
58 additions
and
601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,59 @@ | ||
package bitset | ||
|
||
// bit population count, take from | ||
// https://code.google.com/p/go/issues/detail?id=4988#c11 | ||
// credit: https://code.google.com/u/arnehormann/ | ||
func popcount(x uint64) (n uint64) { | ||
x -= (x >> 1) & 0x5555555555555555 | ||
x = (x>>2)&0x3333333333333333 + x&0x3333333333333333 | ||
x += x >> 4 | ||
x &= 0x0f0f0f0f0f0f0f0f | ||
x *= 0x0101010101010101 | ||
return x >> 56 | ||
} | ||
import "math/bits" | ||
|
||
func popcntSliceGo(s []uint64) uint64 { | ||
cnt := uint64(0) | ||
func popcntSlice(s []uint64) uint64 { | ||
var cnt int | ||
for _, x := range s { | ||
cnt += popcount(x) | ||
cnt += bits.OnesCount64(x) | ||
} | ||
return cnt | ||
return uint64(cnt) | ||
} | ||
|
||
func popcntMaskSliceGo(s, m []uint64) uint64 { | ||
cnt := uint64(0) | ||
func popcntMaskSlice(s, m []uint64) uint64 { | ||
var cnt int | ||
// this explicit check eliminates a bounds check in the loop | ||
if len(m) < len(s) { | ||
panic("mask slice is too short") | ||
} | ||
for i := range s { | ||
cnt += popcount(s[i] &^ m[i]) | ||
cnt += bits.OnesCount64(s[i] &^ m[i]) | ||
} | ||
return cnt | ||
return uint64(cnt) | ||
} | ||
|
||
func popcntAndSliceGo(s, m []uint64) uint64 { | ||
cnt := uint64(0) | ||
func popcntAndSlice(s, m []uint64) uint64 { | ||
var cnt int | ||
// this explicit check eliminates a bounds check in the loop | ||
if len(m) < len(s) { | ||
panic("mask slice is too short") | ||
} | ||
for i := range s { | ||
cnt += popcount(s[i] & m[i]) | ||
cnt += bits.OnesCount64(s[i] & m[i]) | ||
} | ||
return cnt | ||
return uint64(cnt) | ||
} | ||
|
||
func popcntOrSliceGo(s, m []uint64) uint64 { | ||
cnt := uint64(0) | ||
func popcntOrSlice(s, m []uint64) uint64 { | ||
var cnt int | ||
// this explicit check eliminates a bounds check in the loop | ||
if len(m) < len(s) { | ||
panic("mask slice is too short") | ||
} | ||
for i := range s { | ||
cnt += popcount(s[i] | m[i]) | ||
cnt += bits.OnesCount64(s[i] | m[i]) | ||
} | ||
return cnt | ||
return uint64(cnt) | ||
} | ||
|
||
func popcntXorSliceGo(s, m []uint64) uint64 { | ||
cnt := uint64(0) | ||
func popcntXorSlice(s, m []uint64) uint64 { | ||
var cnt int | ||
// this explicit check eliminates a bounds check in the loop | ||
if len(m) < len(s) { | ||
panic("mask slice is too short") | ||
} | ||
for i := range s { | ||
cnt += popcount(s[i] ^ m[i]) | ||
cnt += bits.OnesCount64(s[i] ^ m[i]) | ||
} | ||
return cnt | ||
return uint64(cnt) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.