12#include "runninglengthword.h"
38 for (
size_t i = 0; i < n; i++) {
39 ans.
set(
static_cast<size_t>(va_arg(vl,
int)));
48 void trim() { buffer.shrink_to_fit(); }
58 bool get(
const size_t pos)
const {
59 if (pos >=
static_cast<size_t>(sizeinbits))
61 const size_t wordpos = pos / wordinbits;
62 size_t WordChecked = 0;
67 if (wordpos < WordChecked)
70 const uword w = j.dirtyWords()[wordpos - WordChecked];
71 return (w & (
static_cast<uword
>(1) << (pos % wordinbits))) != 0;
83 while (pointer < buffer.size()) {
91 if (buffer[pointer] != 0)
120 operator std::string()
const {
121 std::stringstream ss;
125 friend std::ostream &operator<<(std::ostream &out,
const EWAHBoolArray &a) {
148 if (a.sizeinbits < sizeinbits)
150 else if (sizeinbits < a.sizeinbits)
154 enum { RESERVEMEMORY =
true };
156 typedef EWAHBoolArraySetBitForwardIterator<uword> const_iterator;
185 std::vector<size_t>
toArray()
const;
377 inline size_t addWord(
const uword newdata,
378 const uint32_t bitsthatmatter = 8 *
sizeof(uword));
380 inline void printout(std::ostream &o = std::cout) {
402 inline size_t sizeInBytes()
const {
return buffer.size() *
sizeof(uword); }
439 size_t sizeOnDisk(
const bool savesizeinbits =
true)
const;
449 size_t write(std::ostream &out,
const bool savesizeinbits =
true)
const;
458 size_t write(
char *out,
size_t capacity,
459 const bool savesizeinbits =
true)
const;
480 size_t read(std::istream &in,
const bool savesizeinbits =
true);
489 size_t read(
const char *in,
size_t capacity,
490 const bool savesizeinbits =
true);
496 void readBuffer(std::istream &in,
const size_t buffersize);
555 template <
class container>
556 void appendSetBits(container &out,
const size_t offset = 0)
const;
579 const std::vector<uword> &getBuffer()
const {
return buffer; }
581 enum { wordinbits =
sizeof(uword) * 8 };
588 : buffer(other.buffer), sizeinbits(other.sizeinbits),
589 lastRLW(other.lastRLW) {}
598 sizeinbits = x.sizeinbits;
607 : buffer(std::move(other.buffer)), sizeinbits(other.sizeinbits),
608 lastRLW(other.lastRLW) {}
614 buffer = std::move(x.buffer);
615 sizeinbits = x.sizeinbits;
628 sizeinbits = x.sizeinbits;
683 void assertWordCount(std::string message)
const;
684 void correctWordCount();
685 size_t numberOfWords()
const;
688 inline size_t addLiteralWord(
const uword newdata);
692 size_t addEmptyWord(
const bool v);
698 std::vector<uword> buffer;
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?
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.
EWAHBoolArray logicalor(const EWAHBoolArray &a) const
computes the logical or with another compressed bitmap Return the answer Running time complexity is p...
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.
void makeSameSize(EWAHBoolArray &a)
Make sure the two bitmaps have the same size (padding with zeroes if necessary).
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...
EWAHBoolArray operator-(const EWAHBoolArray &a) const
calls logicalandnot
void fastaddStreamOfDirtyWords(const uword *v, const size_t number)
LikeaddStreamOfDirtyWords but does not return the cost increse, does not update sizeinbits.
EWAHBoolArray operator^(const EWAHBoolArray &a) const
calls logicalxor
EWAHBoolArray logicalandnot(const EWAHBoolArray &a) const
computes the logical and not with another compressed bitmap Return the answer Running time complexity...
EWAHBoolArray(const EWAHBoolArray &other)
Please don't copy your bitmaps! The running time complexity of a copy is the size of the compressed b...
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 sizeInBytes() const
Return the size of the buffer in bytes.
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...
std::vector< size_t > toVector() const
Returns a vector containing the position of the set bits in increasing order.
void inplace_logicalnot()
Apply the logical not operation on this bitmap.
bool get(const size_t pos) const
Query the value of bit i.
size_t bufferSize() const
size (in words) of the underlying STL vector.
EWAHBoolArray operator|(const EWAHBoolArray &a) const
calls logicalor
BitmapStatistics computeStatistics() const
For research purposes.
EWAHBoolArray & operator=(EWAHBoolArray &&x)
Move assignment operator.
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.
EWAHBoolArray & operator=(const EWAHBoolArray &x)
Copies the content of one bitmap onto another.
EWAHBoolArray logicaland(const EWAHBoolArray &a) const
computes the logical and with another compressed bitmap Return the answer Running time complexity is ...
bool set(size_t i)
Set the ith bit to true (starting at zero).
const_iterator begin() const
Returns an iterator that can be used to access the position of the set bits.
EWAHBoolArray(EWAHBoolArray &&other)
Move constructor.
EWAHBoolArray logicalxor(const EWAHBoolArray &a) const
computes the logical xor with another compressed bitmap Return the answer Running time complexity is ...
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...
bool empty() const
Returns true if no bit is set.
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).
EWAHBoolArray operator&(const EWAHBoolArray &a) const
calls logicaland
const_iterator & end() const
Basically a bogus iterator that can be used together with begin() for constructions such as for(EWAHB...
void expensive_copy(const EWAHBoolArray &x)
This is equivalent to the operator =.
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).
void trim()
Recover wasted memory usage.
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.
This is a low-level iterator.
Used to go through the set bits.