BitMagicC++Library
Public Types | Public Member Functions | Protected Member Functions
bm::serializer< BV > Class Template Reference

Bit-vector serialization class. More...

#include <bmserial.h>

Inheritance diagram for bm::serializer< BV >:
Inheritance graph
[legend]

Public Types

typedef BV bvector_type
 
typedef bvector_type::allocator_type allocator_type
 
typedef bvector_type::blocks_manager_type blocks_manager_type
 
typedef bvector_type::statistics statistics_type
 
typedef byte_buffer< allocator_typebuffer
 

Public Member Functions

 serializer (const allocator_type &alloc=allocator_type(), bm::word_t *temp_block=0)
 Construct serializer. More...
 
 serializer (bm::word_t *temp_block)
 
 ~serializer ()
 
void set_compression_level (unsigned clevel)
 Set compression level. More...
 
unsigned get_compression_level () const
 Get compression level. More...
 
unsigned serialize (const BV &bv, unsigned char *buf, size_t buf_size)
 Bitvector serilization into memory block. More...
 
void serialize (const BV &bv, typename serializer< BV >::buffer &buf, const statistics_type *bv_stat)
 Bitvector serilization into buffer object (it gets resized automatically) More...
 
void gap_length_serialization (bool value)
 Set GAP length serialization (serializes GAP levels of the original vector) More...
 
void byte_order_serialization (bool value)
 Set byte-order serialization (for cross platform compatibility) More...
 

Protected Member Functions

void encode_header (const BV &bv, bm::encoder &enc)
 Encode serialization header information. More...
 
void encode_gap_block (bm::gap_word_t *gap_block, bm::encoder &enc)
 Encode GAP block. More...
 
void gamma_gap_block (bm::gap_word_t *gap_block, bm::encoder &enc)
 Encode GAP block with Elias Gamma coder. More...
 
void gamma_gap_array (const bm::gap_word_t *gap_block, unsigned arr_len, bm::encoder &enc, bool inverted=false)
 Encode GAP block as delta-array with Elias Gamma coder. More...
 
void encode_bit_interval (const bm::word_t *blk, bm::encoder &enc, unsigned size_control)
 Encode BIT block with repeatable runs of zeroes. More...
 

Detailed Description

template<class BV>
class bm::serializer< BV >

Bit-vector serialization class.

Class designed to convert sparse bit-vectors into a single block of memory ready for file or database storage or network transfer.

Reuse of this class for multiple serializations may offer some performance advantage.

Examples:
sample14.cpp, sample4.cpp, and xsample01.cpp.

Definition at line 143 of file bmserial.h.

Member Typedef Documentation

◆ allocator_type

template<class BV>
typedef bvector_type::allocator_type bm::serializer< BV >::allocator_type

Definition at line 147 of file bmserial.h.

◆ blocks_manager_type

template<class BV>
typedef bvector_type::blocks_manager_type bm::serializer< BV >::blocks_manager_type

Definition at line 148 of file bmserial.h.

◆ buffer

template<class BV>
typedef byte_buffer<allocator_type> bm::serializer< BV >::buffer

Definition at line 151 of file bmserial.h.

◆ bvector_type

template<class BV>
typedef BV bm::serializer< BV >::bvector_type

Definition at line 146 of file bmserial.h.

◆ statistics_type

template<class BV>
typedef bvector_type::statistics bm::serializer< BV >::statistics_type

Definition at line 149 of file bmserial.h.

Constructor & Destructor Documentation

◆ serializer() [1/2]

template<class BV >
bm::serializer< BV >::serializer ( const allocator_type alloc = allocator_type(),
bm::word_t temp_block = 0 
)

Construct serializer.

Parameters
alloc- memory allocator
temp_block- temporary block for various operations (if NULL it will be allocated and managed by serializer class) Temp block is used as a scratch memory during serialization, use of external temp block allows to avoid unnecessary re-allocations.

Temp block attached is not owned by the class and NOT deallocated on destruction.

Definition at line 589 of file bmserial.h.

◆ serializer() [2/2]

template<class BV >
bm::serializer< BV >::serializer ( bm::word_t temp_block)

Definition at line 609 of file bmserial.h.

◆ ~serializer()

template<class BV >
bm::serializer< BV >::~serializer ( )

Definition at line 641 of file bmserial.h.

Member Function Documentation

◆ byte_order_serialization()

template<class BV >
void bm::serializer< BV >::byte_order_serialization ( bool  value)

Set byte-order serialization (for cross platform compatibility)

Parameters
value- TRUE serialization format includes byte-order marker

Definition at line 655 of file bmserial.h.

Referenced by convert_bv2bvs(), main(), and bm::serialize().

◆ encode_bit_interval()

template<class BV >
void bm::serializer< BV >::encode_bit_interval ( const bm::word_t blk,
bm::encoder enc,
unsigned  size_control 
)
protected

Encode BIT block with repeatable runs of zeroes.

Definition at line 837 of file bmserial.h.

◆ encode_gap_block()

template<class BV >
void bm::serializer< BV >::encode_gap_block ( bm::gap_word_t gap_block,
bm::encoder enc 
)
protected

Encode GAP block.

Definition at line 784 of file bmserial.h.

◆ encode_header()

template<class BV>
void bm::serializer< BV >::encode_header ( const BV &  bv,
bm::encoder enc 
)
protected

Encode serialization header information.

Definition at line 661 of file bmserial.h.

◆ gamma_gap_array()

template<class BV >
void bm::serializer< BV >::gamma_gap_array ( const bm::gap_word_t gap_block,
unsigned  arr_len,
bm::encoder enc,
bool  inverted = false 
)
protected

Encode GAP block as delta-array with Elias Gamma coder.

Definition at line 737 of file bmserial.h.

◆ gamma_gap_block()

template<class BV >
void bm::serializer< BV >::gamma_gap_block ( bm::gap_word_t gap_block,
bm::encoder enc 
)
protected

Encode GAP block with Elias Gamma coder.

Definition at line 700 of file bmserial.h.

◆ gap_length_serialization()

template<class BV >
void bm::serializer< BV >::gap_length_serialization ( bool  value)

Set GAP length serialization (serializes GAP levels of the original vector)

Parameters
value- when TRUE serialized vector includes GAP levels parameters

Definition at line 649 of file bmserial.h.

Referenced by convert_bv2bvs(), main(), bm::compressed_collection_serializer< CBC >::serialize(), and bm::sparse_vector_serialize().

◆ get_compression_level()

template<class BV >
unsigned bm::serializer< BV >::get_compression_level ( ) const

Get compression level.

Definition at line 635 of file bmserial.h.

◆ serialize() [1/2]

template<class BV>
unsigned bm::serializer< BV >::serialize ( const BV &  bv,
unsigned char *  buf,
size_t  buf_size 
)

Bitvector serilization into memory block.

Parameters
bv- input bitvector
buf- out buffer (pre-allocated) No range checking is done in this method. It is responsibility of caller to allocate sufficient amount of memory using information from calc_stat() function.
buf_size- size of the output buffer
Returns
Size of serialization block.
See also
calc_stat

Definition at line 910 of file bmserial.h.

Referenced by convert_bv2bvs(), main(), bm::compressed_collection_serializer< CBC >::serialize(), and bm::sparse_vector_serialize().

◆ serialize() [2/2]

template<class BV>
void bm::serializer< BV >::serialize ( const BV &  bv,
typename serializer< BV >::buffer buf,
const statistics_type bv_stat 
)

Bitvector serilization into buffer object (it gets resized automatically)

Parameters
bv- input bitvector
buf- output buffer object
bv_stat- input (optional) bit-vector statistics object if NULL, serizlize will compute statistics

Definition at line 888 of file bmserial.h.

◆ set_compression_level()

template<class BV >
void bm::serializer< BV >::set_compression_level ( unsigned  clevel)

Set compression level.

Higher compression takes more time to process.

Parameters
clevel- compression level (0-4)

Definition at line 629 of file bmserial.h.

Referenced by convert_bv2bvs(), main(), bm::compressed_collection_serializer< CBC >::serialize(), and bm::sparse_vector_serialize().


The documentation for this class was generated from the following file: