This example illustrates verious traversal methods based on iterator/enumerator or algorithms.
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <utility>
#include <cassert>
using namespace std;
extern "C" {
static
{
assert(handle_ptr);
unsigned* cnt = (unsigned*)handle_ptr;
if (*cnt >= 5)
return -1;
*cnt += 1;
cout << bit_idx << ", ";
return 0;
}
}
{
const unsigned char* bits,
unsigned size)
{
for (unsigned i = 0; i < size; ++i)
{
return -1;
cout << offset + bits[i] << ", ";
}
return 0;
}
{
{
return -1;
cout << offset + i << ", ";
}
return 0;
}
};
{
try
{
bv.optimize();
{
auto en = bv.get_enumerator(0);
for (unsigned cnt = 0; en.valid() && cnt < 5; ++en, ++cnt)
cout << *en << ", ";
}
cout << endl;
{
unsigned cnt = 0;
void* ctx_ptr = &cnt;
cout << "\nvisitor return code = " << res << endl;
}
{
cout << "\nvisitor return code = " << res << endl;
}
cout << "\nRange traversal: [" << from << ".." << to << "]" << endl;
{
unsigned cnt = 0;
cout << "\nvisitor return code = " << res << endl;
}
{
cout << "\nvisitor return code = " << res << endl;
}
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}
Compressed bit-vector bvector<> container, set algebraic methods, traversal iterators.
Algorithms for bvector<> (main include)
pre-processor un-defines to avoid global space pollution (internal)
Bitvector Bit-vector container with runtime compression of bits.
bvector_size_type size_type
int visit_each_bit(const BV &bv, void *handle_ptr, bit_visitor_callback_type callback_ptr)
bvector visitor scanner to traverse each 1 bit using C callback
int visit_each_bit_range(const BV &bv, typename BV::size_type left, typename BV::size_type right, void *handle_ptr, bit_visitor_callback_type callback_ptr)
bvector visitor scanner to traverse each bits in range (C callback)
int for_each_bit_range(const BV &bv, typename BV::size_type left, typename BV::size_type right, Func &bit_functor)
bit-vector range visitor to traverse each 1 bit
int for_each_bit(const BV &bv, Func &bit_functor)
bit-vector visitor scanner to traverse each 1 bit using C++ visitor
static int bit_visitor_callback(void *handle_ptr, bm::id_t bit_idx) noexcept
Visitor calss for bm::for_each_bit() algorithm It is NOT a classic functor (with function call operat...
int add_bits(size_type offset, const unsigned char *bits, unsigned size)
Decoded bits callback.
int add_range(size_type offset, size_type size)
Decoded range callback.
bm::bvector<>::size_type size_type