#include <assert.h>
#include <iostream>
#include <vector>
using namespace std;
static
{
for (; en.
valid() && cnt < 10; ++en, ++cnt)
cout << *en << ", ";
if (cnt == 10)
cout << " ...";
cout <<
"(size = "<< bv.
size() <<
")" << endl;
}
static
{
bvs.set_compression_level(4);
target_buf.resize(sbuf.size());
::memcpy(target_buf.data(), sbuf.buf(), sbuf.size());
}
static
{
{
}
{
bv_B.resize(10);
bv_A.bit_or(bv_B);
}
{
}
{
}
{
}
{
vector<size_type> vect_B { 1, 2, 4 };
}
{
vector<size_type> vect_B { 1, 2, 4 };
const size_type* arr = &vect_B[0];
}
{
vector<unsigned char> blob;
{
}
}
{
}
}
static
{
{
}
{
bv_B.resize(10);
bv_A.bit_and(bv_B);
}
{
}
{
}
{
vector<unsigned> vect_B { 1, 2, 4 };
}
{
vector<size_type> vect_B { 1, 2, 4 };
const size_type* arr = &vect_B[0];
}
{
vector<unsigned char> blob;
{
}
}
{
}
}
static
{
{
}
{
bv_B.resize(10);
bv_A.bit_xor(bv_B);
}
{
}
{
}
{
vector<unsigned> vect_B { 1, 2, 4 };
}
{
vector<unsigned char> blob;
{
}
}
}
static
{
{
}
{
bv_B.resize(10);
bv_A.bit_sub(bv_B);
}
{
}
{
}
{
vector<size_type> vect_B { 1, 2, 4 };
}
{
vector<size_type> vect_B { 1, 2, 4 };
const size_type* arr = &vect_B[0];
}
{
vector<unsigned char> blob;
{
}
}
{
}
}
static
{
{
}
{
bv_B.resize(10);
bv_R.bit_or_and(bv_A, bv_B);
}
{
}
agg_pipe.set_or_target(&bv_T);
agg_pipe.complete();
}
static
{
{
}
{
bv_A.invert();
}
}
static
{
{
}
cout << endl;
{
{
}
agg_pipe.set_or_target(&bv_T);
agg_pipe.complete();
auto& res_vect = agg_pipe.get_bv_res_vector();
assert(res_vect.size()==3);
for (size_t i = 0; i < res_vect.size(); ++i)
{
if (bv)
else
cout << "Empty result" << endl;
}
}
}
{
try
{
cout << endl << "Set Union (OR) demo" << endl << endl;
cout << endl << "Set Intersect (AND) demo" << endl << endl;
cout << endl << "XOR demo" << endl << endl;
cout << endl << "Set Minus (SUB/AND-NOT) demo" << endl << endl;
cout << endl << "Set Invert (NOT) demo" << endl << endl;
cout << endl << "Set AND-SUB demo" << endl << endl;
cout << endl << "Set AND-OR demo" << endl << endl;
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
}
return 0;
}
Compressed bit-vector bvector<> container, set algebraic methods, traversal iterators.
#define BM_DECLARE_TEMP_BLOCK(x)
Algorithms for fast aggregation of N bvectors.
Algorithms for bvector<> (main include)
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
pre-processor un-defines to avoid global space pollution (internal)
static void DemoAND_SUB()
static void make_BLOB(vector< unsigned char > &target_buf, bm::bvector<> &bv)
static void print_bvector(const bm::bvector<> &bv)
Algorithms for fast aggregation of a group of bit-vectors.
bool combine_and_sub(bvector_type &bv_target)
Aggregate added group of vectors using fused logical AND-SUB Operation does NOT perform an explicit r...
void reset()
Reset aggregate groups, forget all attached vectors.
void combine_or(bvector_type &bv_target)
Aggregate added group of vectors using logical OR Operation does NOT perform an explicit reset of arg...
void combine_and(bvector_type &bv_target)
Aggregate added group of vectors using logical AND Operation does NOT perform an explicit reset of ar...
void set_optimization(typename bvector_type::optmode opt=bvector_type::opt_compress) BMNOEXCEPT
set on-the-fly bit-block compression By default aggregator does not try to optimize result,...
size_t add(const bvector_type *bv, unsigned agr_group=0)
Attach source bit-vector to a argument group (0 or 1).
Constant iterator designed to enumerate "ON" bits.
bool valid() const BMNOEXCEPT
Checks if iterator is still valid.
Bitvector Bit-vector container with runtime compression of bits.
bm::bvector< Alloc > & bit_or(const bm::bvector< Alloc > &bv1, const bm::bvector< Alloc > &bv2, typename bm::bvector< Alloc >::optmode opt_mode=opt_none)
3-operand OR : this := bv1 OR bv2
void merge(bm::bvector< Alloc > &bvect)
Merge/move content from another vector.
bvector< Alloc > & invert()
Invert/NEG all bits It should be noted, invert is affected by size() if size is set - it only inverts...
size_type size() const BMNOEXCEPT
Returns bvector's capacity (number of bits it can store)
bm::bvector< Alloc > & bit_and(const bm::bvector< Alloc > &bv1, const bm::bvector< Alloc > &bv2, typename bm::bvector< Alloc >::optmode opt_mode=opt_none)
3-operand AND : this := bv1 AND bv2
bvector< Alloc > & set(size_type n, bool val=true)
Sets bit n if val is true, clears bit n if val is false.
void resize(size_type new_size)
Change size of the bvector.
bm::bvector< Alloc > & bit_sub(const bm::bvector< Alloc > &bv1, const bm::bvector< Alloc > &bv2, typename bm::bvector< Alloc >::optmode opt_mode=opt_none)
3-operand SUB : this := bv1 MINUS bv2 SUBtraction is also known as AND NOT
void optimize(bm::word_t *temp_block=0, optmode opt_mode=opt_compress, statistics *stat=0)
Optimize memory bitvector's memory allocation.
bvector_size_type size_type
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
void clear(const size_type *ids, size_type ids_size, bm::sort_order so=bm::BM_UNKNOWN)
clear list of bits in this bitset
void combine_operation(const bm::bvector< Alloc > &bvect, bm::operation opcode)
perform a set-algebra operation by operation code
void keep(const size_type *ids, size_type ids_size, bm::sort_order so=bm::BM_UNKNOWN)
Keep list of bits in this bitset, others are cleared.
bm::bvector< Alloc > & bit_or_and(const bm::bvector< Alloc > &bv1, const bm::bvector< Alloc > &bv2, typename bm::bvector< Alloc >::optmode opt_mode=opt_none)
3-operand AND where result is ORed into the terget vector : this |= bv1 AND bv2 TARGET := TARGET OR (...
bm::bvector< Alloc > & bit_xor(const bm::bvector< Alloc > &bv1, const bm::bvector< Alloc > &bv2, typename bm::bvector< Alloc >::optmode opt_mode=opt_none)
3-operand XOR : this := bv1 XOR bv2
Deserializer, performs logical operations between bit-vector and serialized bit-vector.
size_type deserialize(bvector_type &bv, const unsigned char *buf, set_operation op, bool exit_on_one=false)
Deserialize bvector using buffer as set operation argument.
Bit-vector serialization class.
size_type serialize(const BV &bv, unsigned char *buf, size_t buf_size)
Bitvector serialization into memory block.
@ BM_SORTED
input set is sorted (ascending order)
void combine_and(BV &bv, It first, It last)
AND Combine bitvector and the iterable sequence.
void combine_sub(BV &bv, It first, It last)
SUB Combine bitvector and the iterable sequence.
void combine_xor(BV &bv, It first, It last)
XOR Combine bitvector and the iterable sequence.
void combine_or(BV &bv, It first, It last)
OR Combine bitvector and the iterable sequence.