BitMagic-C++
bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator Class Reference

Back insert iterator implements buffered insert, faster than generic access assignment. More...

#include <bmstrsparsevec.h>

Collaboration diagram for bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator:

Public Types

typedef std::output_iterator_tag iterator_category
typedef str_sparse_vector< CharType, BV, STR_SIZE > str_sparse_vector_type
typedef str_sparse_vector_typestr_sparse_vector_type_ptr
typedef str_sparse_vector_type::value_type value_type
typedef str_sparse_vector_type::size_type size_type
typedef str_sparse_vector_type::bvector_type bvector_type
typedef bvector_type::allocator_type allocator_type
typedef allocator_type::allocator_pool_type allocator_pool_type
typedef void difference_type
typedef void pointer
typedef void reference

Public Member Functions

 back_insert_iterator () BMNOEXCEPT
 back_insert_iterator (str_sparse_vector_type *sv) BMNOEXCEPT
 back_insert_iterator (const back_insert_iterator &bi) BMNOEXCEPT
back_insert_iteratoroperator= (const back_insert_iterator &bi)
 ~back_insert_iterator ()
void set_optimize (typename bvector_type::optmode opt_mode) BMNOEXCEPT
 Set optimization on load option (deafult: false).
void set_remap (bool flag) BMNOEXCEPT
 Method to configure back inserter to collect statistics on optimal character codes.
unsigned get_remap () const BMNOEXCEPT
 Get curent remap state flags.
back_insert_iteratoroperator= (const value_type *v)
 push value to the vector
template<typename StrType>
back_insert_iteratoroperator= (const StrType &v)
 push value to the vector
back_insert_iteratoroperator* ()
 noop
back_insert_iteratoroperator++ ()
 noop
back_insert_iteratoroperator++ (int)
 noop
void add (const value_type *v)
 add value to the container
void add_null ()
 add NULL (no-value) to the container
void add_null (size_type count)
 add a series of consequitve NULLs (no-value) to the container
void flush ()
 flush the accumulated buffer.
const octet_freq_matrix_typeget_octet_matrix () const noexcept
 Get octet frequence matrix.

Protected Types

typedef bvector_type::block_idx_type block_idx_type

Protected Member Functions

bool empty () const BMNOEXCEPT
 return true if insertion buffer is empty
void add_value (const value_type *v)
 add value to the buffer without changing the NULL vector
void add_remap_stat (const value_type *v)
 account new value as remap statistics
void flush_impl ()

Protected Attributes

str_sparse_vector_typesv_
bvector_typebv_null_
 !< pointer on the parent vector
buffer_matrix_type buf_matrix_
 !< not NULL vector pointer
size_type pos_in_buf_
 !< value buffer
block_idx_type prev_nb_ = 0
 !< buffer position
bvector_type::optmode opt_mode_ = bvector_type::opt_compress
 !< previous block added
unsigned remap_flags_ = 0
 target remapping
octet_freq_matrix_type omatrix_
 octet frequency matrix

Friends

class str_sparse_vector

Detailed Description

template<typename CharType, typename BV, unsigned STR_SIZE>
class bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator

Back insert iterator implements buffered insert, faster than generic access assignment.

Limitations for buffered inserter:

  1. Do not use more than one inserter (into one vector) at the same time
  2. Use method flush() at the end to send the rest of accumulated buffer flush is happening automatically on destruction, but if flush produces an exception (for whatever reason) it will be an exception in destructor. As such, explicit flush() is safer way to finilize the sparse vector load.

Definition at line 339 of file bmstrsparsevec.h.

Member Typedef Documentation

◆ allocator_pool_type

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef allocator_type::allocator_pool_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::allocator_pool_type

Definition at line 351 of file bmstrsparsevec.h.

◆ allocator_type

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef bvector_type::allocator_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::allocator_type

Definition at line 350 of file bmstrsparsevec.h.

◆ block_idx_type

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef bvector_type::block_idx_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::block_idx_type
protected

Definition at line 440 of file bmstrsparsevec.h.

◆ bvector_type

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef str_sparse_vector_type::bvector_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::bvector_type

Definition at line 349 of file bmstrsparsevec.h.

◆ difference_type

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::difference_type

Definition at line 353 of file bmstrsparsevec.h.

◆ iterator_category

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef std::output_iterator_tag bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::iterator_category

Definition at line 343 of file bmstrsparsevec.h.

◆ pointer

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::pointer

Definition at line 354 of file bmstrsparsevec.h.

◆ reference

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::reference

Definition at line 355 of file bmstrsparsevec.h.

◆ size_type

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef str_sparse_vector_type::size_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::size_type

Definition at line 348 of file bmstrsparsevec.h.

◆ str_sparse_vector_type

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef str_sparse_vector<CharType, BV, STR_SIZE> bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::str_sparse_vector_type

Definition at line 345 of file bmstrsparsevec.h.

◆ str_sparse_vector_type_ptr

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef str_sparse_vector_type* bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::str_sparse_vector_type_ptr

Definition at line 346 of file bmstrsparsevec.h.

◆ value_type

template<typename CharType, typename BV, unsigned STR_SIZE>
typedef str_sparse_vector_type::value_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::value_type

Definition at line 347 of file bmstrsparsevec.h.

Constructor & Destructor Documentation

◆ back_insert_iterator() [1/3]

template<class CharType, class BV, unsigned STR_SIZE>
bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::back_insert_iterator ( )

◆ back_insert_iterator() [2/3]

template<class CharType, class BV, unsigned STR_SIZE>
bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::back_insert_iterator ( str_sparse_vector_type * sv)

◆ back_insert_iterator() [3/3]

template<typename CharType, typename BV, unsigned STR_SIZE>
bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::back_insert_iterator ( const back_insert_iterator & bi)

◆ ~back_insert_iterator()

template<class CharType, class BV, unsigned STR_SIZE>
bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::~back_insert_iterator ( )

Definition at line 2847 of file bmstrsparsevec.h.

References flush().

Member Function Documentation

◆ add()

template<typename CharType, typename BV, unsigned STR_SIZE>
void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::add ( const value_type * v)

add value to the container

Definition at line 2899 of file bmstrsparsevec.h.

References add_null(), add_value(), bv_null_, pos_in_buf_, and sv_.

Referenced by operator=(), and operator=().

◆ add_null() [1/2]

template<class CharType, class BV, unsigned STR_SIZE>
void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::add_null ( )

add NULL (no-value) to the container

Definition at line 2918 of file bmstrsparsevec.h.

References add_value().

Referenced by add().

◆ add_null() [2/2]

template<typename CharType, typename BV, unsigned STR_SIZE>
void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::add_null ( size_type count)

add a series of consequitve NULLs (no-value) to the container

◆ add_remap_stat()

template<typename CharType, typename BV, unsigned STR_SIZE>
void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::add_remap_stat ( const value_type * v)
protected

account new value as remap statistics

Definition at line 2938 of file bmstrsparsevec.h.

References BM_ASSERT, omatrix_, and remap_flags_.

Referenced by add_value().

◆ add_value()

template<typename CharType, typename BV, unsigned STR_SIZE>
void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::add_value ( const value_type * v)
protected

add value to the buffer without changing the NULL vector

Parameters
v- value to push back

Definition at line 2978 of file bmstrsparsevec.h.

References add_remap_stat(), BM_ASSERT, buf_matrix_, flush_impl(), pos_in_buf_, remap_flags_, and sv_.

Referenced by add(), and add_null().

◆ empty()

template<class CharType, class BV, unsigned STR_SIZE>
bool bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::empty ( ) const
protected

return true if insertion buffer is empty

Definition at line 2856 of file bmstrsparsevec.h.

References BMNOEXCEPT, pos_in_buf_, and sv_.

◆ flush()

template<class CharType, class BV, unsigned STR_SIZE>
void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::flush ( )

flush the accumulated buffer.

It is important to call flush at the end, before destruction of the inserter. Flush may throw exceptions, which will be possible to intercept. Otherwise inserter is flushed in the destructor.

Definition at line 2865 of file bmstrsparsevec.h.

References buf_matrix_, flush_impl(), remap_flags_, and sv_.

Referenced by ~back_insert_iterator().

◆ flush_impl()

template<class CharType, class BV, unsigned STR_SIZE>
void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::flush_impl ( )
protected

◆ get_octet_matrix()

template<typename CharType, typename BV, unsigned STR_SIZE>
const octet_freq_matrix_type & bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::get_octet_matrix ( ) const
inlinenoexcept

Get octet frequence matrix.

Definition at line 433 of file bmstrsparsevec.h.

References omatrix_.

◆ get_remap()

template<typename CharType, typename BV, unsigned STR_SIZE>
unsigned bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::get_remap ( ) const
inline

Get curent remap state flags.

Definition at line 392 of file bmstrsparsevec.h.

References BMNOEXCEPT, and remap_flags_.

◆ operator*()

template<typename CharType, typename BV, unsigned STR_SIZE>
back_insert_iterator & bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::operator* ( )
inline

noop

Definition at line 407 of file bmstrsparsevec.h.

References back_insert_iterator().

◆ operator++() [1/2]

template<typename CharType, typename BV, unsigned STR_SIZE>
back_insert_iterator & bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::operator++ ( )
inline

noop

Definition at line 409 of file bmstrsparsevec.h.

References back_insert_iterator().

◆ operator++() [2/2]

template<typename CharType, typename BV, unsigned STR_SIZE>
back_insert_iterator & bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::operator++ ( int )
inline

noop

Definition at line 411 of file bmstrsparsevec.h.

References back_insert_iterator().

◆ operator=() [1/3]

template<typename CharType, typename BV, unsigned STR_SIZE>
back_insert_iterator & bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::operator= ( const back_insert_iterator & bi)
inline

Definition at line 362 of file bmstrsparsevec.h.

References back_insert_iterator(), BM_ASSERT, buf_matrix_, flush_impl(), and sv_.

◆ operator=() [2/3]

template<typename CharType, typename BV, unsigned STR_SIZE>
template<typename StrType>
back_insert_iterator & bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::operator= ( const StrType & v)
inline

push value to the vector

Definition at line 401 of file bmstrsparsevec.h.

References add(), and back_insert_iterator().

◆ operator=() [3/3]

template<typename CharType, typename BV, unsigned STR_SIZE>
back_insert_iterator & bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::operator= ( const value_type * v)
inline

push value to the vector

Definition at line 395 of file bmstrsparsevec.h.

References add(), and back_insert_iterator().

◆ set_optimize()

template<typename CharType, typename BV, unsigned STR_SIZE>
void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::set_optimize ( typename bvector_type::optmode opt_mode)
inline

Set optimization on load option (deafult: false).

Definition at line 376 of file bmstrsparsevec.h.

References BMNOEXCEPT, and opt_mode_.

◆ set_remap()

template<typename CharType, typename BV, unsigned STR_SIZE>
void bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::set_remap ( bool flag)
inline

Method to configure back inserter to collect statistics on optimal character codes.

This methos makes back inserter slower, but can be used to accelerate later remap() of the sparse vector. Use flush at the end to apply the remapping. By default inserter does not collect additional statistics.

Important! You should NOT use intermediate flush if you set remapping!

See also
flush

Definition at line 389 of file bmstrsparsevec.h.

References BMNOEXCEPT, and remap_flags_.

◆ str_sparse_vector

template<typename CharType, typename BV, unsigned STR_SIZE>
friend class str_sparse_vector
friend

Definition at line 461 of file bmstrsparsevec.h.

References str_sparse_vector.

Referenced by back_insert_iterator(), and str_sparse_vector.

Field Documentation

◆ buf_matrix_

template<typename CharType, typename BV, unsigned STR_SIZE>
buffer_matrix_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::buf_matrix_
protected

!< not NULL vector pointer

Definition at line 466 of file bmstrsparsevec.h.

Referenced by add_value(), back_insert_iterator(), flush(), flush_impl(), and operator=().

◆ bv_null_

template<typename CharType, typename BV, unsigned STR_SIZE>
bvector_type* bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::bv_null_
protected

!< pointer on the parent vector

Definition at line 465 of file bmstrsparsevec.h.

Referenced by add(), back_insert_iterator(), and back_insert_iterator().

◆ omatrix_

template<typename CharType, typename BV, unsigned STR_SIZE>
octet_freq_matrix_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::omatrix_
protected

octet frequency matrix

Definition at line 473 of file bmstrsparsevec.h.

Referenced by add_remap_stat(), get_octet_matrix(), and bm::str_sparse_vector< CharType, BV, STR_SIZE >::remap().

◆ opt_mode_

template<typename CharType, typename BV, unsigned STR_SIZE>
bvector_type::optmode bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::opt_mode_ = bvector_type::opt_compress
protected

!< previous block added

Definition at line 470 of file bmstrsparsevec.h.

Referenced by flush_impl(), and set_optimize().

◆ pos_in_buf_

template<typename CharType, typename BV, unsigned STR_SIZE>
size_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::pos_in_buf_
protected

!< value buffer

Definition at line 467 of file bmstrsparsevec.h.

Referenced by add(), add_value(), back_insert_iterator(), back_insert_iterator(), empty(), and flush_impl().

◆ prev_nb_

template<typename CharType, typename BV, unsigned STR_SIZE>
block_idx_type bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::prev_nb_ = 0
protected

!< buffer position

Definition at line 468 of file bmstrsparsevec.h.

Referenced by back_insert_iterator(), and flush_impl().

◆ remap_flags_

template<typename CharType, typename BV, unsigned STR_SIZE>
unsigned bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::remap_flags_ = 0
protected

◆ sv_

template<typename CharType, typename BV, unsigned STR_SIZE>
str_sparse_vector_type* bm::str_sparse_vector< CharType, BV, STR_SIZE >::back_insert_iterator::sv_
protected

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