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;
void SetValue(int index, bool value)
static const uint8_t lsb_index_[256]
void operator^=(const BitVector &other)
static const int hamming_table_[256]
BitVector & operator=(const BitVector &src)
void SetSubtract(const BitVector &v1, const BitVector &v2)
bool operator[](int index) const
void operator&=(const BitVector &other)
bool DeSerialize(bool swap, FILE *fp)
int NextSetBit(int prev_bit) const
void operator|=(const BitVector &other)
bool Serialize(FILE *fp) const
static const uint8_t lsb_eroded_[256]