#include <iostream>
#include <memory>
#include <map>
#include <vector>
#include <chrono>
#include <algorithm>
#include <stdexcept>
#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;
}