#include <iostream>
#include <memory>
#include <map>
#include <vector>
#include <chrono>
#include <algorithm>
#include <stdexcept>
using namespace std;
#include "bmdbg.h"
{
};
template<bool T>
{ 8, 32, 128, 512 };
static
{
);
return bv;
}
template<typename TM>
{
for (typename TM::iterator it = id_map.begin();
it != id_map.end();
++it)
{
typename TM::mapped_type mp = it->second;
delete mp;
}
id_map.clear();
}
{
typedef std::map<unsigned, TBVector*>
map_type;
{
}
};
{
typedef std::map<unsigned, buffer_type>
map_type;
};
{
typedef std::map<unsigned, buffer_type>
map_type;
};
{
struct vect_addr
{
};
typedef std::map<unsigned, vect_addr>
map_type;
void get_vector(
unsigned id, std::vector<unsigned>& vect)
const;
};
{
map_type::const_iterator it =
idx_.find(
id);
{
vect.resize(vaddr.
size+1);
for (unsigned j = 1; j < vect.size(); ++j)
{
a += (vect[j-1] + 1);
vect[j] = a;
}
}
else
{
vect.resize(0);
}
}
static
{
unsigned method = rand() % 5;
if (method == 0)
{
unsigned seed_id = unsigned(rand()) %
max_size;
{
break;
}
}
else
if (method == 1)
{
unsigned seed_id = unsigned(rand()) %
max_size;
unsigned id = seed_id;
{
break;
id += (rand() % 10);
}
}
else
{
{
unsigned id = unsigned(rand()) %
max_size;
break;
}
}
}
static
{
{
if (!ap->any())
{
std::cerr << "Warning. Empty vector generated!" << std::endl;
}
bvi.
idx_[i] = ap.release();
}
}
static
{
size_t mem_total = 0;
for (bv_index::map_type::const_iterator it = bvi.
idx_.begin();
++it)
{
mem_total += sizeof(void*);
}
return mem_total;
}
static
{
size_t mem_total = 0;
std::vector<unsigned char> buf;
buf.reserve(1024);
for (bv_index::map_type::const_iterator it = bvi.
idx_.begin();
++it)
{
unsigned id = it->first;
vbuf.resize(bvs_size);
::memcpy(vbuf.data(), buf.data(), bvs_size);
mem_total += bvs_size;
mem_total += sizeof(std::vector<unsigned char>::size_type);
#ifdef DEBUG
{
{
throw std::runtime_error("deserialization check failed");
}
}
#endif
}
return mem_total;
}
static
{
size_t mem_total = 0;
for (bv_index::map_type::const_iterator it = bvi.
idx_.begin();
++it)
{
unsigned id = it->first;
unsigned count = bvp->
count();
vect.resize(count);
{
vect.push_back(*en);
}
mem_total +=
sizeof(vect_index::buffer_type::value_type) * vect.size() +
sizeof(vect_index::buffer_type::size_type);
}
return mem_total;
}
static
{
vect.resize(0);
{
vect.push_back(*en);
}
{
for (size_t k = vect.size()-1; k >= 1; --k)
{
vect[k] -= vect[k-1];
--vect[k];
}
}
}
static
{
size_t mem_total = 0;
std::vector<unsigned> vect;
for (bv_index::map_type::const_iterator it = bvi.
idx_.begin();
++it)
{
unsigned id = it->first;
{
uint64_t sum = 0;
for (unsigned k = 1; k < vect.size(); ++k)
{
sum += vect[k];
}
delta_map.push_back(std::make_pair(sum, id));
}
}
std::sort(delta_map.begin(), delta_map.end());
if (delta_map.size() != bvi.
idx_.size())
{
throw std::runtime_error("delta map size is incorrect");
}
unsigned sv_pos = 0;
for (unsigned j = 0; j < delta_map.size(); ++j)
{
unsigned id = delta_map[j].second;
bv_index::map_type::const_iterator it = bvi.
idx_.find(
id);
if (it == bvi.
idx_.end())
continue;
vaddr.
size = (unsigned)(vect.size() - 1);
{
}
}
{
sparse_vect_index::sparse_vector_type::statistics st;
mem_total += st.memory_used;
mem_total += st.memory_used;
}
for (bv_index::map_type::const_iterator it = bvi.
idx_.begin();
++it)
{
unsigned id = it->first;
{
vect.push_back(*en);
}
std::vector<unsigned> svect;
if (svect.size() != vect.size())
{
std::cerr << "Size check failed! id = " << id
<< "size() = " << svect.size()
<< std::endl;
throw std::runtime_error("sparse vector content check failed");
}
for (unsigned k = 0; k < vect.size(); ++k)
{
if (vect[k] != svect[k])
{
std::cerr << "SV content check failed! id = " << id
<< " i=" << k << std::endl;
for (unsigned h = 0; h < vect.size(); ++h)
{
std::cout << "[" << vect[h] << "=" << svect[h] << "], ";
}
std::cout << std::endl;
throw std::runtime_error("sparse vector content check failed");
}
}
}
#ifdef DEBUG
#endif
return mem_total;
}
static
{
for (bv_index::map_type::const_iterator it = bvi.
idx_.begin();
++it)
{
bv_join |= *bvp;
}
std::vector<unsigned> result_set;
{
bv_res.clear(true);
result_set.resize(0);
{
bv_index::map_type::const_iterator it = bvi.
idx_.find(
id);
if (it == bvi.
idx_.end())
continue;
bv_res |= bv;
}
bv_res &= bv_join;
{
result_set.push_back(*en);
}
}
}
static
{
for (bvs_index::map_type::const_iterator it = bvs.
idx_.begin();
++it)
{
if (svect.size() == 0)
{
throw std::runtime_error("empty buffer error");
}
const unsigned char* buf = it->second.data();
}
std::vector<unsigned> result_set;
{
bv_res.clear(true);
result_set.resize(0);
{
bvs_index::map_type::const_iterator it = bvs.
idx_.find(
id);
if (it == bvs.
idx_.end())
continue;
const unsigned char* buf = it->second.data();
}
bv_res &= bv_join;
{
result_set.push_back(*en);
}
}
}
static
{
for (vect_index::map_type::const_iterator it = vecti.
idx_.begin();
++it)
{
if (vect.size() == 0)
{
throw std::runtime_error("empty buffer error");
}
}
std::vector<unsigned> result_set;
{
bv_res.clear(true);
result_set.resize(0);
{
vect_index::map_type::const_iterator it = vecti.
idx_.find(
id);
if (it == vecti.
idx_.end())
continue;
}
bv_res &= bv_join;
{
result_set.push_back(*en);
}
}
}
static
{
std::vector<unsigned> vect;
for (sparse_vect_index::map_type::const_iterator it = svi.
idx_.begin();
++it)
{
unsigned id = it->first;
}
std::vector<unsigned> result_set;
{
bv_res.clear(true);
result_set.resize(0);
{
if (vect.size() == 0)
continue;
}
bv_res &= bv_join;
{
result_set.push_back(*en);
}
}
}
{
try
{
size_t bv_mem_total_MB = bv_mem_total / (1024*1024);
std::cout << "bm::bvector<> memory footprint = "
<< bv_mem_total << " (" << bv_mem_total_MB << "MB)"
<< std::endl;
size_t bvs_mem_total_MB = bvs_mem_total / (1024*1024);
std::cout << "bm::bvector<> BLOB memory footprint = "
<< bvs_mem_total << " (" << bvs_mem_total_MB << "MB)"
<< std::endl;
size_t vecti_mem_total_MB = vecti_mem_total / (1024*1024);
std::cout << "std::vector<unsigned> memory footprint = "
<< vecti_mem_total << " (" << vecti_mem_total_MB << "MB)"
<< std::endl;
size_t svi_mem_total_MB = svi_mem_total / (1024*1024);
std::cout << "bm::sparse_vector<> memory footprint = "
<< svi_mem_total << " (" << svi_mem_total_MB << "MB)"
<< std::endl;
std::cout << std::endl << "Performance (ops/sec):" << 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.
#define BM_DECLARE_TEMP_BLOCK(x)
Algorithms for bvector<> (main include)
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
Sparse constainer sparse_vector<> for integer types using bit-transposition transform.
Algorithms for bm::sparse_vector.
Serialization for sparse_vector<>
Timing utilities for benchmarking (internal)
pre-processor un-defines to avoid global space pollution (internal)
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.
@ opt_compress
compress blocks when possible (GAP/prefix sum)
size_type count() const BMNOEXCEPT
population count (count of ON bits)
void resize(size_type new_size)
Change size of the bvector.
void optimize(bm::word_t *temp_block=0, optmode opt_mode=opt_compress, statistics *stat=0)
Optimize memory bitvector's memory allocation.
bool set_bit(size_type n, bool val=true)
Sets bit n.
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
int compare(const bvector< Alloc > &bvect) const BMNOEXCEPT
Lexicographical comparison with a bitvector.
void calc_stat(struct bm::bvector< Alloc >::statistics *st) const BMNOEXCEPT
Calculates bitvector statistics.
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)
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.
void gap_length_serialization(bool value) BMNOEXCEPT
Set GAP length serialization (serializes GAP levels of the original vector)
void set_compression_level(unsigned clevel) BMNOEXCEPT
Set compression level.
void byte_order_serialization(bool value) BMNOEXCEPT
Set byte-order serialization (for cross platform compatibility)
size_type serialize(const BV &bv, unsigned char *buf, size_t buf_size)
Bitvector serialization into memory block.
succinct sparse vector with runtime compression using bit-slicing / transposition method
value_type get(size_type idx) const BMNOEXCEPT
get specified element without bounds checking
void set(size_type idx, value_type v)
set specified element with bounds checking and automatic resize
void import(const value_type *arr, size_type arr_size, size_type offset=0, bool set_not_null=true)
Import list of elements from a C-style array.
void optimize(bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, typename sparse_vector< Val, BV >::statistics *stat=0)
run memory optimization for all vector planes
@ BM_GAP
GAP compression is ON.
size_t deserialize(BV &bv, const unsigned char *buf, bm::word_t *temp_block=0, const bm::bv_ref_vector< BV > *ref_vect=0)
Bitvector deserialization from a memory BLOB.
void combine_or(BV &bv, It first, It last)
OR Combine bitvector and the iterable sequence.
const unsigned gap_levels
unsigned short gap_word_t
size_t max_serialize_mem
estimated maximum memory for serialization
size_t memory_used
memory usage for all blocks and service tables
Statistical information about bitset's memory allocation details.
std::map< unsigned, TBVector * > map_type
std::map< unsigned, buffer_type > map_type
std::vector< unsigned char > buffer_type
static const bm::gap_word_t _len[bm::gap_levels]
sparse_vector_type sv_storage1_
bm::sparse_vector< unsigned, bm::bvector<> > sparse_vector_type
std::map< unsigned, vect_addr > map_type
std::vector< std::pair< uint64_t, unsigned > > delta_sum_map_type
void get_vector(unsigned id, std::vector< unsigned > &vect) const
sparse_vector_type sv_storage_
std::map< unsigned, buffer_type > map_type
std::vector< unsigned int > buffer_type
static void generate_random_vector(TBVector *bv)
static void generate_bv_index(bv_index &bvi)
const unsigned index_size
static void speed_test_vect_index(const vect_index &vecti)
const unsigned benchmark_ops
static TBVector * construct_bvector()
const unsigned bits_per_vect
static void speed_test_bv_index(const bv_index &bvi)
static size_t calc_memory_footprint(const bv_index &bvi)
static void bv2delta(const TBVector &bv, std::vector< unsigned > &vect)
static size_t convert_bv2bvs(const bv_index &bvi, bvs_index &bvs)
void destroy_map(TM &id_map)
const unsigned result_set_cnt
bm::chrono_taker ::duration_map_type timing_map
static void speed_test_sv_index(const sparse_vect_index &svi)
static size_t convert_bv2vect(const bv_index &bvi, vect_index &vidx)
const unsigned sample_cnt
static size_t convert_bv2sv(const bv_index &bvi, sparse_vect_index &sv_idx)
static void speed_test_bvs_index(const bvs_index &bvs)