BitMagic-C++
Public Types | Public Member Functions | Protected Types | Protected Member Functions

algorithms for sparse_vector scan/seach More...

#include <bmsparsevec_algo.h>

Public Types

typedef SV::bvector_type bvector_type
 
typedef const bvector_typebvector_type_const_ptr
 
typedef bvector_typebvector_type_ptr
 
typedef SV::value_type value_type
 
typedef SV::size_type size_type
 
typedef bvector_type::allocator_type allocator_type
 
typedef allocator_type::allocator_pool_type allocator_pool_type
 

Public Member Functions

 sparse_vector_scanner ()
 
void bind (const SV &sv, bool sorted)
 bind sparse vector for all searches More...
 
void reset_binding ()
 reset sparse vector binding More...
 
void find_eq (const SV &sv, typename SV::value_type value, typename SV::bvector_type &bv_out)
 find all sparse vector elements EQ to search value More...
 
bool find_eq (const SV &sv, typename SV::value_type value, typename SV::size_type &pos)
 find first sparse vector element More...
 
bool find_eq_str (const SV &sv, const typename SV::value_type *str, typename SV::size_type &pos)
 find first sparse vector element (string) More...
 
bool find_eq_str (const typename SV::value_type *str, typename SV::size_type &pos)
 binary find first sparse vector element (string) Sparse vector must be attached (bind()) More...
 
bool bfind_eq_str (const SV &sv, const typename SV::value_type *str, typename SV::size_type &pos)
 binary find first sparse vector element (string) Sparse vector must be sorted. More...
 
bool lower_bound_str (const SV &sv, const typename SV::value_type *str, typename SV::size_type &pos)
 lower bound search for an array position More...
 
bool bfind_eq_str (const typename SV::value_type *str, typename SV::size_type &pos)
 binary find first sparse vector element (string) Sparse vector must be sorted and attached More...
 
void find_zero (const SV &sv, typename SV::bvector_type &bv_out)
 find all sparse vector elements EQ to 0 More...
 
void find_nonzero (const SV &sv, typename SV::bvector_type &bv_out)
 Find non-zero elements Output vector is computed as a logical OR (join) of all plains. More...
 
void invert (const SV &sv, typename SV::bvector_type &bv_out)
 invert search result ("EQ" to "not EQ") More...
 
template<typename It >
void find_eq (const SV &sv, It start, It end, typename SV::bvector_type &bv_out)
 find all values A IN (C, D, E, F) More...
 
void find_eq_with_nulls_horizontal (const SV &sv, typename SV::value_type value, typename SV::bvector_type &bv_out)
 For testing purposes only. More...
 
void correct_nulls (const SV &sv, typename SV::bvector_type &bv_out)
 Exclude possible NULL values from the result vector. More...
 

Protected Types

enum  vector_capacity { max_columns = SV::max_vector_size }
 
enum  search_algo_params { linear_cutoff1 = 16, linear_cutoff2 = 128 }
 
typedef bm::heap_matrix< value_type, bm::set_total_blocks, max_columns, allocator_typeheap_matrix_type0
 
typedef bm::heap_matrix< value_type, bm::set_total_blocks *3, max_columns, allocator_typeheap_matrix_type3
 
typedef bm::heap_matrix< typename SV::value_type, linear_cutoff2, SV::sv_octet_plains, allocator_typematrix_search_buf_type
 

Protected Member Functions

void set_search_range (size_type from, size_type to)
 set search boundaries (hint for the aggregator) More...
 
void reset_search_range ()
 reset (disable) search range More...
 
bool find_eq_with_nulls (const SV &sv, typename SV::value_type value, typename SV::bvector_type &bv_out, typename SV::size_type search_limit=0)
 find value (may include NULL indexes) More...
 
bool find_first_eq (const SV &sv, typename SV::value_type value, bm::id_t &idx)
 find first value (may include NULL indexes) More...
 
bool find_first_eq (const SV &sv, const typename SV::value_type *str, bm::id_t &idx, bool remaped)
 find first string value (may include NULL indexes) More...
 
bool prepare_and_sub_aggregator (const SV &sv, typename SV::value_type value)
 Prepare aggregator for AND-SUB (EQ) search. More...
 
bool prepare_and_sub_aggregator (const SV &sv, const typename SV::value_type *str, unsigned octet_start)
 Prepare aggregator for AND-SUB (EQ) search (string) More...
 
void decompress (const SV &sv, typename SV::bvector_type &bv_out)
 Rank-Select decompression for RSC vectors. More...
 
int compare_str (const SV &sv, size_type idx, const value_type *str)
 
 sparse_vector_scanner (const sparse_vector_scanner &)=delete
 
void operator= (const sparse_vector_scanner &)=delete
 

Detailed Description

template<typename SV>
class bm::sparse_vector_scanner< SV >

algorithms for sparse_vector scan/seach

Scanner uses properties of bit-vector plains to answer questions like "find all sparse vector elements equivalent to XYZ".

Class uses fast algorithms based on properties of bit-plains. This is NOT a brute force, direct scan.

Examples:
strsvsample02.cpp, svsample06.cpp, xsample03.cpp, and xsample05.cpp.

Definition at line 154 of file bmsparsevec_algo.h.

Member Typedef Documentation

◆ allocator_pool_type

template<typename SV>
typedef allocator_type::allocator_pool_type bm::sparse_vector_scanner< SV >::allocator_pool_type

Definition at line 164 of file bmsparsevec_algo.h.

◆ allocator_type

Definition at line 163 of file bmsparsevec_algo.h.

◆ bvector_type

template<typename SV>
typedef SV::bvector_type bm::sparse_vector_scanner< SV >::bvector_type

Definition at line 157 of file bmsparsevec_algo.h.

◆ bvector_type_const_ptr

template<typename SV>
typedef const bvector_type* bm::sparse_vector_scanner< SV >::bvector_type_const_ptr

Definition at line 158 of file bmsparsevec_algo.h.

◆ bvector_type_ptr

template<typename SV>
typedef bvector_type* bm::sparse_vector_scanner< SV >::bvector_type_ptr

Definition at line 159 of file bmsparsevec_algo.h.

◆ heap_matrix_type0

template<typename SV>
typedef bm::heap_matrix<value_type, bm::set_total_blocks, max_columns, allocator_type> bm::sparse_vector_scanner< SV >::heap_matrix_type0
protected

Definition at line 390 of file bmsparsevec_algo.h.

◆ heap_matrix_type3

template<typename SV>
typedef bm::heap_matrix<value_type, bm::set_total_blocks*3, max_columns, allocator_type> bm::sparse_vector_scanner< SV >::heap_matrix_type3
protected

Definition at line 394 of file bmsparsevec_algo.h.

◆ matrix_search_buf_type

template<typename SV>
typedef bm::heap_matrix<typename SV::value_type, linear_cutoff2, SV::sv_octet_plains, allocator_type> bm::sparse_vector_scanner< SV >::matrix_search_buf_type
protected

Definition at line 399 of file bmsparsevec_algo.h.

◆ size_type

template<typename SV>
typedef SV::size_type bm::sparse_vector_scanner< SV >::size_type

Definition at line 161 of file bmsparsevec_algo.h.

◆ value_type

template<typename SV>
typedef SV::value_type bm::sparse_vector_scanner< SV >::value_type

Definition at line 160 of file bmsparsevec_algo.h.

Member Enumeration Documentation

◆ search_algo_params

template<typename SV>
enum bm::sparse_vector_scanner::search_algo_params
protected
Enumerator
linear_cutoff1 
linear_cutoff2 

Definition at line 381 of file bmsparsevec_algo.h.

◆ vector_capacity

template<typename SV>
enum bm::sparse_vector_scanner::vector_capacity
protected
Enumerator
max_columns 

Definition at line 376 of file bmsparsevec_algo.h.

Constructor & Destructor Documentation

◆ sparse_vector_scanner() [1/2]

template<typename SV >
bm::sparse_vector_scanner< SV >::sparse_vector_scanner ( )

Definition at line 769 of file bmsparsevec_algo.h.

References bm::id_max.

Referenced by bm::sparse_vector_scanner< SV >::find_eq().

◆ sparse_vector_scanner() [2/2]

template<typename SV>
bm::sparse_vector_scanner< SV >::sparse_vector_scanner ( const sparse_vector_scanner< SV > &  )
protecteddelete

Member Function Documentation

◆ bfind_eq_str() [1/2]

template<typename SV >
bool bm::sparse_vector_scanner< SV >::bfind_eq_str ( const SV &  sv,
const typename SV::value_type *  str,
typename SV::size_type &  pos 
)

binary find first sparse vector element (string) Sparse vector must be sorted.

Definition at line 1214 of file bmsparsevec_algo.h.

References BM_ASSERT, bm::gap_max_bits, bm::set_block_shift, and bm::sub_block3_size.

Referenced by run_benchmark().

◆ bfind_eq_str() [2/2]

template<typename SV >
bool bm::sparse_vector_scanner< SV >::bfind_eq_str ( const typename SV::value_type *  str,
typename SV::size_type &  pos 
)

binary find first sparse vector element (string) Sparse vector must be sorted and attached

See also
bind

Definition at line 1364 of file bmsparsevec_algo.h.

References BM_ASSERT.

◆ bind()

template<typename SV >
void bm::sparse_vector_scanner< SV >::bind ( const SV &  sv,
bool  sorted 
)

bind sparse vector for all searches

Parameters
sv- input sparse vector to bind for searches
sorted- source index is sorted, build index for binary search

Definition at line 781 of file bmsparsevec_algo.h.

References bm::gap_max_bits, bm::set_block_shift, and bm::sub_block3_size.

Referenced by run_benchmark().

◆ compare_str()

template<typename SV >
int bm::sparse_vector_scanner< SV >::compare_str ( const SV &  sv,
size_type  idx,
const value_type str 
)
protected

◆ correct_nulls()

template<typename SV >
void bm::sparse_vector_scanner< SV >::correct_nulls ( const SV &  sv,
typename SV::bvector_type bv_out 
)

Exclude possible NULL values from the result vector.

Parameters
sv- input sparse vector
bv_out- output bit-bector of non-zero elements

Definition at line 872 of file bmsparsevec_algo.h.

Referenced by bm::sparse_vector_scanner< SV >::find_eq().

◆ decompress()

template<typename SV >
void bm::sparse_vector_scanner< SV >::decompress ( const SV &  sv,
typename SV::bvector_type bv_out 
)
protected

Rank-Select decompression for RSC vectors.

Definition at line 1615 of file bmsparsevec_algo.h.

References BM_ASSERT.

Referenced by bm::sparse_vector_scanner< SV >::find_eq().

◆ find_eq() [1/3]

template<typename SV >
void bm::sparse_vector_scanner< SV >::find_eq ( const SV &  sv,
typename SV::value_type  value,
typename SV::bvector_type bv_out 
)

find all sparse vector elements EQ to search value

Find all sparse vector elements equivalent to specified value

Parameters
sv- input sparse vector
value- value to search for
bv_out- output bit-vector (search result masks 1 elements)

Definition at line 1549 of file bmsparsevec_algo.h.

Referenced by main(), and run_benchmark().

◆ find_eq() [2/3]

template<typename SV >
bool bm::sparse_vector_scanner< SV >::find_eq ( const SV &  sv,
typename SV::value_type  value,
typename SV::size_type &  pos 
)

find first sparse vector element

Find all sparse vector elements equivalent to specified value. Works well if sperse vector represents unordered set

Parameters
sv- input sparse vector
value- value to search for
pos- output found sparse vector element index
Returns
true if found

Definition at line 1573 of file bmsparsevec_algo.h.

◆ find_eq() [3/3]

template<typename SV>
template<typename It >
void bm::sparse_vector_scanner< SV >::find_eq ( const SV &  sv,
It  start,
It  end,
typename SV::bvector_type bv_out 
)
inline

◆ find_eq_str() [1/2]

template<typename SV >
bool bm::sparse_vector_scanner< SV >::find_eq_str ( const SV &  sv,
const typename SV::value_type *  str,
typename SV::size_type &  pos 
)

find first sparse vector element (string)

Definition at line 1168 of file bmsparsevec_algo.h.

Referenced by run_benchmark().

◆ find_eq_str() [2/2]

template<typename SV >
bool bm::sparse_vector_scanner< SV >::find_eq_str ( const typename SV::value_type *  str,
typename SV::size_type &  pos 
)

binary find first sparse vector element (string) Sparse vector must be attached (bind())

See also
bind

Definition at line 1158 of file bmsparsevec_algo.h.

References BM_ASSERT.

◆ find_eq_with_nulls()

template<typename SV >
bool bm::sparse_vector_scanner< SV >::find_eq_with_nulls ( const SV &  sv,
typename SV::value_type  value,
typename SV::bvector_type bv_out,
typename SV::size_type  search_limit = 0 
)
protected

find value (may include NULL indexes)

Definition at line 883 of file bmsparsevec_algo.h.

Referenced by bm::sparse_vector_scanner< SV >::find_eq().

◆ find_eq_with_nulls_horizontal()

template<typename SV >
void bm::sparse_vector_scanner< SV >::find_eq_with_nulls_horizontal ( const SV &  sv,
typename SV::value_type  value,
typename SV::bvector_type bv_out 
)

For testing purposes only.

Definition at line 1105 of file bmsparsevec_algo.h.

References bm::bitscan(), and BM_ASSERT.

Referenced by bm::sparse_vector_scanner< SV >::find_eq().

◆ find_first_eq() [1/2]

template<typename SV >
bool bm::sparse_vector_scanner< SV >::find_first_eq ( const SV &  sv,
typename SV::value_type  value,
bm::id_t idx 
)
protected

find first value (may include NULL indexes)

Definition at line 914 of file bmsparsevec_algo.h.

References BM_ASSERT.

Referenced by bm::sparse_vector_scanner< SV >::find_eq().

◆ find_first_eq() [2/2]

template<typename SV >
bool bm::sparse_vector_scanner< SV >::find_first_eq ( const SV &  sv,
const typename SV::value_type *  str,
bm::id_t idx,
bool  remaped 
)
protected

find first string value (may include NULL indexes)

Definition at line 938 of file bmsparsevec_algo.h.

References BM_ASSERT.

◆ find_nonzero()

template<typename SV >
void bm::sparse_vector_scanner< SV >::find_nonzero ( const SV &  sv,
typename SV::bvector_type bv_out 
)

Find non-zero elements Output vector is computed as a logical OR (join) of all plains.

Parameters
sv- input sparse vector
bv_out- output bit-bector of non-zero elements

Definition at line 1602 of file bmsparsevec_algo.h.

◆ find_zero()

template<typename SV >
void bm::sparse_vector_scanner< SV >::find_zero ( const SV &  sv,
typename SV::bvector_type bv_out 
)

find all sparse vector elements EQ to 0

Parameters
sv- input sparse vector
bv_out- output bit-vector (search result masks 1 elements)

Definition at line 828 of file bmsparsevec_algo.h.

References bm::id_max.

Referenced by bm::set2set_11_transform< SV >::attach_sv().

◆ invert()

template<typename SV >
void bm::sparse_vector_scanner< SV >::invert ( const SV &  sv,
typename SV::bvector_type bv_out 
)

invert search result ("EQ" to "not EQ")

Parameters
sv- input sparse vector
bv_out- output bit-bector of non-zero elements

Definition at line 854 of file bmsparsevec_algo.h.

References bm::id_max.

Referenced by main().

◆ lower_bound_str()

template<typename SV >
bool bm::sparse_vector_scanner< SV >::lower_bound_str ( const SV &  sv,
const typename SV::value_type *  str,
typename SV::size_type &  pos 
)

lower bound search for an array position

Method assumes the sparse array is sorted

Parameters
sv- input sparse vector
value- value to search for
pos- output sparse vector element index
Returns
true if value found

Definition at line 1374 of file bmsparsevec_algo.h.

References BM_ASSERT.

Referenced by insertion_sort().

◆ operator=()

template<typename SV>
void bm::sparse_vector_scanner< SV >::operator= ( const sparse_vector_scanner< SV > &  )
protecteddelete

◆ prepare_and_sub_aggregator() [1/2]

template<typename SV >
bool bm::sparse_vector_scanner< SV >::prepare_and_sub_aggregator ( const SV &  sv,
typename SV::value_type  value 
)
protected

Prepare aggregator for AND-SUB (EQ) search.

Definition at line 1070 of file bmsparsevec_algo.h.

References bm::bitscan(), and BM_ASSERT.

Referenced by bm::sparse_vector_scanner< SV >::find_eq().

◆ prepare_and_sub_aggregator() [2/2]

template<typename SV >
bool bm::sparse_vector_scanner< SV >::prepare_and_sub_aggregator ( const SV &  sv,
const typename SV::value_type *  str,
unsigned  octet_start 
)
protected

Prepare aggregator for AND-SUB (EQ) search (string)

Definition at line 986 of file bmsparsevec_algo.h.

References bm::bitscan(), BM_ASSERT, and bm::word_bitcount().

◆ reset_binding()

template<typename SV >
void bm::sparse_vector_scanner< SV >::reset_binding ( )

reset sparse vector binding

Definition at line 819 of file bmsparsevec_algo.h.

◆ reset_search_range()

template<typename SV >
void bm::sparse_vector_scanner< SV >::reset_search_range ( )
protected

reset (disable) search range

Definition at line 1642 of file bmsparsevec_algo.h.

References bm::id_max.

Referenced by bm::sparse_vector_scanner< SV >::find_eq().

◆ set_search_range()

template<typename SV >
void bm::sparse_vector_scanner< SV >::set_search_range ( size_type  from,
size_type  to 
)
protected

set search boundaries (hint for the aggregator)

Definition at line 1631 of file bmsparsevec_algo.h.

References BM_ASSERT.

Referenced by bm::sparse_vector_scanner< SV >::find_eq().


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