Go to the documentation of this file. 1 #ifndef BMSPARSEVEC_SERIAL__H__INCLUDED__
2 #define BMSPARSEVEC_SERIAL__H__INCLUDED__
26 #ifndef BM__H__INCLUDED__
29 # error missing include (bm.h or bm64.h)
96 void set_plain(
unsigned i,
unsigned char* ptr,
size_t buf_size)
106 const unsigned char*
buf()
const {
return buf_.buf(); }
156 template<
typename SV>
191 template<
typename SV>
204 void deserialize(SV& sv,
const unsigned char* buf);
255 const unsigned char* buf,
301 const unsigned char* buf,
345 buffer_coll.calc_stat(&st);
347 buf.resize(st.max_serialize_mem);
350 unsigned char* buf_ptr = buf.data();
356 enc.
put_8((
unsigned char)bo);
358 unsigned char* mbuf1 = enc.
get_pos();
369 size_t addr_bv_size = bvs.
serialize(bv, buf_ptr, buf.size());
370 buf_ptr += addr_bv_size;
376 size_t coll_size = buffer_coll.size();
382 for (
unsigned i = 0; i < buffer_coll.size(); ++i)
385 size_t sz = cbuf.size();
391 for (
unsigned i = 0; i < buffer_coll.size(); ++i)
394 size_t sz = cbuf.size();
395 enc.
memcpy(cbuf.buf(), sz);
398 buf.resize(enc.
size());
405 const unsigned char* buf,
412 unsigned char h1 = dec.
get_8();
413 unsigned char h2 = dec.
get_8();
416 if (h1 !=
'B' && h2 !=
'C')
428 const unsigned char* bv_buf_ptr = dec.
get_pos();
438 dec.
seek((
int)addr_bv_size);
444 if (coll_size != addr_cnt)
449 typedef std::vector<unsigned>::size_type vect_size_type;
450 std::vector<bm::id64_t> buf_size_vec;
451 buf_size_vec.resize(vect_size_type(coll_size));
453 for (
unsigned i = 0; i < coll_size; ++i)
456 buf_size_vec[i] = sz;
462 buf_vect.resize(vect_size_type(coll_size));
463 for (
unsigned i = 0; i < coll_size; ++i)
479 template<
typename SV>
482 bvs_.gap_length_serialization(
false);
487 template<
typename SV>
491 typename SV::statistics sv_stat;
492 sv.calc_stat(&sv_stat);
493 unsigned char* buf = sv_layout.
reserve(sv_stat.max_serialize_mem);
496 unsigned plains = sv.stored_plains();
499 unsigned h_size = 1 + 1 +
515 unsigned char* buf_ptr = buf + h_size;
518 for (i = 0; i < plains; ++i)
520 typename SV::bvector_type_const_ptr bv = sv.get_plain(i);
528 bvs_.serialize(*bv, buf_ptr, sv_stat.max_serialize_mem);
530 sv_layout.
set_plain(i, buf_ptr, buf_size);
532 if (sv_stat.max_serialize_mem > buf_size)
534 sv_stat.max_serialize_mem -= buf_size;
547 bm::encoder enc_m(buf_ptr, sv_stat.max_serialize_mem);
551 const unsigned char* matrix_buf = sv.get_remap_buffer();
557 enc_m.
memcpy(matrix_buf, remap_size);
564 buf_ptr += enc_m.
size();
567 sv_layout.
resize(
size_t(buf_ptr - buf));
575 if (sv.is_compressed())
580 enc.
put_8((
unsigned char)bo);
582 unsigned char matr_s_ser = 1;
588 enc.
put_8(matr_s_ser);
590 enc.
put_64(sv.size_internal());
594 for (i = 0; i < plains; ++i)
596 const unsigned char* p = sv_layout.
get_plain(i);
602 size_t offset = size_t(p - buf);
611 template<
typename SV>
618 template<
typename SV>
620 const unsigned char* buf)
626 unsigned char h1 = dec.
get_8();
627 unsigned char h2 = dec.
get_8();
629 BM_ASSERT(h1 ==
'B' && (h2 ==
'M' || h2 ==
'C'));
631 if (h1 !=
'B' && (h2 !=
'M' || h2 !=
'C'))
634 throw std::logic_error(
"Invalid serialization signature header");
636 BM_THROW(BM_ERR_SERIALFORMAT);
639 unsigned char matr_s_ser = 0;
642 unsigned plains = dec.
get_8();
645 matr_s_ser = dec.
get_8();
646 plains = (unsigned) dec.
get_64();
653 throw std::logic_error(
"Invalid serialization target (64-bit BLOB)");
655 BM_THROW(BM_ERR_SERIALFORMAT);
661 unsigned sv_plains = sv.stored_plains();
662 if (!plains || plains > sv_plains)
665 throw std::logic_error(
"Invalid serialization target (bit depth)");
667 BM_THROW(BM_ERR_SERIALFORMAT);
680 const unsigned char* remap_buf_ptr = 0;
683 for (i = 0; i < plains; ++i)
685 size_t offset = (size_t) dec.
get_64();
690 const unsigned char* bv_buf_ptr = buf + offset;
696 bv->get_blocks_manager();
697 temp_block = bv_bm.check_allocate_tempblock();
699 size_t read_bytes = deserial_.deserialize(*bv, bv_buf_ptr, temp_block);
700 remap_buf_ptr = bv_buf_ptr + read_bytes;
713 unsigned char rh = dec_m.
get_8();
720 size_t remap_size = (size_t) dec_m.
get_64();
721 unsigned char* remap_buf = sv.init_remap_buffer();
723 size_t target_remap_size = sv.remap_size();
724 if (!remap_size || !remap_buf || remap_size != target_remap_size)
727 throw std::logic_error(
"Invalid serialization format (remap size)");
729 BM_THROW(BM_ERR_SERIALFORMAT);
732 dec_m.
memcpy(remap_buf, remap_size);
733 unsigned char end_tok = dec_m.
get_8();
737 throw std::logic_error(
"Invalid serialization format");
739 BM_THROW(BM_ERR_SERIALFORMAT);
747 throw std::logic_error(
"Invalid serialization format (remap error)");
749 BM_THROW(BM_ERR_SERIALFORMAT);
CBC::buffer_type buffer_type
CBC::address_resolver_type address_resolver_type
SV::value_type value_type
size_t plane_size_[SV::sv_plains]
serialized plain size
bm::serializer< bvector_type > bvs_
sparse vector de-serializer
bm::deserializer< typename SV::bvector_type, bm::decoder > deserial_
int sparse_vector_deserialize(SV &sv, const unsigned char *buf, bm::word_t *temp_block=0)
Deserialize sparse vector.
buffer_type buf_
serialization buffer
SV::bvector_type bvector_type
const unsigned char * get_pos() const
Return current buffer pointer.
size_t deserialize(BV &bv, const unsigned char *buf, bm::word_t *temp_block=0)
Bitvector deserialization from memory.
const unsigned char * buf() const
Return serialization buffer pointer.
unsigned char * get_pos() const
Get current memory stream position.
bvector_type::allocator_type::allocator_pool_type allocator_pool_type
unsigned long long int id64_t
Sparse constainer sparse_vector<> for integer types using bit-transposition transform.
size_type serialize(const BV &bv, unsigned char *buf, size_t buf_size)
Bitvector serialization into memory block.
SV::bvector_type bvector_type
SV::value_type value_type
CBC::container_type container_type
CBC::buffer_type buffer_type
void memcpy(unsigned char *dst, size_t count)
read bytes from the decode buffer
size_t size() const
Returns size of the current encoding stream.
sparse_vector_deserializer()
int deserialize(CBC &buffer_coll, const unsigned char *buf, bm::word_t *temp_block=0)
bvector_type * bvector_type_ptr
void sparse_vector_serialize(const SV &sv, sparse_vector_serial_layout< SV > &sv_layout, bm::word_t *temp_block=0)
Serialize sparse vector into a memory buffer(s) structure.
CBC::bvector_type bvector_type
layout class for serialization buffer structure
pre-processor un-defines to avoid global space pollution (internal)
static ByteOrder byte_order()
sparse_vector_serial_layout()
Seriaizer for compressed collections.
~sparse_vector_serial_layout()
size_t capacity() const
return serialization buffer capacity
void gap_length_serialization(bool value)
Set GAP length serialization (serializes GAP levels of the original vector)
CBC compressed_collection_type
unsigned char * reserve(size_t capacity)
resize capacity
allocator_type::allocator_pool_type allocator_pool_type
void put_64(bm::id64_t w)
Puts 64 bits word into encoding buffer.
CBC::bvector_type bvector_type
void serialize(const SV &sv, sparse_vector_serial_layout< SV > &sv_layout)
Serialize sparse vector into a memory buffer(s) structure.
bvector_type::allocator_type::allocator_pool_type allocator_pool_type
serializer< bvector_type >::buffer buffer_type
ad-hoc conditional expressions
void set_pos(unsigned char *buf_pos)
Set current memory stream position.
void resize(size_t ssize)
Set new serialized size.
void deserialize(SV &sv, const unsigned char *buf)
CBC::statistics statistics_type
const typedef bvector_type * bvector_type_const_ptr
Bit-vector serialization class.
Deseriaizer for compressed collections.
void serialize(const CBC &buffer_coll, buffer_type &buf, bm::word_t *temp_block=0)
void put_8(unsigned char c)
Puts one character into the encoding buffer.
const typedef bvector_type * bvector_type_const_ptr
void set_plain(unsigned i, unsigned char *ptr, size_t buf_size)
Set plain output pointer and size.
CBC::address_resolver_type address_resolver_type
ByteOrder
Byte orders recognized by the library.
SV::value_type value_type
void seek(int delta)
change current position
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
CBC compressed_collection_type
size_t size() const
return current serialized size
bm::id64_t get_64()
Reads 64-bit word from the decoding buffer.
bvector_type * bvector_type_ptr
const unsigned char * get_plain(unsigned i) const
Get plain pointer.
unsigned char * plain_ptrs_[SV::sv_plains]
pointers on serialized bit-plains
void memcpy(const unsigned char *src, size_t count)
copy bytes into target buffer or just rewind if src is NULL
unsigned char get_8()
Reads character from the decoding buffer.
blocks_manager< Alloc > blocks_manager_type
SV::bvector_type bvector_type
sparse_vector_serializer()
Class for decoding data from memory buffer.
void freemem()
free memory
CBC::statistics statistics_type