19 #ifndef TESSERACT_CCUTIL_BITVECTOR_H_
20 #define TESSERACT_CCUTIL_BITVECTOR_H_
50 void Init(
int length);
70 array_[WordIndex(index)] |= BitMask(index);
73 array_[WordIndex(index)] &= ~BitMask(index);
81 bool At(
int index)
const {
82 return (array_[WordIndex(index)] & BitMask(index)) != 0;
85 return (array_[WordIndex(index)] & BitMask(index)) != 0;
105 void Alloc(
int length);
109 int WordIndex(
int index)
const {
110 assert(0 <= index && index < bit_size_);
111 return index / kBitFactor;
114 uint32_t BitMask(
int index)
const {
115 return 1 << (index & (kBitFactor - 1));
119 int WordLength()
const {
120 return (bit_size_ + kBitFactor - 1) / kBitFactor;
123 int ByteLength()
const {
124 return WordLength() *
sizeof(*array_);
134 static const int kBitFactor =
sizeof(uint32_t) * 8;
139 #endif // TESSERACT_CCUTIL_BITVECTOR_H_