16void fast_logicalor_tocontainer(
size_t n,
const EWAHBoolArray<uword> **inputs,
17 EWAHBoolArray<uword> &container);
26EWAHBoolArray<uword> fast_logicalor(
size_t n,
27 const EWAHBoolArray<uword> **inputs) {
28 EWAHBoolArray<uword> answer;
29 fast_logicalor_tocontainer(n, inputs, answer);
36template <
class uword>
class EWAHBoolArrayIterator {
41 bool hasNext()
const {
return pointer < myparent.size(); }
48 if (compressedwords < rl) {
51 returnvalue = notzero;
57 returnvalue = myparent[pointer];
59 if ((compressedwords == rl) && (literalwords == lw)) {
61 if (pointer < myparent.size())
62 readNewRunningLengthWord();
68 : pointer(other.pointer), myparent(other.myparent),
69 compressedwords(other.compressedwords),
70 literalwords(other.literalwords), rl(other.rl), lw(other.lw),
73 static const uword zero = 0;
74 static const uword notzero =
static_cast<uword
>(~zero);
77 EWAHBoolArrayIterator(
const std::vector<uword> &parent);
78 void readNewRunningLengthWord();
79 friend class EWAHBoolArray<uword>;
81 const std::vector<uword> &myparent;
82 uword compressedwords;
91template <
class uword>
class EWAHBoolArraySetBitForwardIterator {
93 typedef std::forward_iterator_tag iterator_category;
94 typedef size_t *pointer;
95 typedef size_t &reference_type;
96 typedef size_t value_type;
97 typedef ptrdiff_t difference_type;
98 typedef EWAHBoolArraySetBitForwardIterator<uword> type_of_iterator;
104 bool operator<(
const type_of_iterator &o)
const {
109 return answer < o.answer;
112 bool operator<=(
const type_of_iterator &o)
const {
117 return answer <= o.answer;
120 bool operator>(
const type_of_iterator &o)
const {
return !((*this) <= o); }
122 bool operator>=(
const type_of_iterator &o)
const {
return !((*this) < o); }
124 EWAHBoolArraySetBitForwardIterator &operator++() {
132 EWAHBoolArraySetBitForwardIterator operator++(
int) {
133 EWAHBoolArraySetBitForwardIterator old(*
this);
141 bool operator==(
const EWAHBoolArraySetBitForwardIterator<uword> &o)
const {
142 if ((!hasValue) && (!o.hasValue))
144 return (hasValue == o.hasValue) && (answer == o.answer);
147 bool operator!=(
const EWAHBoolArraySetBitForwardIterator<uword> &o)
const {
148 return !(*
this == o);
151 static EWAHBoolArraySetBitForwardIterator<uword> &end() {
152 static EWAHBoolArraySetBitForwardIterator<uword> e;
156 EWAHBoolArraySetBitForwardIterator(
const std::vector<uword> *parent,
157 size_t startpointer = 0)
158 : word(0), position(0), runningLength(0), literalPosition(0),
159 wordPosition(startpointer), wordLength(0), buffer(parent),
160 hasNext(false), hasValue(false), answer(0) {
161 if (wordPosition < buffer->size()) {
162 setRunningLengthWord();
163 hasNext = moveToNext();
171 EWAHBoolArraySetBitForwardIterator()
172 : word(0), position(0), runningLength(0), literalPosition(0),
173 wordPosition(0), wordLength(0), buffer(NULL), hasNext(false),
174 hasValue(false), answer(0) {}
176 inline bool runningHasNext()
const {
return position < runningLength; }
178 inline bool literalHasNext() {
179 while (word == 0 && wordPosition < wordLength) {
180 word = (*buffer)[wordPosition++];
181 literalPosition = position;
182 position += WORD_IN_BITS;
187 inline void setRunningLengthWord() {
188 uword rlw = (*buffer)[wordPosition];
193 position = runningLength;
196 wordLength =
static_cast<uword
>(
200 inline bool moveToNext() {
201 while (!runningHasNext() && !literalHasNext()) {
202 if (wordPosition >= buffer->size()) {
205 setRunningLengthWord();
211 if (runningHasNext()) {
213 if (runningHasNext())
216 uword t =
static_cast<uword
>(word & (~word + 1));
217 answer = literalPosition + countOnes((uword)(t - 1));
220 hasNext = moveToNext();
223 enum { WORD_IN_BITS =
sizeof(uword) * 8 };
226 size_t runningLength;
227 size_t literalPosition;
230 const std::vector<uword> *buffer;
243 : totalliteral(0), totalcompressed(0), runningwordmarker(0),
244 maximumofrunningcounterreached(0) {}
245 size_t getCompressedSize()
const {
return totalliteral + runningwordmarker; }
246 size_t getUncompressedSize()
const {
return totalliteral + totalcompressed; }
247 size_t getNumberOfDirtyWords()
const {
return totalliteral; }
248 size_t getNumberOfCleanWords()
const {
return totalcompressed; }
249 size_t getNumberOfMarkers()
const {
return runningwordmarker; }
250 size_t getOverRuns()
const {
return maximumofrunningcounterreached; }
252 size_t totalcompressed;
253 size_t runningwordmarker;
254 size_t maximumofrunningcounterreached;
260 const size_t dist = (i + wordinbits) / wordinbits -
261 (sizeinbits + wordinbits - 1) / wordinbits;
265 fastaddStreamOfEmptyWords(
false, dist - 1);
268 static_cast<uword
>(
static_cast<uword
>(1) << (i % wordinbits)));
273 lastRunningLengthWord.setRunningLength(
276 static_cast<uword
>(
static_cast<uword
>(1) << (i % wordinbits)));
279 buffer[buffer.size() - 1] |=
280 static_cast<uword
>(
static_cast<uword
>(1) << (i % wordinbits));
282 if (buffer[buffer.size() - 1] ==
static_cast<uword
>(~0)) {
284 buffer[buffer.size() - 1] = 0;
285 buffer.resize(buffer.size() - 1);
286 lastRunningLengthWord.setNumberOfLiteralWords(
static_cast<uword
>(
295 size_t pointer(0), lastrlw(0);
296 while (pointer < buffer.size()) {
305 buffer[pointer] =
static_cast<uword
>(~buffer[pointer]);
309 if (sizeinbits % wordinbits != 0) {
311 const uword maskbogus =
static_cast<uword
>(
312 (
static_cast<uword
>(1) << (sizeinbits % wordinbits)) - 1);
317 addLiteralWord(maskbogus);
325 while (pointer < buffer.size()) {
328 pointer += 1 + rlw.getNumberOfLiteralWords();
333template <
class uword>
334void EWAHBoolArray<uword>::assertWordCount(std::string message)
const {
336 size_t tot = numberOfWords();
337 size_t expected = (sizeinbits + wordinbits - 1) / wordinbits;
338 if (expected != tot) {
339 std::cerr <<
"[assertWordCount] wordinbits " << wordinbits << std::endl;
340 std::cerr <<
"[assertWordCount] sizeinbits " << sizeinbits << std::endl;
341 std::cerr <<
"[assertWordCount] " << message << std::endl;
342 std::cerr <<
"[assertWordCount] number of words " << tot << std::endl;
343 std::cerr <<
"[assertWordCount] expected number of words " << expected
346 throw std::runtime_error(
"bug");
351template <
class uword>
void EWAHBoolArray<uword>::correctWordCount() {
352 size_t tot = numberOfWords();
353 size_t expected = (sizeinbits + wordinbits - 1) / wordinbits;
354 if (expected != tot) {
355 if (tot < expected) {
356 fastaddStreamOfEmptyWords(
false, expected - tot);
358 RunningLengthWord<uword> lastRunningLengthWord(buffer[lastRLW]);
359 lastRunningLengthWord.setRunningLength(
static_cast<uword
>(
360 lastRunningLengthWord.getRunningLength() + expected - tot));
368 while (pointer < buffer.size()) {
375 tot += countOnes((uword)buffer[pointer]);
382template <
class uword>
384 std::vector<size_t> ans;
387 const size_t buffersize = buffer.size();
388 while (pointer < buffersize) {
390 const size_t productofrl =
393 size_t upper_limit = pos + productofrl;
394 for (; pos < upper_limit; ++pos) {
402 for (
size_t k = 0; k < rlwlw; ++k) {
403 uword myword = buffer[pointer];
404 while (myword != 0) {
405 uint64_t t = myword & (~myword + 1);
406 uint32_t r = numberOfTrailingZeros(t);
407 ans.push_back(pos + r);
417template <
class uword>
420 x.buffer.reserve(buffer.size());
431 const uword *dw = i.dirtyWords();
433 x.addLiteralWord(~dw[k]);
438 if ((this->sizeinbits % wordinbits != 0) && !rlw.
getRunningBit()) {
442 const uword maskbogus =
static_cast<uword
>(
443 (
static_cast<uword
>(1) << (this->sizeinbits % wordinbits)) - 1);
444 x.addLiteralWord(maskbogus);
456 const uword *dw = i.dirtyWords();
458 x.addLiteralWord(~dw[k]);
460 const uword maskbogus =
461 (this->sizeinbits % wordinbits != 0)
462 ?
static_cast<uword
>(
463 (
static_cast<uword
>(1) << (this->sizeinbits % wordinbits)) -
465 : ~static_cast<uword>(0);
466 x.addLiteralWord(
static_cast<uword
>(
471 x.sizeinbits = this->sizeinbits;
474template <
class uword>
476 const uint32_t bitsthatmatter) {
477 sizeinbits += bitsthatmatter;
479 return addEmptyWord(0);
480 }
else if (newdata ==
static_cast<uword
>(~0)) {
481 return addEmptyWord(1);
483 return addLiteralWord(newdata);
487template <
class uword>
490 out.write(
reinterpret_cast<const char *
>(&buffer[0]),
491 sizeof(uword) * buffer.size());
494template <
class uword>
496 const size_t buffersize) {
497 buffer.resize(buffersize);
499 in.read(
reinterpret_cast<char *
>(&buffer[0]),
sizeof(uword) * buffersize);
502template <
class uword>
504 const bool savesizeinbits)
const {
506 if (savesizeinbits) {
507 uint64_t sb =
static_cast<uint64_t
>(sizeinbits);
508 out.write(
reinterpret_cast<const char *
>(&sb),
sizeof(sb));
509 written +=
sizeof(uint64_t);
511 const size_t buffersize = buffer.size();
512 uint64_t bs =
static_cast<uint64_t
>(buffersize);
513 out.write(
reinterpret_cast<const char *
>(&bs),
sizeof(bs));
514 written +=
sizeof(uint64_t);
516 if (buffersize > 0) {
517 out.write(
reinterpret_cast<const char *
>(&buffer[0]),
518 static_cast<std::streamsize
>(
sizeof(uword) * buffersize));
519 written +=
sizeof(uword) * buffersize;
524template <
class uword>
526 const bool savesizeinbits)
const {
528 if (savesizeinbits) {
529 uint64_t sb =
static_cast<uint64_t
>(sizeinbits);
530 if (capacity <
sizeof(sb))
532 capacity -=
sizeof(sb);
533 memcpy(out, &sb,
sizeof(sb));
535 written +=
sizeof(uint64_t);
537 const size_t buffersize = buffer.size();
538 uint64_t bs =
static_cast<uint64_t
>(buffersize);
539 if (capacity <
sizeof(bs))
541 capacity -=
sizeof(bs);
542 memcpy(out, &buffersize,
sizeof(bs));
544 written +=
sizeof(uint64_t);
546 if (buffersize > 0) {
547 if (capacity <
sizeof(uword) * buffersize)
549 memcpy(out, &buffer[0],
sizeof(uword) * buffersize);
550 written +=
sizeof(uword) * buffersize;
555template <
class uword>
558 if (savesizeinbits) {
560 in.read(
reinterpret_cast<char *
>(&tmp),
sizeof(tmp));
562 sizeinbits =
static_cast<size_t>(tmp);
566 size_t buffersize(0);
568 in.read(
reinterpret_cast<char *
>(&tmp),
sizeof(tmp));
570 buffersize =
static_cast<size_t>(tmp);
571 buffer.resize(buffersize);
572 if (buffersize > 0) {
573 in.read(
reinterpret_cast<char *
>(&buffer[0]),
574 static_cast<std::streamsize
>(
sizeof(uword) * buffersize));
575 read +=
sizeof(uword) * buffersize;
580template <
class uword>
582 const bool savesizeinbits) {
584 if (savesizeinbits) {
586 if (capacity <
sizeof(tmp))
588 capacity -=
sizeof(tmp);
589 memcpy(
reinterpret_cast<char *
>(&tmp), in,
sizeof(tmp));
592 sizeinbits =
static_cast<size_t>(tmp);
596 size_t buffersize(0);
598 if (capacity <
sizeof(uint64_t))
600 capacity -=
sizeof(uint64_t);
601 memcpy(
reinterpret_cast<char *
>(&tmp), in,
sizeof(uint64_t));
602 in +=
sizeof(uint64_t);
603 read +=
sizeof(uint64_t);
604 buffersize =
static_cast<size_t>(tmp);
605 buffer.resize(buffersize);
606 if (buffersize > 0) {
607 if (capacity <
sizeof(uword) * buffersize)
609 memcpy(&buffer[0], in,
sizeof(uword) * buffersize);
610 read +=
sizeof(uword) * buffersize;
615template <
class uword>
618 uword numbersofar = lastRunningLengthWord.getNumberOfLiteralWords();
622 lastRLW = buffer.size() - 1;
624 lastRunningLengthWord2.setNumberOfLiteralWords(1);
625 buffer.push_back(newdata);
628 lastRunningLengthWord.setNumberOfLiteralWords(
629 static_cast<uword
>(numbersofar + 1));
630 buffer.push_back(newdata);
634template <
class uword>
636 size_t wordsadded = 0;
637 if (totalbits <= sizeinbits)
640 size_t missingbits = totalbits - sizeinbits;
645 size_t remain = sizeinbits % wordinbits;
648 size_t avail = wordinbits - remain;
650 if (missingbits > avail) {
651 missingbits -= avail;
660 if (missingbits > 0) {
661 size_t wordstoadd = missingbits / wordinbits;
662 if ((missingbits % wordinbits) != 0)
665 wordsadded = addStreamOfEmptyWords(
false, wordstoadd);
667 sizeinbits = totalbits;
678 : pointer(0), myparent(&p.getBuffer()), rlw((*myparent)[pointer], this) {}
679 EWAHBoolArrayRawIterator(
const EWAHBoolArrayRawIterator &o)
680 : pointer(o.pointer), myparent(o.myparent), rlw(o.rlw) {}
682 bool hasNext()
const {
return pointer < myparent->size(); }
684 BufferedRunningLengthWord<uword> &next() {
685 rlw.read((*myparent)[pointer]);
686 pointer =
static_cast<size_t>(pointer + rlw.getNumberOfLiteralWords() + 1);
690 const uword *dirtyWords()
const {
691 return myparent->data() +
692 static_cast<size_t>(pointer - rlw.getNumberOfLiteralWords());
695 EWAHBoolArrayRawIterator &operator=(
const EWAHBoolArrayRawIterator &other) {
696 pointer = other.pointer;
697 myparent = other.myparent;
703 const std::vector<uword> *myparent;
704 BufferedRunningLengthWord<uword> rlw;
706 EWAHBoolArrayRawIterator();
709template <
class uword>
714template <
class uword>
719template <
class uword>
723 if (!(i.hasNext() and j.hasNext())) {
724 return (i.hasNext() ==
false) && (j.hasNext() ==
false);
730 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
749 predator.discardRunningWordsWithReload();
753 if (nbre_literal > 0) {
754 for (
size_t k = 0; k < nbre_literal; ++k)
755 if ((rlwi.getLiteralWordAt(k) ^ rlwj.getLiteralWordAt(k)) != 0)
757 rlwi.discardLiteralWordsWithReload(nbre_literal);
758 rlwj.discardLiteralWordsWithReload(nbre_literal);
761 const bool i_remains = rlwi.
size() > 0;
763 return !remaining.nonzero_discharge();
767 buffer.swap(x.buffer);
768 size_t tmp = x.sizeinbits;
769 x.sizeinbits = sizeinbits;
776template <
class uword>
778 if (sizeinbits % wordinbits == 0) {
780 sizeinbits += x.sizeinbits;
786 lastRLW = x.lastRLW + buffer.size() - 1;
787 buffer.resize(buffer.size() - 1);
788 buffer.insert(buffer.end(), x.buffer.begin(), x.buffer.end());
790 lastRLW = x.lastRLW + buffer.size();
791 buffer.insert(buffer.end(), x.buffer.begin(), x.buffer.end());
794 std::stringstream ss;
795 ss <<
"This should really not happen! You are trying to append to a bitmap "
796 "having a fractional number of words, that is, "
797 <<
static_cast<int>(sizeinbits) <<
" bits with a word size in bits of "
798 <<
static_cast<int>(wordinbits) <<
". ";
799 ss <<
"Size of the bitmap being appended: " << x.sizeinbits <<
" bits."
801 throw std::invalid_argument(ss.str());
805template <
class uword>
807 const std::vector<uword> &parent)
808 : pointer(0), myparent(parent), compressedwords(0), literalwords(0), rl(0),
810 if (pointer < myparent.size())
811 readNewRunningLengthWord();
814template <
class uword>
815void EWAHBoolArrayIterator<uword>::readNewRunningLengthWord() {
818 ConstRunningLengthWord<uword> rlw(myparent[pointer]);
819 rl = rlw.getRunningLength();
820 lw = rlw.getNumberOfLiteralWords();
821 b = rlw.getRunningBit();
822 if ((rl == 0) && (lw == 0)) {
823 if (pointer < myparent.size() - 1) {
825 readNewRunningLengthWord();
827 pointer = myparent.size();
832template <
class uword>
837 while (i.hasNext()) {
838 ans.setWord(counter++, i.next());
843template <
class uword>
844template <
class container>
846 const size_t offset)
const {
848 size_t currentoffset(offset);
850 out.reserve(buffer.size() + 64);
851 const size_t buffersize = buffer.size();
852 while (pointer < buffersize) {
854 const size_t productofrl =
857 const size_t upper_limit = currentoffset + productofrl;
858 for (; currentoffset < upper_limit; ++currentoffset) {
859 out.push_back(currentoffset);
862 currentoffset += productofrl;
866 for (uword k = 0; k < rlwlw; ++k) {
867 uword currentword = buffer[pointer];
868 while (currentword != 0) {
869 uword t =
static_cast<uword
>(currentword & (~currentword + 1));
870 uint32_t r = numberOfTrailingZeros(t);
871 out.push_back(currentoffset + r);
874 currentoffset += wordinbits;
880template <
class uword>
882 return !(*
this == x);
885template <
class uword>
888 return (this->toBoolArray() == x);
891template <
class uword>
894 return (this->toBoolArray() != x);
897template <
class uword>
902 sizeinbits += number * wordinbits;
903 size_t wordsadded = 0;
908 buffer[lastRLW]) != 0) ||
912 lastRLW = buffer.size() - 1;
919 const uword whatwecanadd =
920 number < static_cast<size_t>(
922 ?
static_cast<uword
>(number)
923 :
static_cast<uword
>(
926 buffer[lastRLW],
static_cast<uword
>(runlen + whatwecanadd));
928 number -=
static_cast<size_t>(whatwecanadd);
932 lastRLW = buffer.size() - 1;
937 number -=
static_cast<size_t>(
943 lastRLW = buffer.size() - 1;
947 static_cast<uword
>(number));
952template <
class uword>
961 buffer[lastRLW]) != 0) ||
964 lastRLW = buffer.size() - 1;
971 const uword whatwecanadd =
972 number < static_cast<size_t>(
974 ?
static_cast<uword
>(number)
975 :
static_cast<uword
>(
978 buffer[lastRLW],
static_cast<uword
>(runlen + whatwecanadd));
980 number -=
static_cast<size_t>(whatwecanadd);
983 lastRLW = buffer.size() - 1;
988 number -=
static_cast<size_t>(
993 lastRLW = buffer.size() - 1;
997 static_cast<uword
>(number));
1001template <
class uword>
1003 const size_t number) {
1006 uword rlw = buffer[lastRLW];
1007 size_t NumberOfLiteralWords =
1009 if (NumberOfLiteralWords + number <=
1012 rlw,
static_cast<uword
>(NumberOfLiteralWords + number));
1013 buffer[lastRLW] = rlw;
1014 sizeinbits += number * wordinbits;
1015 buffer.insert(buffer.end(), v, v + number);
1019 size_t howmanywecanadd =
1023 buffer[lastRLW] = rlw;
1024 buffer.insert(buffer.end(), v, v + howmanywecanadd);
1025 size_t wordadded = howmanywecanadd;
1026 sizeinbits += howmanywecanadd * wordinbits;
1027 buffer.push_back(0);
1028 lastRLW = buffer.size() - 1;
1031 addStreamOfDirtyWords(v + howmanywecanadd, number - howmanywecanadd);
1035template <
class uword>
1037 const size_t number) {
1040 uword rlw = buffer[lastRLW];
1041 size_t NumberOfLiteralWords =
1043 if (NumberOfLiteralWords + number <=
1046 rlw,
static_cast<uword
>(NumberOfLiteralWords + number));
1047 buffer[lastRLW] = rlw;
1048 for (
size_t i = 0; i < number; ++i)
1049 buffer.push_back(v[i]);
1054 size_t howmanywecanadd =
1058 buffer[lastRLW] = rlw;
1059 for (
size_t i = 0; i < howmanywecanadd; ++i)
1060 buffer.push_back(v[i]);
1063 buffer.push_back(0);
1064 lastRLW = buffer.size() - 1;
1065 fastaddStreamOfDirtyWords(v + howmanywecanadd, number - howmanywecanadd);
1068template <
class uword>
1070 const size_t number) {
1073 uword rlw = buffer[lastRLW];
1074 size_t NumberOfLiteralWords =
1076 if (NumberOfLiteralWords + number <=
1079 rlw,
static_cast<uword
>(NumberOfLiteralWords + number));
1080 buffer[lastRLW] = rlw;
1081 sizeinbits += number * wordinbits;
1082 for (
size_t k = 0; k < number; ++k)
1083 buffer.push_back(~v[k]);
1087 size_t howmanywecanadd =
1091 buffer[lastRLW] = rlw;
1092 for (
size_t k = 0; k < howmanywecanadd; ++k)
1093 buffer.push_back(~v[k]);
1094 size_t wordadded = howmanywecanadd;
1095 sizeinbits += howmanywecanadd * wordinbits;
1096 buffer.push_back(0);
1097 lastRLW = buffer.size() - 1;
1100 addStreamOfDirtyWords(v + howmanywecanadd, number - howmanywecanadd);
1106 const bool noliteralword =
1107 (lastRunningLengthWord.getNumberOfLiteralWords() == 0);
1110 uword runlen = lastRunningLengthWord.getRunningLength();
1111 if ((noliteralword) && (runlen == 0)) {
1112 lastRunningLengthWord.setRunningBit(v);
1114 if ((noliteralword) && (lastRunningLengthWord.getRunningBit() == v) &&
1115 (runlen < RunningLengthWord<uword>::largestrunninglengthcount)) {
1116 lastRunningLengthWord.setRunningLength(
static_cast<uword
>(runlen + 1));
1120 buffer.push_back(0);
1121 lastRLW = buffer.size() - 1;
1122 RunningLengthWord<uword> lastRunningLengthWord2(buffer[lastRLW]);
1123 lastRunningLengthWord2.setRunningBit(v);
1124 lastRunningLengthWord2.setRunningLength(1);
1129template <
class uword>
1130void fast_logicalor_tocontainer(
size_t n,
const EWAHBoolArray<uword> **inputs,
1131 EWAHBoolArray<uword> &container) {
1132 class EWAHBoolArrayPtr {
1135 EWAHBoolArrayPtr(
const EWAHBoolArray<uword> *p,
bool o) : ptr(p), own(o) {}
1136 const EWAHBoolArray<uword> *ptr;
1139 bool operator<(
const EWAHBoolArrayPtr &o)
const {
1140 return o.ptr->sizeInBytes() < ptr->sizeInBytes();
1149 container = *inputs[0];
1152 std::priority_queue<EWAHBoolArrayPtr> pq;
1153 for (
size_t i = 0; i < n; i++) {
1155 pq.push(EWAHBoolArrayPtr(inputs[i],
false));
1157 while (pq.size() > 2) {
1159 EWAHBoolArrayPtr x1 = pq.top();
1162 EWAHBoolArrayPtr x2 = pq.top();
1165 EWAHBoolArray<uword> *buffer =
new EWAHBoolArray<uword>();
1166 x1.ptr->logicalor(*x2.ptr, *buffer);
1174 pq.push(EWAHBoolArrayPtr(buffer,
true));
1176 EWAHBoolArrayPtr x1 = pq.top();
1179 EWAHBoolArrayPtr x2 = pq.top();
1182 x1.ptr->logicalor(*x2.ptr, container);
1192template <
class uword>
1197 container.buffer.reserve(buffer.size() + a.buffer.size());
1200 if (!(i.hasNext() and j.hasNext())) {
1208 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
1217 const size_t index =
1222 predator.discardRunningWordsWithReload();
1227 if (nbre_literal > 0) {
1228 for (
size_t k = 0; k < nbre_literal; ++k) {
1229 container.
addWord(rlwi.getLiteralWordAt(k) | rlwj.getLiteralWordAt(k));
1231 rlwi.discardLiteralWordsWithReload(nbre_literal);
1232 rlwj.discardLiteralWordsWithReload(nbre_literal);
1235 const bool i_remains = rlwi.
size() > 0;
1237 remaining.discharge(container);
1242template <
class uword>
1247 if (!(i.hasNext() and j.hasNext())) {
1254 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
1267 predator.discardRunningWordsWithReload();
1272 if (nbre_literal > 0) {
1273 for (
size_t k = 0; k < nbre_literal; ++k) {
1274 answer += countOnes(
1275 (uword)(rlwi.getLiteralWordAt(k) | rlwj.getLiteralWordAt(k)));
1277 rlwi.discardLiteralWordsWithReload(nbre_literal);
1278 rlwj.discardLiteralWordsWithReload(nbre_literal);
1281 const bool i_remains = rlwi.
size() > 0;
1283 answer += remaining.dischargeCount();
1287template <
class uword>
1292 container.buffer.reserve(buffer.size() + a.buffer.size());
1295 if (!(i.hasNext() and j.hasNext())) {
1302 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
1307 const size_t index =
1313 predator.discardRunningWordsWithReload();
1317 if (nbre_literal > 0) {
1318 for (
size_t k = 0; k < nbre_literal; ++k)
1319 container.
addWord(rlwi.getLiteralWordAt(k) ^ rlwj.getLiteralWordAt(k));
1320 rlwi.discardLiteralWordsWithReload(nbre_literal);
1321 rlwj.discardLiteralWordsWithReload(nbre_literal);
1324 const bool i_remains = rlwi.
size() > 0;
1326 remaining.discharge(container);
1331template <
class uword>
1338 return this->numberOfOnes();
1345 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
1361 predator.discardRunningWordsWithReload();
1365 if (nbre_literal > 0) {
1366 for (
size_t k = 0; k < nbre_literal; ++k) {
1367 answer += countOnes(
1368 (uword)(rlwi.getLiteralWordAt(k) ^ rlwj.getLiteralWordAt(k)));
1370 rlwi.discardLiteralWordsWithReload(nbre_literal);
1371 rlwj.discardLiteralWordsWithReload(nbre_literal);
1374 const bool i_remains = rlwi.
size() > 0;
1376 answer += remaining.dischargeCount();
1380template <
class uword>
1385 container.buffer.reserve(buffer.size() > a.buffer.size() ? buffer.size()
1389 if (!(i.hasNext() and j.hasNext())) {
1397 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
1406 const size_t index =
1411 predator.discardRunningWordsWithReload();
1415 if (nbre_literal > 0) {
1416 for (
size_t k = 0; k < nbre_literal; ++k) {
1417 container.
addWord(rlwi.getLiteralWordAt(k) & rlwj.getLiteralWordAt(k));
1419 rlwi.discardLiteralWordsWithReload(nbre_literal);
1420 rlwj.discardLiteralWordsWithReload(nbre_literal);
1424 while (remain.
size() > 0) {
1426 if (!remain.next()) {
1432 container.assertWordCount(
"logicaland");
1435template <
class uword>
1440 container.buffer.reserve(buffer.size() > a.buffer.size() ? buffer.size()
1448 if (!(i.hasNext())) {
1456 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
1465 }
else if (i_is_prey) {
1466 const size_t index =
1471 const size_t index =
1476 predator.discardRunningWordsWithReload();
1480 if (nbre_literal > 0) {
1481 for (
size_t k = 0; k < nbre_literal; ++k) {
1482 container.
addWord(
static_cast<uword
>(rlwi.getLiteralWordAt(k) &
1483 ~rlwj.getLiteralWordAt(k)));
1485 rlwi.discardLiteralWordsWithReload(nbre_literal);
1486 rlwj.discardLiteralWordsWithReload(nbre_literal);
1489 if (rlwi.
size() > 0) {
1490 rlwi.discharge(container);
1493 while (rlwj.
size() > 0) {
1501 container.assertWordCount(
"logicalandnot");
1504template <
class uword>
1509 return this->numberOfOnes();
1511 if (!(i.hasNext())) {
1519 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
1527 }
else if (i_is_prey) {
1530 const size_t index =
1534 predator.discardRunningWordsWithReload();
1538 if (nbre_literal > 0) {
1539 for (
size_t k = 0; k < nbre_literal; ++k) {
1540 answer += countOnes(
1541 (uword)(rlwi.getLiteralWordAt(k) & (~rlwj.getLiteralWordAt(k))));
1543 rlwi.discardLiteralWordsWithReload(nbre_literal);
1544 rlwj.discardLiteralWordsWithReload(nbre_literal);
1547 const bool i_remains = rlwi.
size() > 0;
1549 answer += rlwi.dischargeCount();
1554template <
class uword>
1558 if (!(i.hasNext() and j.hasNext())) {
1566 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
1577 predator.discardRunningWordsWithReload();
1581 if (nbre_literal > 0) {
1582 for (
size_t k = 0; k < nbre_literal; ++k) {
1583 answer += countOnes(
1584 (uword)(rlwi.getLiteralWordAt(k) & rlwj.getLiteralWordAt(k)));
1586 rlwi.discardLiteralWordsWithReload(nbre_literal);
1587 rlwj.discardLiteralWordsWithReload(nbre_literal);
1593template <
class uword>
1597 if (!(i.hasNext() and j.hasNext())) {
1604 while ((rlwi.
size() > 0) && (rlwj.
size() > 0)) {
1618 predator.discardRunningWordsWithReload();
1622 if (nbre_literal > 0) {
1623 for (
size_t k = 0; k < nbre_literal; ++k) {
1624 if ((rlwi.getLiteralWordAt(k) & rlwj.getLiteralWordAt(k)) != 0)
1627 rlwi.discardLiteralWordsWithReload(nbre_literal);
1628 rlwj.discardLiteralWordsWithReload(nbre_literal);
1634template <
class uword>
1638 while (i.hasNext()) {
1640 ++bs.runningwordmarker;
1645 ++bs.maximumofrunningcounterreached;
1652 std::cout <<
"==printing out EWAHBoolArray==" << std::endl;
1653 std::cout <<
"Number of compressed words: " << buffer.size() << std::endl;
1654 std::cout <<
"Size in bits: " << sizeinbits << std::endl;
1657 while (pointer < buffer.size()) {
1662 std::cout <<
"pointer = " << pointer <<
" running bit=" << b
1663 <<
" running length=" << rl <<
" lit. words=" << lw << std::endl;
1664 for (uword j = 0; j < lw; ++j) {
1665 const uword &w = buffer[pointer + j + 1];
1666 std::cout << toBinaryString(w) << std::endl;
1670 std::cout <<
"==END==" << std::endl;
1673template <
class uword>
1675 return (savesizeinbits ?
sizeof(uint64_t) : 0) +
sizeof(uint64_t) +
1676 sizeof(uword) * buffer.size();
This object is returned by the compressed bitmap as a statistical descriptor.
A dynamic bitset implementation.
Same as RunningLengthWord, except that the values are buffered for quick access.
uword getRunningLength() const
how many words should be filled by the running bit (see previous method)
uword getNumberOfLiteralWords() const
followed by how many literal words?
uword size() const
Total of getRunningLength() and getNumberOfLiteralWords()
bool getRunningBit() const
Which bit is being repeated?
Same as RunningLengthWord, except that the values cannot be modified.
bool getRunningBit() const
Which bit is being repeated?
uword getRunningLength() const
how many words should be filled by the running bit
uword getNumberOfLiteralWords() const
followed by how many literal words?
This class is a compressed bitmap.
bool operator==(const EWAHBoolArray &x) const
We define two EWAHBoolArray as being equal if they have the same set bits.
void appendSetBits(container &out, const size_t offset=0) const
Convert to a list of positions of "set" bits.
void setSizeInBits(const size_t size)
set size in bits.
void logicalxor(const EWAHBoolArray &a, EWAHBoolArray &container) const
computes the logical xor with another compressed bitmap answer goes into container Running time compl...
EWAHBoolArrayRawIterator< uword > raw_iterator() const
To iterate over the compressed data.
size_t padWithZeroes(const size_t totalbits)
make sure the size of the array is totalbits bits by padding with zeroes.
void logicalor(const EWAHBoolArray &a, EWAHBoolArray &container) const
computes the logical or with another compressed bitmap answer goes into container Running time comple...
void fastaddStreamOfDirtyWords(const uword *v, const size_t number)
LikeaddStreamOfDirtyWords but does not return the cost increse, does not update sizeinbits.
void logicalandnot(const EWAHBoolArray &a, EWAHBoolArray &container) const
computes the logical and with another compressed bitmap answer goes into container Running time compl...
size_t addStreamOfNegatedDirtyWords(const uword *v, const size_t number)
add a stream of dirty words, each one negated, returns the number of words added (storage cost increa...
size_t logicalandcount(const EWAHBoolArray &a) const
computes the size (in number of set bits) of the logical and with another compressed bitmap Running t...
void inplace_logicalnot()
Apply the logical not operation on this bitmap.
BitmapStatistics computeStatistics() const
For research purposes.
void fastaddStreamOfEmptyWords(const bool v, size_t number)
Like addStreamOfEmptyWords but addStreamOfEmptyWords but does not return the cost increase,...
void debugprintout() const
Prints a verbose description of the content of the compressed bitmap.
EWAHBoolArray< uword > logicalnot() const
Write the logical not of this bitmap in the provided container.
bool set(size_t i)
Set the ith bit to true (starting at zero).
size_t addWord(const uword newdata, const uint32_t bitsthatmatter=8 *sizeof(uword))
convenience method.
size_t addStreamOfEmptyWords(const bool v, size_t number)
same as addEmptyWord, but you can do several in one shot! returns the number of words added (storage ...
void readBuffer(std::istream &in, const size_t buffersize)
read the buffer from a stream, see method writeBuffer.
size_t logicalxorcount(const EWAHBoolArray &a) const
computes the size (in number of set bits) of the logical xor with another compressed bitmap Running t...
void writeBuffer(std::ostream &out) const
This only writes the content of the buffer (see write()) method.
size_t logicalandnotcount(const EWAHBoolArray &a) const
computes the size (in number of set bits) of the logical and not with another compressed bitmap Runni...
size_t logicalorcount(const EWAHBoolArray &a) const
computes the size (in number of set bits) of the logical or with another compressed bitmap Running ti...
size_t write(std::ostream &out, const bool savesizeinbits=true) const
Save this bitmap to a stream.
size_t read(std::istream &in, const bool savesizeinbits=true)
this is the counterpart to the write method.
void logicaland(const EWAHBoolArray &a, EWAHBoolArray &container) const
computes the logical and with another compressed bitmap answer goes into container Running time compl...
size_t sizeOnDisk(const bool savesizeinbits=true) const
Compute the size on disk assuming that it was saved using the method "write".
size_t numberOfOnes() const
Returns the number of bits set to the value 1.
size_t sizeInBits() const
Return the size in bits of this bitmap (this refers to the uncompressed size in bits).
void reset()
clear the content of the bitmap.
bool operator!=(const EWAHBoolArray &x) const
We define two EWAHBoolArray as being different if they do not have the same set bits.
size_t addStreamOfDirtyWords(const uword *v, const size_t number)
add a stream of dirty words, returns the number of words added (storage cost increase)
bool intersects(const EWAHBoolArray &a) const
tests whether the bitmaps "intersect" (have at least one 1-bit at the same position).
std::vector< size_t > toArray() const
Retrieve the set bits.
void append(const EWAHBoolArray &x)
Appends the content of some other compressed bitmap at the end of the current bitmap.
void swap(EWAHBoolArray &x)
Swap the content of this bitmap with another bitmap.
BoolArray< uword > toBoolArray() const
For convenience, this fully uncompresses the bitmap.
EWAHBoolArrayIterator< uword > uncompress() const
Iterate over the uncompressed words.
Iterate over words of bits from a compressed bitmap.
bool hasNext() const
is there a new word?
uword next()
return next word.
This is a low-level iterator.
size_t operator*() const
Provides the location of the set bit.
uword getNumberOfLiteralWords() const
followed by how many literal words?
void setRunningBit(bool b)
running length of which type of bits
bool getRunningBit() const
Which bit is being repeated?
uword getRunningLength() const
how many words should be filled by the running bit