代码拉取完成,页面将自动刷新
package bitset
type BitSet struct {
Size uint32
Bits []byte
}
func New(numBits uint32) *BitSet {
bs := &BitSet{}
byte_len := numBits/8 + 1
bs.Size = byte_len * 8
bs.Bits = make([]byte, byte_len)
return bs
}
//---------------------------------------------------------- set 1 to position [bit]
func (bs *BitSet) Set(bit uint32) {
if bit >= bs.Size {
return
}
n := bit / 8
off := bit % 8
bs.Bits[n] |= 128 >> off
}
//---------------------------------------------------------- set 0 to position [bit]
func (bs *BitSet) Unset(bit uint32) {
if bit >= bs.Size {
return
}
n := bit / 8
off := bit % 8
bs.Bits[n] &^= 128 >> off
}
//---------------------------------------------------------- test wheather a bit is set
func (bs *BitSet) Test(bit uint32) bool {
if bit >= bs.Size {
return false
}
n := bit / 8
off := bit % 8
if bs.Bits[n]&(128>>off) != 0 {
return true
} else {
return false
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。