10 errIndexOutOfBounds = errors.New("index out of bounds error")
18 func NewBitMap(size uint32) *BitMap {
19 obj := &BitMap{size: size}
20 num := (size + bitLen - 1) / bitLen
21 arr := make([]int32, num)
26 func (b *BitMap) Set(index uint32) error {
28 return errIndexOutOfBounds
31 arrIndex, bitIndex := index / bitLen, index % bitLen
32 b.arr[arrIndex] |= (1 << bitIndex)
36 func (b *BitMap) Clean(index uint32) error {
38 return errIndexOutOfBounds
41 arrIndex, bitIndex := index / bitLen, index % bitLen
42 b.arr[arrIndex] &= (^(1 << bitIndex))
46 func (b *BitMap) Test(index uint32) (bool, error) {
48 return false, errIndexOutOfBounds
51 arrIndex, bitIndex := index / bitLen, index % bitLen
52 return b.arr[arrIndex] & (1 << bitIndex) != 0, nil