BitMagic-C++
Data Structures | Public Types | Public Member Functions | Data Fields | Protected Types | Protected Member Functions | Friends
bm::sparse_vector< Val, BV > Class Template Reference

sparse vector with runtime compression using bit transposition method More...

#include <bmsparsevec.h>

Inheritance diagram for bm::sparse_vector< Val, BV >:
Inheritance graph
[legend]
Collaboration diagram for bm::sparse_vector< Val, BV >:
Collaboration graph
[legend]

Data Structures

class  back_insert_iterator
 Back insert iterator implements buffered insert, faster than generic access assignment. More...
 
class  const_iterator
 Const iterator to traverse the sparse vector. More...
 
struct  is_remap_support
 
struct  is_rsc_support
 
class  reference
 Reference class to access elements via common [] operator. More...
 
struct  statistics
 

Public Types

typedef Val value_type
 
typedef BV bvector_type
 
typedef bvector_typebvector_type_ptr
 
typedef bvector_type::size_type size_type
 
typedef bvector_type::block_idx_type block_idx_type
 
typedef const bvector_typebvector_type_const_ptr
 
typedef const value_typeconst_reference
 
typedef BV::allocator_type allocator_type
 
typedef bvector_type::allocation_policy allocation_policy_type
 
typedef bvector_type::enumerator bvector_enumerator_type
 
typedef allocator_type::allocator_pool_type allocator_pool_type
 
typedef bm::basic_bmatrix< BV > bmatrix_type
 
typedef base_sparse_vector< Val, BV, 1 > parent_type
 
- Public Types inherited from bm::base_sparse_vector< Val, BV, 1 >
enum  bit_plains
 
enum  vector_capacity
 
typedef Val value_type
 
typedef BV bvector_type
 
typedef BV::size_type size_type
 
typedef bvector_typebvector_type_ptr
 
typedef const bvector_typebvector_type_const_ptr
 
typedef const value_typeconst_reference
 
typedef BV::allocator_type allocator_type
 
typedef bvector_type::allocation_policy allocation_policy_type
 
typedef bvector_type::enumerator bvector_enumerator_type
 
typedef allocator_type::allocator_pool_type allocator_pool_type
 
typedef bm::basic_bmatrix< BV > bmatrix_type
 

Public Member Functions

void swap (sparse_vector< Val, BV > &sv) BMNOEXCEPT
 content exchange More...
 
void set_allocator_pool (allocator_pool_type *pool_ptr) BMNOEXCEPT
 Set allocator pool for local (non-threaded) memory cyclic(lots of alloc-free ops) opertations. More...
 
Construction and assignment
 sparse_vector (bm::null_support null_able=bm::no_null, allocation_policy_type ap=allocation_policy_type(), size_type bv_max_size=bm::id_max, const allocator_type &alloc=allocator_type())
 Sparse vector constructor. More...
 
 sparse_vector (const sparse_vector< Val, BV > &sv)
 
sparse_vector< Val, BV > & operator= (const sparse_vector< Val, BV > &sv)
 
 sparse_vector (sparse_vector< Val, BV > &&sv) BMNOEXCEPT
 
sparse_vector< Val, BV > & operator= (sparse_vector< Val, BV > &&sv) BMNOEXCEPT
 
 ~sparse_vector () BMNOEXCEPT
 
Element access
reference operator[] (size_type idx) BMNOEXCEPT
 Operator to get write access to an element. More...
 
value_type operator[] (size_type idx) const BMNOEXCEPT
 get specified element without bounds checking More...
 
value_type at (size_type idx) const
 access specified element with bounds checking More...
 
value_type get (size_type idx) const BMNOEXCEPT
 get specified element without bounds checking More...
 
void set (size_type idx, value_type v)
 set specified element with bounds checking and automatic resize More...
 
void inc (size_type idx)
 increment specified element by one More...
 
void push_back (value_type v)
 push value back into vector More...
 
void push_back_null (size_type count)
 push back specified amount of NULL values More...
 
void insert (size_type idx, value_type v)
 insert specified element into container More...
 
void erase (size_type idx)
 erase specified element from container More...
 
void clear (size_type idx, bool set_null)
 clear specified element with bounds checking and automatic resize More...
 
Iterator access
const_iterator begin () const BMNOEXCEPT
 Provide const iterator access to container content. More...
 
const_iterator end () const BMNOEXCEPT
 Provide const iterator access to the end. More...
 
const_iterator get_const_iterator (size_type idx) const BMNOEXCEPT
 Get const_itertor re-positioned to specific element. More...
 
back_insert_iterator get_back_inserter ()
 Provide back insert iterator Back insert iterator implements buffered insertion, which is faster, than random access or push_back. More...
 
Loading of sparse vector from C-style array
void import (const value_type *arr, size_type arr_size, size_type offset=0, bool set_not_null=true)
 Import list of elements from a C-style array. More...
 
void import_back (const value_type *arr, size_type arr_size, bool set_not_null=true)
 Import list of elements from a C-style array (pushed back) More...
 
Export content to C-style array
size_type decode (value_type *arr, size_type idx_from, size_type dec_size, bool zero_mem=true) const
 Bulk export list of elements to a C-style array. More...
 
size_type gather (value_type *arr, const size_type *idx, size_type size, bm::sort_order sorted_idx) const
 Gather elements to a C-style array. More...
 
Clear
void clear_all (bool free_mem) BMNOEXCEPT
 resize to zero, free memory More...
 
void clear () BMNOEXCEPT
 resize to zero, free memory More...
 
sparse_vector< Val, BV > & clear_range (size_type left, size_type right, bool set_null=false)
 clear range (assign bit 0 for all plains) More...
 
Size, etc
size_type size () const BMNOEXCEPT
 return size of the vector More...
 
bool empty () const BMNOEXCEPT
 return true if vector is empty More...
 
void resize (size_type sz)
 resize vector More...
 
void sync_size () BMNOEXCEPT
 recalculate size to exclude tail NULL elements After this call size() will return the true size of the vector More...
 
Comparison
bool equal (const sparse_vector< Val, BV > &sv, bm::null_support null_able=bm::use_null) const BMNOEXCEPT
 check if another sparse vector has the same content and size More...
 
Element comparison
int compare (size_type idx, const value_type val) const BMNOEXCEPT
 Compare vector element with argument. More...
 
Memory optimization
void optimize (bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, typename sparse_vector< Val, BV >::statistics *stat=0)
 run memory optimization for all vector plains More...
 
void optimize_gap_size ()
 Optimize sizes of GAP blocks. More...
 
void calc_stat (struct sparse_vector< Val, BV >::statistics *st) const BMNOEXCEPT
 Calculates memory statistics. More...
 
Merge, split, partition data
sparse_vector< Val, BV > & join (const sparse_vector< Val, BV > &sv)
 join all with another sparse vector using OR operation More...
 
sparse_vector< Val, BV > & merge (sparse_vector< Val, BV > &sv)
 merge with another sparse vector using OR operation Merge is different from join(), because it borrows data from the source vector, so it gets modified. More...
 
void copy_range (const sparse_vector< Val, BV > &sv, size_type left, size_type right, bm::null_support splice_null=bm::use_null)
 copy range of values from another sparse vector More...
 
void filter (const bvector_type &bv_mask)
 Apply value filter, defined by mask vector. More...
 
- Public Member Functions inherited from bm::base_sparse_vector< Val, BV, 1 >
 base_sparse_vector ()
 
 base_sparse_vector (bm::null_support null_able, allocation_policy_type ap, size_type bv_max_size, const allocator_type &alloc)
 
 base_sparse_vector (const base_sparse_vector< Val, BV, MAX_SIZE > &bsv)
 
 base_sparse_vector (base_sparse_vector< Val, BV, MAX_SIZE > &&bsv) BMNOEXCEPT
 
void swap (base_sparse_vector< Val, BV, MAX_SIZE > &bsv) BMNOEXCEPT
 
size_type size () const BMNOEXCEPT
 
void resize (size_type new_size)
 
void clear_range (size_type left, size_type right, bool set_null)
 
void clear_all (bool free_mem=true) BMNOEXCEPT
 resize to zero, free memory More...
 
bool empty () const BMNOEXCEPT
 
void optimize (bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, typename bvector_type::statistics *stat=0)
 run memory optimization for all bit-vector rows More...
 
void calc_stat (typename bvector_type::statistics *st) const BMNOEXCEPT
 Calculates memory statistics. More...
 
bool equal (const base_sparse_vector< Val, BV, MAX_SIZE > &sv, bm::null_support null_able=bm::use_null) const BMNOEXCEPT
 check if another sparse vector has the same content and size More...
 
bool is_nullable () const BMNOEXCEPT
 check if container supports NULL(unassigned) values More...
 
bm::null_support get_null_support () const BMNOEXCEPT
 check if container supports NULL(unassigned) values More...
 
const bvector_typeget_null_bvector () const BMNOEXCEPT
 Get bit-vector of assigned values or NULL (if not constructed that way) More...
 
bool is_null (size_type idx) const BMNOEXCEPT
 test if specified element is NULL More...
 
bvector_type_ptr get_plain (unsigned i)
 get access to bit-plain, function checks and creates a plain More...
 
bvector_type_const_ptr get_plain (unsigned i) const BMNOEXCEPT
 get read-only access to bit-plain More...
 
unsigned effective_plains () const BMNOEXCEPT
 Number of effective bit-plains in the value type. More...
 
bvector_type_ptr plain (unsigned i) BMNOEXCEPT
 get access to bit-plain as is (can return NULL) More...
 
bvector_type_const_ptr plain (unsigned i) const BMNOEXCEPT
 
bvector_typeget_null_bvect ()
 
void free_plain (unsigned i)
 free memory in bit-plain More...
 
bm::id64_t get_plains_mask (unsigned element_idx) const BMNOEXCEPT
 
const bmatrix_typeget_bmatrix () const BMNOEXCEPT
 

Data Fields

friend const_iterator
 
friend back_insert_iterator
 

Protected Types

enum  octet_plains { sv_octet_plains = sizeof(value_type) }
 
enum  buf_size_e { n_buf_size = 1024 * 8 }
 
typedef bm::heap_matrix< unsigned char, sizeof(value_type), 256, typename bvector_type::allocator_typeremap_matrix_type
 unused remap matrix type for compatibility with the sparse serializer More...
 
- Protected Types inherited from bm::base_sparse_vector< Val, BV, 1 >
typedef bvector_type::block_idx_type block_idx_type
 

Protected Member Functions

void set_value (size_type idx, value_type v)
 set value without checking boundaries More...
 
void set_value_no_null (size_type idx, value_type v)
 set value without checking boundaries or support of NULL More...
 
void push_back_no_null (value_type v)
 push value back into vector without NULL semantics More...
 
void insert_value (size_type idx, value_type v)
 insert value without checking boundaries More...
 
void insert_value_no_null (size_type idx, value_type v)
 insert value without checking boundaries or support of NULL More...
 
void resize_internal (size_type sz)
 
size_type size_internal () const BMNOEXCEPT
 
bool is_remap () const BMNOEXCEPT
 
size_t remap_size () const BMNOEXCEPT
 
const unsigned char * get_remap_buffer () const BMNOEXCEPT
 
unsigned char * init_remap_buffer () BMNOEXCEPT
 
void set_remap () BMNOEXCEPT
 
const remap_matrix_typeget_remap_matrix () const
 
remap_matrix_typeget_remap_matrix ()
 
bool resolve_range (size_type from, size_type to, size_type *idx_from, size_type *idx_to) const BMNOEXCEPT
 
void inc_no_null (size_type idx)
 Increment element by 1 without chnaging NULL vector or size. More...
 
void inc_no_null (size_type idx, value_type v)
 increment by v without chnaging NULL vector or size More...
 
- Protected Member Functions inherited from bm::base_sparse_vector< Val, BV, 1 >
void copy_from (const base_sparse_vector< Val, BV, MAX_SIZE > &bsv)
 
void clear_value_plains_from (unsigned plain_idx, size_type idx)
 
void insert_clear_value_plains_from (unsigned plain_idx, size_type idx)
 
void erase_column (size_type idx)
 
void insert_null (size_type idx, bool not_null)
 
void optimize_block (block_idx_type nb)
 optimize block in all matrix plains More...
 
void copy_range_plains (const base_sparse_vector< Val, BV, MAX_SIZE > &bsv, typename base_sparse_vector< Val, BV, MAX_SIZE >::size_type left, typename base_sparse_vector< Val, BV, MAX_SIZE >::size_type right, bm::null_support splice_null)
 Perform copy_range() on a set of plains. More...
 

Friends

template<class V , class SV >
class rsc_sparse_vector
 
template<class SVect >
class sparse_vector_scanner
 
template<class SVect >
class sparse_vector_serializer
 
template<class SVect >
class sparse_vector_deserializer
 

Various traits

void set_null (size_type idx)
 set specified element to unassigned value (NULL) More...
 
static bool is_compressed () BMNOEXCEPT
 trait if sparse vector is "compressed" (false) More...
 

Access to internals

void sync (bool)
 syncronize internal structures More...
 
size_type extract (value_type *arr, size_type size, size_type offset=0, bool zero_mem=true) const BMNOEXCEPT2
 Bulk export list of elements to a C-style array. More...
 
size_type extract_range (value_type *arr, size_type size, size_type offset, bool zero_mem=true) const
 extract small window without use of masking vector More...
 
size_type extract_plains (value_type *arr, size_type size, size_type offset, bool zero_mem=true) const
 extract medium window without use of masking vector More...
 
size_type effective_size () const BMNOEXCEPT
 size of sparse vector (may be different for RSC) More...
 
size_type effective_vector_max () const BMNOEXCEPT
 Always 1 (non-matrix type) More...
 
static size_type translate_address (size_type i) BMNOEXCEPT
 address translation for this type of container More...
 
static void throw_range_error (const char *err_msg)
 throw range error More...
 
static void throw_bad_alloc ()
 throw bad alloc More...
 
static bool find_rank (size_type rank, size_type &pos) BMNOEXCEPT
 find position of compressed element by its rank More...
 

Additional Inherited Members

- Static Public Member Functions inherited from bm::base_sparse_vector< Val, BV, 1 >
static unsigned plains () BMNOEXCEPT
 get total number of bit-plains in the vector More...
 
static unsigned stored_plains () BMNOEXCEPT
 Number of stored bit-plains (value plains + extra. More...
 
- Static Protected Member Functions inherited from bm::base_sparse_vector< Val, BV, 1 >
static unsigned value_bits () BMNOEXCEPT
 Number of total bit-plains in the value type. More...
 
static unsigned null_plain () BMNOEXCEPT
 plain index for the "NOT NULL" flags plain More...
 
- Protected Attributes inherited from bm::base_sparse_vector< Val, BV, 1 >
bmatrix_type bmatr_
 bit-transposed matrix More...
 
size_type size_
 array size More...
 
unsigned effective_plains_
 

Detailed Description

template<class Val, class BV>
class bm::sparse_vector< Val, BV >

sparse vector with runtime compression using bit transposition method

Sparse vector implements variable bit-depth storage model. Initial data is bit-transposed into bit-planes so each element may use less memory than the original native data type prescribes. For example, 32-bit integer may only use 20 bits.

Another level of compression is provided by bit-vector (BV template parameter) used for storing bit planes. bvector<> implements varians of on the fly block compression, so if a significant area of a sparse vector uses less bits - it will save memory.

Overall it provides variable bit-depth compression, sparse compression in bit-plains.

Examples:
inv_list.cpp, rscsample01.cpp, rscsample02.cpp, rscsample03.cpp, rscsample04.cpp, rscsample05.cpp, svsample01.cpp, svsample02.cpp, svsample03.cpp, svsample04.cpp, svsample05.cpp, svsample06.cpp, svsample07.cpp, svsample08.cpp, svsample09.cpp, xsample01.cpp, xsample02.cpp, xsample03.cpp, xsample06.cpp, xsample07.cpp, and xsample08.cpp.

Definition at line 81 of file bmsparsevec.h.

Member Typedef Documentation

◆ allocation_policy_type

template<class Val, class BV>
typedef bvector_type::allocation_policy bm::sparse_vector< Val, BV >::allocation_policy_type

Definition at line 92 of file bmsparsevec.h.

◆ allocator_pool_type

template<class Val, class BV>
typedef allocator_type::allocator_pool_type bm::sparse_vector< Val, BV >::allocator_pool_type

Definition at line 94 of file bmsparsevec.h.

◆ allocator_type

template<class Val, class BV>
typedef BV::allocator_type bm::sparse_vector< Val, BV >::allocator_type

Definition at line 91 of file bmsparsevec.h.

◆ block_idx_type

template<class Val, class BV>
typedef bvector_type::block_idx_type bm::sparse_vector< Val, BV >::block_idx_type

Definition at line 88 of file bmsparsevec.h.

◆ bmatrix_type

template<class Val, class BV>
typedef bm::basic_bmatrix<BV> bm::sparse_vector< Val, BV >::bmatrix_type

Definition at line 95 of file bmsparsevec.h.

◆ bvector_enumerator_type

template<class Val, class BV>
typedef bvector_type::enumerator bm::sparse_vector< Val, BV >::bvector_enumerator_type

Definition at line 93 of file bmsparsevec.h.

◆ bvector_type

template<class Val, class BV>
typedef BV bm::sparse_vector< Val, BV >::bvector_type

Definition at line 85 of file bmsparsevec.h.

◆ bvector_type_const_ptr

template<class Val, class BV>
typedef const bvector_type* bm::sparse_vector< Val, BV >::bvector_type_const_ptr

Definition at line 89 of file bmsparsevec.h.

◆ bvector_type_ptr

template<class Val, class BV>
typedef bvector_type* bm::sparse_vector< Val, BV >::bvector_type_ptr

Definition at line 86 of file bmsparsevec.h.

◆ const_reference

template<class Val, class BV>
typedef const value_type& bm::sparse_vector< Val, BV >::const_reference

Definition at line 90 of file bmsparsevec.h.

◆ parent_type

template<class Val, class BV>
typedef base_sparse_vector<Val, BV, 1> bm::sparse_vector< Val, BV >::parent_type

Definition at line 96 of file bmsparsevec.h.

◆ remap_matrix_type

template<class Val, class BV>
typedef bm::heap_matrix<unsigned char, sizeof(value_type), 256, typename bvector_type::allocator_type> bm::sparse_vector< Val, BV >::remap_matrix_type
protected

unused remap matrix type for compatibility with the sparse serializer

Definition at line 911 of file bmsparsevec.h.

◆ size_type

template<class Val, class BV>
typedef bvector_type::size_type bm::sparse_vector< Val, BV >::size_type

Definition at line 87 of file bmsparsevec.h.

◆ value_type

template<class Val, class BV>
typedef Val bm::sparse_vector< Val, BV >::value_type

Definition at line 84 of file bmsparsevec.h.

Member Enumeration Documentation

◆ buf_size_e

template<class Val, class BV>
enum bm::sparse_vector::buf_size_e
protected
Enumerator
n_buf_size 

Definition at line 876 of file bmsparsevec.h.

◆ octet_plains

template<class Val, class BV>
enum bm::sparse_vector::octet_plains
protected
Enumerator
sv_octet_plains 

Definition at line 872 of file bmsparsevec.h.

Constructor & Destructor Documentation

◆ sparse_vector() [1/3]

template<class Val , class BV >
bm::sparse_vector< Val, BV >::sparse_vector ( bm::null_support  null_able = bm::no_null,
allocation_policy_type  ap = allocation_policy_type(),
size_type  bv_max_size = bm::id_max,
const allocator_type alloc = allocator_type() 
)

Sparse vector constructor.

Parameters
null_able- defines if vector supports NULL values flag by default it is OFF, use bm::use_null to enable it
ap- allocation strategy for underlying bit-vectors Default allocation policy uses BM_BIT setting (fastest access)
bv_max_size- maximum possible size of underlying bit-vectors Please note, this is NOT size of svector itself, it is dynamic upper limit which should be used very carefully if we surely know the ultimate size
alloc- allocator for bit-vectors
See also
bvector<>
bm::bvector<>::allocation_policy
bm::startegy

Definition at line 943 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::operator=().

◆ sparse_vector() [2/3]

template<class Val, class BV>
bm::sparse_vector< Val, BV >::sparse_vector ( const sparse_vector< Val, BV > &  sv)

copy-ctor

Definition at line 954 of file bmsparsevec.h.

◆ sparse_vector() [3/3]

template<class Val, class BV>
bm::sparse_vector< Val, BV >::sparse_vector ( sparse_vector< Val, BV > &&  sv)

move-ctor

Definition at line 962 of file bmsparsevec.h.

◆ ~sparse_vector()

template<class Val , class BV >
bm::sparse_vector< Val, BV >::~sparse_vector ( )

Member Function Documentation

◆ at()

template<class Val, class BV>
sparse_vector< Val, BV >::value_type bm::sparse_vector< Val, BV >::at ( size_type  idx) const

access specified element with bounds checking

Parameters
idx- element index
Returns
value of the element

Definition at line 1468 of file bmsparsevec.h.

Referenced by main(), bm::sparse_vector< unsigned short, bvector_type >::operator[](), and print_svector().

◆ begin()

template<class Val , class BV >
sparse_vector< Val, BV >::const_iterator bm::sparse_vector< Val, BV >::begin ( ) const

Provide const iterator access to container content.

Definition at line 1950 of file bmsparsevec.h.

Referenced by build_vector_pairs(), compare_sv_it(), main(), and bm::sparse_vector< unsigned short, bvector_type >::operator[]().

◆ calc_stat()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::calc_stat ( struct sparse_vector< Val, BV >::statistics st) const

Calculates memory statistics.

Function fills statistics structure containing information about how this vector uses memory and estimation of max. amount of memory bvector needs to serialize itself.

Parameters
st- pointer on statistics structure to be filled in.
See also
statistics

Definition at line 1762 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::resize().

◆ clear() [1/2]

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::clear ( size_type  idx,
bool  set_null 
)

clear specified element with bounds checking and automatic resize

Parameters
idx- element index
set_null- if true the value receives NULL (unassigned) value

Definition at line 1515 of file bmsparsevec.h.

Referenced by main().

◆ clear() [2/2]

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::clear ( )
inline

resize to zero, free memory

Definition at line 615 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::operator[]().

◆ clear_all()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::clear_all ( bool  free_mem)

◆ clear_range()

template<class Val, class BV>
sparse_vector< Val, BV > & bm::sparse_vector< Val, BV >::clear_range ( size_type  left,
size_type  right,
bool  set_null = false 
)

clear range (assign bit 0 for all plains)

Parameters
left- interval start
right- interval end (closed interval)
set_null- set cleared values to unassigned (NULL)

Definition at line 1750 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::clear().

◆ compare()

template<class Val , class BV >
int bm::sparse_vector< Val, BV >::compare ( size_type  idx,
const value_type  val 
) const

Compare vector element with argument.

Parameters
idx- vactor element index
val- argument to compare with
Returns
0 - equal, < 0 - vect[i] < str, >0 otherwise

Definition at line 1929 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::resize().

◆ copy_range()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::copy_range ( const sparse_vector< Val, BV > &  sv,
size_type  left,
size_type  right,
bm::null_support  splice_null = bm::use_null 
)

copy range of values from another sparse vector

Copy [left..right] values from the source vector, clear everything outside the range.

Parameters
sv- source vector
left- index from in losed diapason of [left..right]
right- index to in losed diapason of [left..right]
splice_null- "use_null" copy range for NULL vector or do not copy it

Definition at line 1891 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::resize().

◆ decode()

template<class Val , class BV >
sparse_vector< Val, BV >::size_type bm::sparse_vector< Val, BV >::decode ( value_type arr,
size_type  idx_from,
size_type  dec_size,
bool  zero_mem = true 
) const

Bulk export list of elements to a C-style array.

For efficiency, this is left as a low level function, it does not do any bounds checking on the target array, it will override memory and crash if you are not careful with allocation and request size.

Parameters
arr- dest array
idx_from- index in the sparse vector to export from
dec_size- decoding size (array allocation should match)
zero_mem- set to false if target array is pre-initialized with 0s to avoid performance penalty
Returns
number of actually exported elements (can be less than requested)
See also
gather

Definition at line 1116 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::is_compressed(), and main().

◆ effective_size()

template<class Val, class BV>
size_type bm::sparse_vector< Val, BV >::effective_size ( ) const
inline

size of sparse vector (may be different for RSC)

Definition at line 857 of file bmsparsevec.h.

◆ effective_vector_max()

template<class Val, class BV>
size_type bm::sparse_vector< Val, BV >::effective_vector_max ( ) const
inline

Always 1 (non-matrix type)

Definition at line 862 of file bmsparsevec.h.

◆ empty()

template<class Val, class BV>
bool bm::sparse_vector< Val, BV >::empty ( ) const
inline

return true if vector is empty

Returns
true if empty

Definition at line 641 of file bmsparsevec.h.

Referenced by main(), bm::sparse_vector< Val, BV >::back_insert_iterator::operator++(), and run_benchmark().

◆ end()

template<class Val, class BV>
const_iterator bm::sparse_vector< Val, BV >::end ( ) const
inline

Provide const iterator access to the end.

Definition at line 482 of file bmsparsevec.h.

Referenced by build_vector_pairs(), and main().

◆ equal()

template<class Val, class BV>
bool bm::sparse_vector< Val, BV >::equal ( const sparse_vector< Val, BV > &  sv,
bm::null_support  null_able = bm::use_null 
) const

check if another sparse vector has the same content and size

Parameters
sv- sparse vector for comparison
null_able- flag to consider NULL vector in comparison (default) or compare only value content plains
Returns
true, if it is the same

Definition at line 1940 of file bmsparsevec.h.

Referenced by main(), bm::sparse_vector< unsigned short, bvector_type >::resize(), SDemo1(), and SDemo2().

◆ erase()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::erase ( size_type  idx)

erase specified element from container

Parameters
idx- element index

Definition at line 1612 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::operator[]().

◆ extract()

template<class Val, class BV>
sparse_vector< Val, BV >::size_type bm::sparse_vector< Val, BV >::extract ( value_type arr,
size_type  size,
size_type  offset = 0,
bool  zero_mem = true 
) const

Bulk export list of elements to a C-style array.

Use of all extract() methods is restricted. Please consider decode() for the same purpose.

Parameters
arr- dest array
size- dest size
offset- target index in the sparse vector to export from
zero_mem- set to false if target array is pre-initialized with 0s to avoid performance penalty
Returns
number of exported elements
See also
decode

Decoder functor

< target array for reverse transpose

< bit-plane mask

< SV read offset

Definition at line 1402 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::sync().

◆ extract_plains()

template<class Val , class BV >
sparse_vector< Val, BV >::size_type bm::sparse_vector< Val, BV >::extract_plains ( value_type arr,
size_type  size,
size_type  offset,
bool  zero_mem = true 
) const

extract medium window without use of masking vector

See also
decode

Definition at line 1357 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::sync().

◆ extract_range()

template<class Val , class BV >
sparse_vector< Val, BV >::size_type bm::sparse_vector< Val, BV >::extract_range ( value_type arr,
size_type  size,
size_type  offset,
bool  zero_mem = true 
) const

extract small window without use of masking vector

See also
decode

Definition at line 1277 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::sync().

◆ filter()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::filter ( const bvector_type bv_mask)

Apply value filter, defined by mask vector.

All bit-plains are ANDed against the filter mask.

Definition at line 1905 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::resize().

◆ find_rank()

template<class Val , class BV >
bool bm::sparse_vector< Val, BV >::find_rank ( size_type  rank,
size_type pos 
)
static

find position of compressed element by its rank

Definition at line 1739 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::translate_address().

◆ gather()

template<class Val , class BV >
sparse_vector< Val, BV >::size_type bm::sparse_vector< Val, BV >::gather ( value_type arr,
const size_type idx,
size_type  size,
bm::sort_order  sorted_idx 
) const

Gather elements to a C-style array.

Gather collects values from different locations, for best performance feed it with sorted list of indexes.

Faster than one-by-one random access.

For efficiency, this is left as a low level function, it does not do any bounds checking on the target array, it will override memory and crash if you are not careful with allocation and request size.

Parameters
arr- dest array
idx- index list to gather elements
size- decoding index list size (array allocation should match)
sorted_idx- sort order directive for the idx array (BM_UNSORTED, BM_SORTED, BM_UNKNOWN) Sort order affects both performance and correctness(!), use BM_UNKNOWN if not sure.
Returns
number of actually exported elements (can be less than requested)
See also
decode

Definition at line 1128 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::is_compressed().

◆ get()

template<class Val, class BV>
sparse_vector< Val, BV >::value_type bm::sparse_vector< Val, BV >::get ( size_type  idx) const

get specified element without bounds checking

Parameters
idx- element index
Returns
value of the element

Definition at line 1479 of file bmsparsevec.h.

Referenced by counting_sort_naive(), print_sorted(), raw_data_size(), and test_data().

◆ get_back_inserter()

template<class Val, class BV>
back_insert_iterator bm::sparse_vector< Val, BV >::get_back_inserter ( )
inline

Provide back insert iterator Back insert iterator implements buffered insertion, which is faster, than random access or push_back.

Definition at line 495 of file bmsparsevec.h.

Referenced by generate_DNA_vector(), generate_test_set(), main(), write_as_rsc_svector(), and write_as_svector().

◆ get_const_iterator()

template<class Val, class BV>
const_iterator bm::sparse_vector< Val, BV >::get_const_iterator ( size_type  idx) const
inline

Get const_itertor re-positioned to specific element.

Parameters
idx- position in the sparse vector

Definition at line 488 of file bmsparsevec.h.

◆ get_remap_buffer()

template<class Val, class BV>
const unsigned char* bm::sparse_vector< Val, BV >::get_remap_buffer ( ) const
inlineprotected

Definition at line 901 of file bmsparsevec.h.

◆ get_remap_matrix() [1/2]

template<class Val, class BV>
const remap_matrix_type* bm::sparse_vector< Val, BV >::get_remap_matrix ( ) const
inlineprotected

Definition at line 913 of file bmsparsevec.h.

◆ get_remap_matrix() [2/2]

template<class Val, class BV>
remap_matrix_type* bm::sparse_vector< Val, BV >::get_remap_matrix ( )
inlineprotected

Definition at line 914 of file bmsparsevec.h.

◆ import()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::import ( const value_type arr,
size_type  arr_size,
size_type  offset = 0,
bool  set_not_null = true 
)

Import list of elements from a C-style array.

Parameters
arr- source array
arr_size- source size
offset- target index in the sparse vector
set_not_null- import should register in not null vector

Definition at line 1015 of file bmsparsevec.h.

Referenced by convert_bv2sv(), and main().

◆ import_back()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::import_back ( const value_type arr,
size_type  arr_size,
bool  set_not_null = true 
)

Import list of elements from a C-style array (pushed back)

Parameters
arr- source array
arr_size- source array size
set_not_null- import should register in not null vector

Definition at line 1105 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::is_compressed().

◆ inc()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::inc ( size_type  idx)

increment specified element by one

Parameters
idx- element index

Definition at line 1695 of file bmsparsevec.h.

Referenced by counting_sort(), counting_sort_parallel(), counting_sort_subbatch(), and bm::sparse_vector< unsigned short, bvector_type >::operator[]().

◆ inc_no_null() [1/2]

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::inc_no_null ( size_type  idx)
protected

Increment element by 1 without chnaging NULL vector or size.

Definition at line 1708 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::resolve_range().

◆ inc_no_null() [2/2]

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::inc_no_null ( size_type  idx,
value_type  v 
)
protected

increment by v without chnaging NULL vector or size

Definition at line 1722 of file bmsparsevec.h.

◆ init_remap_buffer()

template<class Val, class BV>
unsigned char* bm::sparse_vector< Val, BV >::init_remap_buffer ( )
inlineprotected

Definition at line 902 of file bmsparsevec.h.

◆ insert()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::insert ( size_type  idx,
value_type  v 
)

insert specified element into container

Parameters
idx- element index
v- element value

Definition at line 1554 of file bmsparsevec.h.

Referenced by insertion_sort(), and bm::sparse_vector< unsigned short, bvector_type >::operator[]().

◆ insert_value()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::insert_value ( size_type  idx,
value_type  v 
)
protected

insert value without checking boundaries

Definition at line 1568 of file bmsparsevec.h.

◆ insert_value_no_null()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::insert_value_no_null ( size_type  idx,
value_type  v 
)
protected

insert value without checking boundaries or support of NULL

Definition at line 1577 of file bmsparsevec.h.

◆ is_compressed()

template<class Val, class BV>
static bool bm::sparse_vector< Val, BV >::is_compressed ( )
inlinestatic

trait if sparse vector is "compressed" (false)

Definition at line 512 of file bmsparsevec.h.

◆ is_remap()

template<class Val, class BV>
bool bm::sparse_vector< Val, BV >::is_remap ( ) const
inlineprotected

Definition at line 899 of file bmsparsevec.h.

◆ join()

template<class Val, class BV>
sparse_vector< Val, BV > & bm::sparse_vector< Val, BV >::join ( const sparse_vector< Val, BV > &  sv)

join all with another sparse vector using OR operation

Parameters
sv- argument vector to join with
Returns
slf reference
See also
merge

Definition at line 1814 of file bmsparsevec.h.

Referenced by main(), and bm::sparse_vector< unsigned short, bvector_type >::resize().

◆ merge()

template<class Val, class BV>
sparse_vector< Val, BV > & bm::sparse_vector< Val, BV >::merge ( sparse_vector< Val, BV > &  sv)

merge with another sparse vector using OR operation Merge is different from join(), because it borrows data from the source vector, so it gets modified.

Parameters
sv- [in, out]argument vector to join with (vector mutates)
Returns
slf reference
See also
join

Definition at line 1853 of file bmsparsevec.h.

Referenced by counting_sort_parallel(), and bm::sparse_vector< unsigned short, bvector_type >::resize().

◆ operator=() [1/2]

template<class Val, class BV>
sparse_vector<Val,BV>& bm::sparse_vector< Val, BV >::operator= ( const sparse_vector< Val, BV > &  sv)
inline

copy assignmment operator

Definition at line 370 of file bmsparsevec.h.

◆ operator=() [2/2]

template<class Val, class BV>
sparse_vector<Val,BV>& bm::sparse_vector< Val, BV >::operator= ( sparse_vector< Val, BV > &&  sv)
inline

move assignmment operator

Definition at line 383 of file bmsparsevec.h.

◆ operator[]() [1/2]

template<class Val, class BV>
reference bm::sparse_vector< Val, BV >::operator[] ( size_type  idx)
inline

Operator to get write access to an element.

Definition at line 403 of file bmsparsevec.h.

◆ operator[]() [2/2]

template<class Val, class BV>
value_type bm::sparse_vector< Val, BV >::operator[] ( size_type  idx) const
inline

get specified element without bounds checking

Parameters
idx- element index
Returns
value of the element

Definition at line 411 of file bmsparsevec.h.

◆ optimize()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::optimize ( bm::word_t temp_block = 0,
typename bvector_type::optmode  opt_mode = bvector_type::opt_compress,
typename sparse_vector< Val, BV >::statistics stat = 0 
)

run memory optimization for all vector plains

Parameters
temp_block- pre-allocated memory block to avoid unnecessary re-allocs
opt_mode- requested compression depth
stat- memory allocation statistics after optimization

Definition at line 1778 of file bmsparsevec.h.

Referenced by convert_bv2sv(), generate_big_case(), main(), bm::sparse_vector< unsigned short, bvector_type >::resize(), SDemo1(), SDemo2(), and write_as_svector().

◆ optimize_gap_size()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::optimize_gap_size ( )

Optimize sizes of GAP blocks.

This method runs an analysis to find optimal GAP levels for all bit plains of the vector.

Definition at line 1797 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::resize().

◆ push_back()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::push_back ( value_type  v)

push value back into vector

Parameters
v- element value

Definition at line 1532 of file bmsparsevec.h.

Referenced by generate_random_subset(), main(), bm::sparse_vector< unsigned short, bvector_type >::operator[](), and SDemo1().

◆ push_back_no_null()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::push_back_no_null ( value_type  v)
protected

push value back into vector without NULL semantics

Definition at line 1625 of file bmsparsevec.h.

◆ push_back_null()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::push_back_null ( size_type  count)

push back specified amount of NULL values

Parameters
count- number of NULLs to push back

Definition at line 1541 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::operator[]().

◆ remap_size()

template<class Val, class BV>
size_t bm::sparse_vector< Val, BV >::remap_size ( ) const
inlineprotected

Definition at line 900 of file bmsparsevec.h.

◆ resize()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::resize ( size_type  sz)
inline

◆ resize_internal()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::resize_internal ( size_type  sz)
inlineprotected

Definition at line 896 of file bmsparsevec.h.

◆ resolve_range()

template<class Val, class BV>
bool bm::sparse_vector< Val, BV >::resolve_range ( size_type  from,
size_type  to,
size_type idx_from,
size_type idx_to 
) const
inlineprotected

Definition at line 916 of file bmsparsevec.h.

◆ set()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::set ( size_type  idx,
value_type  v 
)

set specified element with bounds checking and automatic resize

Parameters
idx- element index
v- element value

Definition at line 1503 of file bmsparsevec.h.

Referenced by build_histogram(), convert_bv2sv(), counting_sort_naive(), fill_test_data(), load_snp_report(), main(), SDemo2(), test_mismatch_search(), test_sv_cmp(), and test_sv_cmp_it().

◆ set_allocator_pool()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::set_allocator_pool ( allocator_pool_type pool_ptr)

Set allocator pool for local (non-threaded) memory cyclic(lots of alloc-free ops) opertations.

Definition at line 1959 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::effective_vector_max().

◆ set_null()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::set_null ( size_type  idx)

set specified element to unassigned value (NULL)

Parameters
idx- element index

Definition at line 1007 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::get_back_inserter(), main(), and bm::sparse_vector< unsigned short, bvector_type >::operator[]().

◆ set_remap()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::set_remap ( )
inlineprotected

Definition at line 903 of file bmsparsevec.h.

◆ set_value()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::set_value ( size_type  idx,
value_type  v 
)
protected

set value without checking boundaries

Definition at line 1634 of file bmsparsevec.h.

◆ set_value_no_null()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::set_value_no_null ( size_type  idx,
value_type  v 
)
protected

set value without checking boundaries or support of NULL

Definition at line 1645 of file bmsparsevec.h.

◆ size()

template<class Val, class BV>
size_type bm::sparse_vector< Val, BV >::size ( ) const
inline

◆ size_internal()

template<class Val, class BV>
size_type bm::sparse_vector< Val, BV >::size_internal ( ) const
inlineprotected

Definition at line 897 of file bmsparsevec.h.

◆ swap()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::swap ( sparse_vector< Val, BV > &  sv)

◆ sync()

template<class Val, class BV>
void bm::sparse_vector< Val, BV >::sync ( bool  )
inline

syncronize internal structures

Definition at line 784 of file bmsparsevec.h.

◆ sync_size()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::sync_size ( )

recalculate size to exclude tail NULL elements After this call size() will return the true size of the vector

Definition at line 1093 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::resize().

◆ throw_bad_alloc()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::throw_bad_alloc ( )
static

throw bad alloc

Definition at line 999 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::translate_address().

◆ throw_range_error()

template<class Val , class BV >
void bm::sparse_vector< Val, BV >::throw_range_error ( const char *  err_msg)
static

throw range error

Definition at line 987 of file bmsparsevec.h.

Referenced by bm::sparse_vector< unsigned short, bvector_type >::translate_address().

◆ translate_address()

template<class Val, class BV>
static size_type bm::sparse_vector< Val, BV >::translate_address ( size_type  i)
inlinestatic

address translation for this type of container

Definition at line 831 of file bmsparsevec.h.

Friends And Related Function Documentation

◆ rsc_sparse_vector

template<class Val, class BV>
template<class V , class SV >
friend class rsc_sparse_vector
friend

Definition at line 929 of file bmsparsevec.h.

◆ sparse_vector_deserializer

template<class Val, class BV>
template<class SVect >
friend class sparse_vector_deserializer
friend

Definition at line 932 of file bmsparsevec.h.

◆ sparse_vector_scanner

template<class Val, class BV>
template<class SVect >
friend class sparse_vector_scanner
friend

Definition at line 930 of file bmsparsevec.h.

◆ sparse_vector_serializer

template<class Val, class BV>
template<class SVect >
friend class sparse_vector_serializer
friend

Definition at line 931 of file bmsparsevec.h.

Field Documentation

◆ back_insert_iterator

template<class Val, class BV>
friend bm::sparse_vector< Val, BV >::back_insert_iterator

◆ const_iterator

template<class Val, class BV>
friend bm::sparse_vector< Val, BV >::const_iterator

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