22 #ifndef TESSERACT_CCUTIL_BITVECTOR_H_ 23 #define TESSERACT_CCUTIL_BITVECTOR_H_ 53 void Init(
int length);
73 array_[WordIndex(index)] |= BitMask(index);
76 array_[WordIndex(index)] &= ~BitMask(index);
84 bool At(
int index)
const {
85 return (array_[WordIndex(index)] & BitMask(index)) != 0;
88 return (array_[WordIndex(index)] & BitMask(index)) != 0;
108 void Alloc(
int length);
112 int WordIndex(
int index)
const {
113 assert(0 <= index && index < bit_size_);
114 return index / kBitFactor;
117 uint32_t BitMask(
int index)
const {
118 return 1 << (index & (kBitFactor - 1));
122 int WordLength()
const {
123 return (bit_size_ + kBitFactor - 1) / kBitFactor;
126 int ByteLength()
const {
127 return WordLength() *
sizeof(*array_);
137 static const int kBitFactor =
sizeof(uint32_t) * 8;
142 #endif // TESSERACT_CCUTIL_BITVECTOR_H_ BitVector & operator=(const BitVector &src)
void operator &=(const BitVector &other)
void operator^=(const BitVector &other)
void SetValue(int index, bool value)
bool operator[](int index) const
static const uint8_t lsb_eroded_[256]
bool Serialize(FILE *fp) const
static const int hamming_table_[256]
int NextSetBit(int prev_bit) const
bool DeSerialize(bool swap, FILE *fp)
void SetSubtract(const BitVector &v1, const BitVector &v2)
static const uint8_t lsb_index_[256]
void operator|=(const BitVector &other)