Example of how to use various bit setting techniques.Several techniques benchmarked to better illustrate relative performance.
#include <iostream>
#include <vector>
#define BM64ADDR
using namespace std;
{
if (first == last)
std::cout << "<EMPTY SET>";
else
for (; first != last; ++first)
std::cout << *first << ";";
std::cout << std::endl;
}
static
std::vector<bm_size_type> &v2,
std::vector<bm_size_type> &v3)
{
{
v1.push_back(j);
}
{
v2.push_back(j);
}
{
v3.push_back(j);
}
}
static
{
{
{
}
{
}
{
}
}
}
static
{
{
{
}
{
}
{
}
}
}
static
std::vector<bm_size_type> &v2,
std::vector<bm_size_type> &v3)
{
{
}
}
static
std::vector<bm_size_type> &v2,
std::vector<bm_size_type> &v3)
{
{
}
}
{
try
{
unsigned cnt = 0;
for (unsigned i = 0; i < sizeof(bits) / sizeof(bits[0]); ++i)
{
bool b = bv1.
set_bit(bits[i],
true);
cnt += b;
}
std::cout << "Number of bits changed:" << cnt << std::endl;
bool b;
std::cout << "Bit 5 set:" << (b ? " yes " : " no ") << std::endl;
std::cout << "Bit 256 set:" << (b ? " yes " : " no ") << std::endl;
std::cout << "Bit 256 set:" << (b ? " yes " : " no ") << std::endl;
std::cout << "Bit 13 set:" << (b ? " yes " : " no ") << std::endl;
bm::combine_or(bv1, &bits[0], &bits[0] + (
sizeof(bits) /
sizeof(bits[0])));
{
std::cout << "Extracted p = " << p << std::endl;
}
std::vector<bm_size_type> v1, v2, v3;
for (unsigned k = 0; k < 1000; ++k)
{
for (i = 0; i < v1.size(); ++i)
s = s + s* v1[i] + i;
for (i = 0; i < v2.size(); ++i)
s = s + s* v2[i] + i;
std::cout << s << "\r";
}
std::cout << std::endl << "Running benchmarks..." << std::endl;
std::cout << std::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)
Timing utilities for benchmarking (internal)
pre-processor un-defines to avoid global space pollution (internal)
Bitvector Bit-vector container with runtime compression of bits.
bool clear_bit(size_type n)
Clears bit n.
bvector< Alloc > & set(size_type n, bool val=true)
Sets bit n if val is true, clears bit n if val is false.
bool set_bit(size_type n, bool val=true)
Sets bit n.
bvector_size_type size_type
bvector< Alloc > & flip(size_type n)
Flips bit n.
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
enumerator end() const
Returns enumerator pointing on the next bit after the last.
void swap(bvector< Alloc > &bvect) BMNOEXCEPT
Exchanges content of bv and this bvector.
void init()
Explicit post-construction initialization. Must be caled to make sure safe use of *_no_check() method...
bvector< Alloc > & set_range(size_type left, size_type right, bool value=true)
Sets all bits in the specified closed interval [left,right] Interval must be inside the bvector's siz...
size_type extract_next(size_type prev)
Finds the number of the next bit ON and sets it to 0.
void clear(const size_type *ids, size_type ids_size, bm::sort_order so=bm::BM_UNKNOWN)
clear list of bits in this bitset
bool set_bit_conditional(size_type n, bool val, bool condition)
Sets bit n only if current value equals the condition.
bvector< Alloc > & reset() BMNOEXCEPT
Clears every bit in the bitvector.
void set_bit_no_check(size_type n)
Set bit without checking preconditions (size, etc)
Utility class to collect performance measurements and statistics.
std::map< std::string, statistics > duration_map_type
test name to duration map
static void print_duration_map(TOut &tout, const duration_map_type &dmap, format fmt=ct_time)
void combine_or(BV &bv, It first, It last)
OR Combine bitvector and the iterable sequence.
const unsigned benchmark_count
void PrintContainer(T first, T last)
static void combine_or_test(std::vector< bm_size_type > &v1, std::vector< bm_size_type > &v2, std::vector< bm_size_type > &v3)
bm::chrono_taker ::duration_map_type timing_map
static void generate_test_vectors(std::vector< bm_size_type > &v1, std::vector< bm_size_type > &v2, std::vector< bm_size_type > &v3)
static void bv_set_bit_no_check_test()
static void bvector_bulk_set_test(std::vector< bm_size_type > &v1, std::vector< bm_size_type > &v2, std::vector< bm_size_type > &v3)
static void bv_set_bit_test()
bm::bvector ::size_type bm_size_type