github.com/hsfzxjy/dgo/go@v0.2.0/pin/bitset/bitset64.go (about) 1 package bitset 2 3 import "math/bits" 4 5 type Bitset64 uint64 6 7 func (b Bitset64) IsEmpty() bool { return b == 0 } 8 func (b Bitset64) Count() int { return bits.OnesCount64(uint64(b)) } 9 func (b Bitset64) Test(i uint8) bool { return i < 64 && b&(1<<i) != 0 } 10 func (b *Bitset64) Set(i uint8) { *b |= 1 << i } 11 func (b *Bitset64) Clear(i uint8) { *b &^= 1 << i } 12 13 func (b *Bitset64) PickSet() (result uint8, success bool) { 14 const full = ^uint64(0) 15 v := uint64(*b) 16 if v == full { 17 return 0, false 18 } 19 x := bits.TrailingZeros64(^v) 20 *b |= 1 << x 21 return uint8(x), true 22 }