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, 0x28, 0x2c, 0x2c, 0x2e,
60 0x20, 0x30, 0x30, 0x32, 0x30, 0x34, 0x34, 0x36,
61 0x30, 0x38, 0x38, 0x3a, 0x38, 0x3c, 0x3c, 0x3e,
62 0, 0x40, 0x40, 0x42, 0x40, 0x44, 0x44, 0x46,
63 0x40, 0x48, 0x48, 0x4a, 0x48, 0x4c, 0x4c, 0x4e,
64 0x40, 0x50, 0x50, 0x52, 0x50, 0x54, 0x54, 0x56,
65 0x50, 0x58, 0x58, 0x5a, 0x58, 0x5c, 0x5c, 0x5e,
66 0x40, 0x60, 0x60, 0x62, 0x60, 0x64, 0x64, 0x66,
67 0x60, 0x68, 0x68, 0x6a, 0x68, 0x6c, 0x6c, 0x6e,
68 0x60, 0x70, 0x70, 0x72, 0x70, 0x74, 0x74, 0x76,
69 0x70, 0x78, 0x78, 0x7a, 0x78, 0x7c, 0x7c, 0x7e,
70 0, 0x80, 0x80, 0x82, 0x80, 0x84, 0x84, 0x86,
71 0x80, 0x88, 0x88, 0x8a, 0x88, 0x8c, 0x8c, 0x8e,
72 0x80, 0x90, 0x90, 0x92, 0x90, 0x94, 0x94, 0x96,
73 0x90, 0x98, 0x98, 0x9a, 0x98, 0x9c, 0x9c, 0x9e,
74 0x80, 0xa0, 0xa0, 0xa2, 0xa0, 0xa4, 0xa4, 0xa6,
75 0xa0, 0xa8, 0xa8, 0xaa, 0xa8, 0xac, 0xac, 0xae,
76 0xa0, 0xb0, 0xb0, 0xb2, 0xb0, 0xb4, 0xb4, 0xb6,
77 0xb0, 0xb8, 0xb8, 0xba, 0xb8, 0xbc, 0xbc, 0xbe,
78 0x80, 0xc0, 0xc0, 0xc2, 0xc0, 0xc4, 0xc4, 0xc6,
79 0xc0, 0xc8, 0xc8, 0xca, 0xc8, 0xcc, 0xcc, 0xce,
80 0xc0, 0xd0, 0xd0, 0xd2, 0xd0, 0xd4, 0xd4, 0xd6,
81 0xd0, 0xd8, 0xd8, 0xda, 0xd8, 0xdc, 0xdc, 0x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
new uint32_t[WordLength()];
118 memcpy(array_, src.array_, ByteLength());
122 Alloc(src.bit_size_);
123 memcpy(array_, src.array_, ByteLength());
139 if (fwrite(&bit_size_,
sizeof(bit_size_), 1, fp) != 1)
return false;
140 int wordlen = WordLength();
141 if (static_cast<int>(fwrite(array_,
sizeof(*array_), wordlen, fp)) != wordlen)
149 uint32_t new_bit_size;
150 if (fread(&new_bit_size,
sizeof(new_bit_size), 1, fp) != 1)
return false;
152 ReverseN(&new_bit_size,
sizeof(new_bit_size));
155 int wordlen = WordLength();
156 if (static_cast<int>(fread(array_,
sizeof(*array_), wordlen, fp)) != wordlen)
159 for (
int i = 0; i < wordlen; ++i)
160 ReverseN(&array_[i],
sizeof(array_[i]));
166 memset(array_, 0, ByteLength());
169 memset(array_, ~0, ByteLength());
176 int next_bit = prev_bit + 1;
177 if (next_bit >= bit_size_)
return -1;
179 int next_word = WordIndex(next_bit);
180 int bit_index = next_word * kBitFactor;
181 int word_end = bit_index + kBitFactor;
182 uint32_t word = array_[next_word];
183 uint8_t byte = word & 0xff;
184 while (bit_index < word_end) {
185 if (bit_index + 8 > next_bit && byte != 0) {
186 while (bit_index +
lsb_index_[byte] < next_bit && byte != 0)
197 int wordlen = WordLength();
198 while (next_word < wordlen && (word = array_[next_word]) == 0) {
200 bit_index += kBitFactor;
202 if (bit_index >= bit_size_)
return -1;
204 while ((word & 0xff) == 0) {
213 int wordlen = WordLength();
215 for (
int w = 0; w < wordlen; ++w) {
216 uint32_t word = array_[w];
217 for (
int i = 0; i < 4; ++i) {
228 int length =
MIN(WordLength(), other.WordLength());
229 for (
int w = 0; w < length; ++w)
230 array_[w] |= other.array_[w];
233 int length =
MIN(WordLength(), other.WordLength());
234 for (
int w = 0; w < length; ++w)
235 array_[w] &= other.array_[w];
236 for (
int w = WordLength() - 1; w >= length; --w)
240 int length =
MIN(WordLength(), other.WordLength());
241 for (
int w = 0; w < length; ++w)
242 array_[w] ^= other.array_[w];
247 int length =
MIN(v1.WordLength(), v2.WordLength());
248 for (
int w = 0; w < length; ++w)
249 array_[w] = v1.array_[w] ^ (v1.array_[w] & v2.array_[w]);
250 for (
int w = WordLength() - 1; w >= length; --w)
251 array_[w] = v1.array_[w];
256 void BitVector::Alloc(
int length) {
257 int initial_wordlength = WordLength();
259 int new_wordlength = WordLength();
260 if (new_wordlength != initial_wordlength) {
262 array_ =
new uint32_t[new_wordlength];
static const uint8_t lsb_index_[256]
void SetSubtract(const BitVector &v1, const BitVector &v2)
void operator^=(const BitVector &other)
static const int hamming_table_[256]
void operator|=(const BitVector &other)
bool DeSerialize(bool swap, FILE *fp)
void ReverseN(void *ptr, int num_bytes)
BitVector & operator=(const BitVector &src)
static const uint8_t lsb_eroded_[256]
void operator &=(const BitVector &other)
int NextSetBit(int prev_bit) const
bool Serialize(FILE *fp) const