Example rank and select operations.
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <memory>
{
try
{
std::unique_ptr<bm::bvector<>::rs_index_type>
bv.build_rs_index(rs_idx.get());
auto r1 = bv.rank(20, *rs_idx);
std::cout << r1 << std::endl;
r1 = bv.rank(21, *rs_idx);
std::cout << r1 << std::endl;
r1 = bv.rank(30, *rs_idx);
std::cout << r1 << std::endl;
bool found = bv.select(2, pos, *rs_idx);
if (found)
std::cout << pos << std::endl;
else
std::cout << "Rank not found." << std::endl;
found = bv.
select(2, pos, *rs_idx);
if (found)
std::cout << pos << std::endl;
else
std::cout << "Rank not found." << std::endl;
found = bv.
select(5, pos, *rs_idx);
if (found)
std::cout << pos << std::endl;
else
std::cout << "Rank not found." << std::endl;
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}
bool select(size_type rank, size_type &pos, const rs_index_type &rs_idx) const
select bit-vector position for the specified rank(bitcount)