#include <iostream>
#include <string>
#include <vector>
#include <assert.h>
#include "bm.h"
#include "bmstrsparsevec.h"
#include "bmsparsevec_serial.h"
#include "bmundef.h"
using namespace std;
typedef bm::bvector<> bvector_type;
typedef bm::str_sparse_vector<char, bvector_type, 5> str_sv_type;
int main(void)
{
try
{
str_sv_type str_sv1;
str_sv_type str_sv2;
str_sv_type str_sv3;
{
str_sv_type str_sv0;
{
auto bi = str_sv0.get_back_inserter();
for (unsigned i = 0; i < 100000; ++i)
{
bi = "ATGC";
bi = "GCTA";
bi = "GCAA";
bi = "TATA";
} }
str_sv1.remap_from(str_sv0); }
BM_DECLARE_TEMP_BLOCK(tb)
str_sv1.optimize(tb);
str_sv_type::statistics st;
str_sv1.calc_stat(&st);
cout << "Used memory: " << st.memory_used << std::endl;
bm::sparse_vector_serial_layout<str_sv_type> sv_lay;
bm::sparse_vector_serializer<str_sv_type> sv_serializer;
sv_serializer.set_bookmarks(true, 128);
sv_serializer.serialize(str_sv1, sv_lay);
const unsigned char* buf = sv_lay.buf();
cout << "Serialized size = " << sv_lay.size() << endl;
bm::sparse_vector_deserializer<str_sv_type> sv_deserial;
bvector_type::size_type from = 100000;
bvector_type::size_type to = from + 65536;
{
bvector_type bv_mask;
bv_mask.set_range(from, to);
sv_deserial.deserialize(str_sv2, buf, bv_mask);
sv_deserial.deserialize_range(str_sv3, buf, from, to);
char s1[16]; char s2[16]; char s3[16];
for (bvector_type::size_type j = from; j < to; ++j)
{
str_sv1.get(j, s1, sizeof(s1));
str_sv2.get(j, s2, sizeof(s2));
str_sv3.get(j, s3, sizeof(s3));
int cmp;
cmp = ::strcmp(s1, s2);
assert(cmp==0);
cmp = ::strcmp(s1, s3);
assert(cmp==0); (void)cmp;
} cout << "Gather deserialization check OK" << endl;
}
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}