35 return data &
static_cast<uword
>(1);
42 return static_cast<uword
>((mydata >> 1) & largestrunninglengthcount);
49 return static_cast<uword
>((data >> 1) & largestrunninglengthcount);
56 return static_cast<uword
>(mydata >> (1 + runninglengthbits));
69 static inline uword
size(uword data) {
78 return static_cast<uword
>(data >> (1 + runninglengthbits));
86 mydata |=
static_cast<uword
>(1);
88 mydata &=
static_cast<uword
>(~1);
91 void discardFirstWords(uword x) {
94 setRunningLength(rl - x);
107 data |=
static_cast<uword
>(1);
109 data &=
static_cast<uword
>(~1);
112 void setRunningLength(uword l) {
113 mydata |= shiftedlargestrunninglengthcount;
115 static_cast<uword
>((l << 1) | notshiftedlargestrunninglengthcount);
119 static inline void setRunningLength(uword &data, uword l) {
120 data |= shiftedlargestrunninglengthcount;
121 data &=
static_cast<uword
>((l << 1) | notshiftedlargestrunninglengthcount);
124 void setNumberOfLiteralWords(uword l) {
125 mydata |= notrunninglengthplusrunningbit;
126 mydata &=
static_cast<uword
>((l << (runninglengthbits + 1)) |
127 runninglengthplusrunningbit);
130 static inline void setNumberOfLiteralWords(uword &data, uword l) {
131 data |= notrunninglengthplusrunningbit;
132 data &=
static_cast<uword
>(l << (runninglengthbits + 1)) |
133 runninglengthplusrunningbit;
136 static const uint32_t runninglengthbits =
sizeof(uword) * 4;
137 static const uint32_t literalbits =
sizeof(uword) * 8 - 1 - runninglengthbits;
138 static const uword largestliteralcount =
139 (
static_cast<uword
>(1) << literalbits) - 1;
140 static const uword largestrunninglengthcount =
141 (
static_cast<uword
>(1) << runninglengthbits) - 1;
142 static const uword shiftedlargestrunninglengthcount =
143 largestrunninglengthcount << 1;
144 static const uword notshiftedlargestrunninglengthcount =
145 static_cast<uword
>(~shiftedlargestrunninglengthcount);
146 static const uword runninglengthplusrunningbit =
147 (
static_cast<uword
>(1) << (runninglengthbits + 1)) - 1;
148 static const uword notrunninglengthplusrunningbit =
149 static_cast<uword
>(~runninglengthplusrunningbit);
150 static const uword notlargestrunninglengthcount =
151 static_cast<uword
>(~largestrunninglengthcount);
207 enum { wordinbits =
sizeof(uword) * 8 };
211 : RunningBit(data &
static_cast<uword
>(1)),
212 RunningLength(
static_cast<uword
>(
214 NumberOfLiteralWords(
static_cast<uword
>(
218 : RunningBit(p.mydata &
static_cast<uword
>(1)),
219 RunningLength((p.mydata >> 1) &
221 NumberOfLiteralWords(p.mydata >>
231 writeLiteralWords(pd, container);
237 size_t dischargeCount() {
245 for (
size_t i = 0; i < pd; ++i)
246 answer += countOnes((uword)getLiteralWordAt(i));
253 size_t dischargeCountNegated() {
261 for (
size_t i = 0; i < pd; ++i)
262 answer += countOnes((uword)(~getLiteralWordAt(i)));
272 size_t dischargeCount(
size_t max,
size_t *count) {
275 if (index + RunningLength > max) {
276 const size_t offset = max - index;
278 *count += offset * wordinbits;
279 RunningLength -= offset;
283 *count += RunningLength * wordinbits;
284 index += RunningLength;
285 if (NumberOfLiteralWords + index > max) {
286 const size_t offset = max - index;
287 for (
size_t i = 0; i < offset; ++i)
288 *count += countOnes((uword)getLiteralWordAt(i));
290 NumberOfLiteralWords -= offset;
293 for (
size_t i = 0; i < NumberOfLiteralWords; ++i)
294 *count += countOnes((uword)getLiteralWordAt(i));
295 index += NumberOfLiteralWords;
302 size_t dischargeCountNegated(
size_t max,
size_t *count) {
305 if (index + RunningLength > max) {
306 const size_t offset = max - index;
308 *count += offset * wordinbits;
309 RunningLength -= offset;
313 *count += RunningLength * wordinbits;
314 index += RunningLength;
315 if (NumberOfLiteralWords + index > max) {
316 const size_t offset = max - index;
317 for (
size_t i = 0; i < offset; ++i)
318 *count += countOnes((uword)(~getLiteralWordAt(i)));
320 NumberOfLiteralWords -= offset;
323 for (
size_t i = 0; i < NumberOfLiteralWords; ++i)
324 *count += countOnes((uword)(~getLiteralWordAt(i)));
325 index += NumberOfLiteralWords;
331 bool nonzero_discharge() {
340 discardFirstWordsWithReload(
static_cast<uword
>(pl + pd));
349 if (index + RunningLength > max) {
350 const size_t offset = max - index;
352 RunningLength =
static_cast<uword
>(RunningLength - offset);
356 index += RunningLength;
357 if (NumberOfLiteralWords + index > max) {
358 const size_t offset = max - index;
359 writeLiteralWords(offset, container);
361 NumberOfLiteralWords =
362 static_cast<uword
>(NumberOfLiteralWords - offset);
365 writeLiteralWords(NumberOfLiteralWords, container);
366 index += NumberOfLiteralWords;
373 bool nonzero_discharge(
size_t max,
size_t &index) {
375 while ((index < max) && (
size() > 0)) {
378 if (index + pl > max) {
385 if (pd + index > max) {
390 discardFirstWordsWithReload(
static_cast<uword
>(pl + pd));
399 while ((index < max) && (
size() > 0)) {
402 if (index + pl > max) {
408 if (pd + index > max) {
411 writeNegatedLiteralWords(pd, container);
412 discardFirstWordsWithReload(
static_cast<uword
>(pl + pd));
417 bool nonzero_dischargeNegated(
size_t max,
size_t &index) {
418 while ((index < max) && (
size() > 0)) {
421 if (index + pl > max) {
428 if (pd + index > max) {
433 discardFirstWordsWithReload(
static_cast<uword
>(pl + pd));
439 uword getLiteralWordAt(
size_t index) {
return parent->dirtyWords()[index]; }
445 void writeNegatedLiteralWords(
size_t numWords,
450 void discardRunningWords() { RunningLength = 0; }
452 void discardRunningWordsWithReload() {
454 if (NumberOfLiteralWords == 0)
459 if (!parent->hasNext()) {
460 NumberOfLiteralWords = 0;
468 void read(
const uword &data) {
469 RunningBit = data &
static_cast<uword
>(1);
470 RunningLength =
static_cast<uword
>(
472 NumberOfLiteralWords =
static_cast<uword
>(
481 void discardFirstWords(uword x) {
482 if (RunningLength >= x) {
483 RunningLength =
static_cast<uword
>(RunningLength - x);
486 x =
static_cast<uword
>(x - RunningLength);
488 NumberOfLiteralWords =
static_cast<uword
>(NumberOfLiteralWords - x);
505 return static_cast<uword
>(RunningLength + NumberOfLiteralWords);
508 friend std::ostream &operator<<(std::ostream &out,
510 out <<
"{RunningBit:" << a.RunningBit
511 <<
",RunningLength:" << a.RunningLength
512 <<
",NumberOfLiteralWords:" << a.NumberOfLiteralWords <<
"}";
515 void discardLiteralWordsWithReload(uword x) {
516 assert(NumberOfLiteralWords >= x);
517 NumberOfLiteralWords -= x;
518 if (NumberOfLiteralWords == 0)
522 void discardFirstWordsWithReload(uword x) {
524 if (RunningLength > x) {
525 RunningLength =
static_cast<uword
>(RunningLength - x);
528 x =
static_cast<uword
>(x - RunningLength);
530 size_t toDiscard = x > NumberOfLiteralWords ? NumberOfLiteralWords : x;
531 NumberOfLiteralWords =
532 static_cast<uword
>(NumberOfLiteralWords - toDiscard);
533 x =
static_cast<uword
>(x - toDiscard);
534 if ((x > 0) || (
size() == 0)) {
544 uword NumberOfLiteralWords;
545 EWAHBoolArrayRawIterator<uword> *parent;