# bm::serializer< BV > Class Template Reference
[bvector serialization]

Bit-vector serialization class. More...

`#include <bmserial.h>`

## Public Types

typedef BV::allocator_type | allocator_type
typedef BV::blocks_manager_type | blocks_manager_type

## Public Member Functions

| serializer (const allocator_type &alloc=allocator_type())
| ~serializer ()
void | set_compression_level (unsigned clevel)
| Set compression level.
unsigned | get_compression_level () const
| Get compression level.
unsigned | serialize (const BV &bv, unsigned char *buf, unsigned buf_size)
| Bitvector serilization into memory block.
void | gap_length_serialization (bool value)
| Set GAP length serialization (serializes GAP levels of the original vector).
void | byte_order_serialization (bool value)
| Set byte-order serialization (for cross platform compatibility).

## Protected Member Functions

void | encode_header (const BV &bv, bm::encoder &enc)
| Encode serialization header information.
void | encode_gap_block (bm::gap_word_t *gap_block, bm::encoder &enc)
| Encode GAP block.
void | gamma_gap_block (bm::gap_word_t *gap_block, bm::encoder &enc)
| Encode GAP block with Elias Gamma coder.
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.
void | encode_bit_interval (const bm::word_t *blk, bm::encoder &enc, unsigned size_control)
| Encode BIT block with repeatable runs of zeroes.

## Detailed Description

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

Bit-vector serialization class.

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

Examples:

  sample4.cpp.

Definition at line 146 of file bmserial.h.

## Member Typedef Documentation

template<class BV>

typedef BV::allocator_type bm::serializer< BV >::allocator_type

Definition at line 149 of file bmserial.h.

template<class BV>

typedef BV::blocks_manager_type bm::serializer< BV >::blocks_manager_type

Definition at line 150 of file bmserial.h.

## Constructor & Destructor Documentation

template<class BV >

bm::serializer< BV >::serializer | ( | const allocator_type & | alloc = `allocator_type()` | ) | `[inline]`

Definition at line 544 of file bmserial.h.

template<class BV >

bm::serializer< BV >::~serializer | ( |  | ) | `[inline]`

Definition at line 567 of file bmserial.h.

## Member Function Documentation

template<class BV >

void bm::serializer< BV >::byte_order_serialization | ( | bool | value | ) | `[inline]`

Set byte-order serialization (for cross platform compatibility).

Parameters:

  | value | - TRUE serialization format includes byte-order marker

Definition at line 580 of file bmserial.h.

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

template<class BV >

void bm::serializer< BV >::encode_bit_interval | ( | const bm::word_t * | blk,
|  | bm::encoder & | enc,
|  | unsigned | size_control |
| ) |  |  | `[inline, protected]`

Encode BIT block with repeatable runs of zeroes.

Definition at line 762 of file bmserial.h.

References BM_ASSERT, bm::encoder::put_16(), bm::encoder::put_32(), bm::encoder::put_8(), bm::set_block_bit_0runs, and bm::set_block_size.

Referenced by bm::serializer< BV >::serialize().

template<class BV >

void bm::serializer< BV >::encode_gap_block | ( | bm::gap_word_t * | gap_block,
|  | bm::encoder & | enc |
| ) |  |  | `[inline, protected]`

Encode GAP block.

Definition at line 709 of file bmserial.h.

References BM_ASSERT, bm::serializer< BV >::gamma_gap_array(), bm::serializer< BV >::gamma_gap_block(), bm::gap_bit_count(), bm::gap_convert_to_arr(), bm::gap_equiv_len, bm::gap_length(), bm::gap_max_bits, bm::encoder::put_16(), bm::encoder::put_8(), and bm::set_block_bit_1bit.

Referenced by bm::serializer< BV >::serialize().

template<class BV >

void bm::serializer< BV >::encode_header | ( | const BV & | bv,
|  | bm::encoder & | enc |
| ) |  |  | `[inline, protected]`

Encode serialization header information.

Definition at line 586 of file bmserial.h.

References bm::BM_HM_DEFAULT, bm::BM_HM_NO_BO, bm::BM_HM_NO_GAPL, bm::BM_HM_RESIZE, bm::gap_levels, bm::id_max, bm::encoder::put_16(), bm::encoder::put_32(), and bm::encoder::put_8().

Referenced by bm::serializer< BV >::serialize().

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` |
| ) |  |  | `[inline, protected]`

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

Definition at line 662 of file bmserial.h.

References bm::bit_out< TEncoder >::gamma(), bm::encoder::get_pos(), bm::encoder::put_8(), bm::encoder::put_prefixed_array_16(), bm::set_block_arrgap, bm::set_block_arrgap_egamma, bm::set_block_arrgap_egamma_inv, bm::set_block_arrgap_inv, and bm::encoder::set_pos().

Referenced by bm::serializer< BV >::encode_gap_block(), and bm::serializer< BV >::serialize().

template<class BV >

void bm::serializer< BV >::gamma_gap_block | ( | bm::gap_word_t * | gap_block,
|  | bm::encoder & | enc |
| ) |  |  | `[inline, protected]`

Encode GAP block with Elias Gamma coder.

Definition at line 625 of file bmserial.h.

References bm::for_each_dgap(), bm::gap_length(), bm::encoder::get_pos(), bm::encoder::put_16(), bm::encoder::put_8(), bm::set_block_gap, bm::set_block_gap_egamma, and bm::encoder::set_pos().

Referenced by bm::serializer< BV >::encode_gap_block(), and bm::serializer< BV >::serialize().

template<class BV >

void bm::serializer< BV >::gap_length_serialization | ( | bool | value | ) | `[inline]`

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

Parameters:

  | value | - when TRUE serialized vector includes GAP levels parameters

Definition at line 574 of file bmserial.h.

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

template<class BV >

unsigned bm::serializer< BV >::get_compression_level | ( |  | ) | const`[inline]`

Get compression level.

Definition at line 561 of file bmserial.h.

template<class BV >

unsigned bm::serializer< BV >::serialize | ( | const BV & | bv,
|  | unsigned char * | buf,
|  | unsigned | buf_size |
| ) |  |  | `[inline]`

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 814 of file bmserial.h.

References bm::bit_block_calc_count_change(), bm::bit_convert_to_arr(), bm::bit_convert_to_gap(), bm::bit_count_nonzero_size(), bm::bit_find_in_block(), BM_ASSERT, BM_IS_GAP, BMGAP_PTR, bm::serializer< BV >::encode_bit_interval(), bm::serializer< BV >::encode_gap_block(), bm::serializer< BV >::encode_header(), bm::serializer< BV >::gamma_gap_array(), bm::serializer< BV >::gamma_gap_block(), bm::gap_equiv_len, bm::gap_max_bits, bm::encoder::put_16(), bm::encoder::put_8(), bm::encoder::put_prefixed_array_32(), SER_NEXT_GRP, bm::set_block_16one, bm::set_block_16zero, bm::set_block_1one, bm::set_block_1zero, bm::set_block_32one, bm::set_block_32zero, bm::set_block_8one, bm::set_block_8zero, bm::set_block_aone, bm::set_block_azero, bm::set_block_bit, bm::set_block_bit_1bit, bm::set_block_end, bm::set_block_size, bm::set_total_blocks, and bm::encoder::size().

Referenced by bm::serialize().

template<class BV >

void bm::serializer< BV >::set_compression_level | ( | unsigned | clevel | ) | `[inline]`

Set compression level.

Higher compression takes more time to process.

Parameters:

  | clevel | - compression level (0-4)

Definition at line 555 of file bmserial.h.

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

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

- bmserial.h