Example rank and select operations.
Example rank and select operations.
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <memory>
{
try
{
std::unique_ptr<bm::bvector<>::rs_index_type>
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;
std::cout << r1c << std::endl;
std::cout << r1c << std::endl;
std::cout << r1c << 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;
}
Compressed bit-vector bvector<> container, set algebraic methods, traversal iterators.
pre-processor un-defines to avoid global space pollution (internal)
Bitvector Bit-vector container with runtime compression of bits.
size_type rank(size_type n, const rs_index_type &rs_idx) const BMNOEXCEPT
Returns rank of specified bit position (same as count_to()).
bool select(size_type rank, size_type &pos, const rs_index_type &rs_idx) const BMNOEXCEPT
select bit-vector position for the specified rank(bitcount)
bvector_size_type size_type
size_type rank_corrected(size_type n, const rs_index_type &rs_idx) const BMNOEXCEPT
Returns rank corrceted by the requested border value (as -1).
rs_index< allocator_type > rs_index_type
void build_rs_index(rs_index_type *rs_idx, bvector< Alloc > *bv_blocks=0) const
compute running total of all blocks in bit vector (rank-select index)