IsFull returns true iff all bits in the bit array are 1.
()
| 224 | |
| 225 | // IsFull returns true iff all bits in the bit array are 1. |
| 226 | func (bA *BitArray) IsFull() bool { |
| 227 | if bA == nil { |
| 228 | return true |
| 229 | } |
| 230 | bA.mtx.Lock() |
| 231 | defer bA.mtx.Unlock() |
| 232 | |
| 233 | // Check all elements except the last |
| 234 | for _, elem := range bA.Elems[:len(bA.Elems)-1] { |
| 235 | if (^elem) != 0 { |
| 236 | return false |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // Check that the last element has (lastElemBits) 1's |
| 241 | lastElemBits := (bA.Bits+63)%64 + 1 |
| 242 | lastElem := bA.Elems[len(bA.Elems)-1] |
| 243 | return (lastElem+1)&((uint64(1)<<uint(lastElemBits))-1) == 0 |
| 244 | } |
| 245 | |
| 246 | // PickRandom returns a random index for a set bit in the bit array. |
| 247 | // If there is no such value, it returns 0, false. |