Syntax
class BitSet : public Equatable<BitSet<kNumBits>>,
public Clearable<BitSet<kNumBits>>
{
public:
bool Has(uint16_t aIndex) const { return (mMask[aIndex / 8] & BitMaskFor(aIndex)) != 0; }
void Add(uint16_t aIndex) { mMask[aIndex / 8] |= BitMaskFor(aIndex); }
void Remove(uint16_t aIndex) { mMask[aIndex / 8] &= ~BitMaskFor(aIndex); }
void Update(uint16_t aIndex, bool aToAdd) { aToAdd ? Add(aIndex) : Remove(aIndex); }
bool IsEmpty(void) const
{
bool isEmpty = true;
for (uint8_t byte : mMask)
{
if (byte != 0)
{
isEmpty = false;
break;
}
}
return isEmpty;
}
private:
static uint8_t BitMaskFor(uint16_t aIndex) { return (0x80 >> (aIndex & 7)); }
uint8_t mMask[BytesForBitSize(kNumBits)];
};
![]()
template <uint16_t kNumBits> class BitSet : public Equatable<BitSet<kNumBits>>, public Clearable<BitSet<kNumBits>>