BitMagic-C++
Data Structures | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions
bm::aggregator< BV > Class Template Reference

Algorithms for fast aggregation of a group of bit-vectors. More...

#include <bmaggregator.h>

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

Public Types

enum  max_size { max_aggregator_cap = 256 }
 Maximum aggregation capacity in one pass. More...
 
typedef BV bvector_type
 
typedef const bvector_typebvector_type_const_ptr
 
typedef bm::id64_t digest_type
 

Public Member Functions

 aggregator ()
 
 ~aggregator ()
 
Methods to setup argument groups and run operations on groups
unsigned add (const bvector_type *bv, unsigned agr_group=0)
 Attach source bit-vector to a argument group (0 or 1). More...
 
void reset ()
 Reset aggregate groups, forget all attached vectors. More...
 
void combine_or (bvector_type &bv_target)
 Aggregate added group of vectors using logical OR Operation does NOT performm an explicit reset of arg group(s) More...
 
void combine_and (bvector_type &bv_target)
 Aggregate added group of vectors using logical AND Operation does NOT performm an explicit reset of arg group(s) More...
 
bool combine_and_sub (bvector_type &bv_target)
 Aggregate added group of vectors using fused logical AND-SUB Operation does NOT performm an explicit reset of arg group(s) More...
 
bool combine_and_sub (bvector_type &bv_target, bool any)
 Aggregate added group of vectors using fused logical AND-SUB Operation does NOT performm an explicit reset of arg group(s) Operation can terminate early if anything was found. More...
 
bool find_first_and_sub (bm::id_t &idx)
 
Logical operations (C-style interface)
void combine_or (bvector_type &bv_target, const bvector_type_const_ptr *bv_src, unsigned src_size)
 Aggregate group of vectors using logical OR. More...
 
void combine_and (bvector_type &bv_target, const bvector_type_const_ptr *bv_src, unsigned src_size)
 Aggregate group of vectors using logical AND. More...
 
bool combine_and_sub (bvector_type &bv_target, const bvector_type_const_ptr *bv_src_and, unsigned src_and_size, const bvector_type_const_ptr *bv_src_sub, unsigned src_sub_size, bool any)
 Fusion aggregate group of vectors using logical AND MINUS another set. More...
 
bool find_first_and_sub (bm::id_t &idx, const bvector_type_const_ptr *bv_src_and, unsigned src_and_size, const bvector_type_const_ptr *bv_src_sub, unsigned src_sub_size)
 
Horizontal Logical operations used for tests (C-style interface)
void combine_or_horizontal (bvector_type &bv_target, const bvector_type_const_ptr *bv_src, unsigned src_size)
 Horizontal OR aggregation (potentially slower) method. More...
 
void combine_and_horizontal (bvector_type &bv_target, const bvector_type_const_ptr *bv_src, unsigned src_size)
 Horizontal AND aggregation (potentially slower) method. More...
 
void combine_and_sub_horizontal (bvector_type &bv_target, const bvector_type_const_ptr *bv_src_and, unsigned src_and_size, const bvector_type_const_ptr *bv_src_sub, unsigned src_sub_size)
 Horizontal AND-SUB aggregation (potentially slower) method. More...
 

Protected Types

typedef bvector_type::blocks_manager_type blocks_manager_type
 

Protected Member Functions

void combine_or (unsigned i, unsigned j, bvector_type &bv_target, const bvector_type_const_ptr *bv_src, unsigned src_size)
 
void combine_and (unsigned i, unsigned j, bvector_type &bv_target, const bvector_type_const_ptr *bv_src, unsigned src_size)
 
digest_type combine_and_sub (unsigned i, unsigned j, const bvector_type_const_ptr *bv_src_and, unsigned src_and_size, const bvector_type_const_ptr *bv_src_sub, unsigned src_sub_size)
 
bm::word_tsort_input_blocks_or (const bvector_type_const_ptr *bv_src, unsigned src_size, unsigned i, unsigned j, unsigned *arg_blk_count, unsigned *arg_blk_gap_count)
 
bm::word_tsort_input_blocks_and (const bvector_type_const_ptr *bv_src, unsigned src_size, unsigned i, unsigned j, unsigned *arg_blk_count, unsigned *arg_blk_gap_count)
 
bool process_bit_blocks_or (blocks_manager_type &bman_target, unsigned i, unsigned j, unsigned block_count)
 
bool process_gap_blocks_or (blocks_manager_type &bman_target, unsigned i, unsigned j, unsigned block_count)
 
digest_type process_bit_blocks_and (unsigned block_count, digest_type digest)
 
digest_type process_gap_blocks_and (unsigned block_count, digest_type digest)
 
digest_type process_bit_blocks_sub (unsigned block_count, digest_type digest)
 
digest_type process_gap_blocks_sub (unsigned block_count, digest_type digest)
 

Static Protected Member Functions

static unsigned resize_target (bvector_type &bv_target, const bvector_type_const_ptr *bv_src, unsigned src_size, bool init_clear=true)
 
static unsigned find_effective_sub_block_size (unsigned i, const bvector_type_const_ptr *bv_src, unsigned src_size)
 

Detailed Description

template<typename BV>
class bm::aggregator< BV >

Algorithms for fast aggregation of a group of bit-vectors.

Current implementation can aggregate up to max_aggregator_cap vectors (TODO: remove this limitation)

Algorithms of this class use cache locality optimizations and efficient on cases, wehen we need to apply the same logical operation (aggregate) more than 2x vectors.

TARGET = BV1 or BV2 or BV3 or BV4 ...

Examples:
sample16.cpp.

Definition at line 51 of file bmaggregator.h.

Member Typedef Documentation

◆ blocks_manager_type

template<typename BV>
typedef bvector_type::blocks_manager_type bm::aggregator< BV >::blocks_manager_type
protected

Definition at line 228 of file bmaggregator.h.

◆ bvector_type

template<typename BV>
typedef BV bm::aggregator< BV >::bvector_type

Definition at line 54 of file bmaggregator.h.

◆ bvector_type_const_ptr

template<typename BV>
typedef const bvector_type* bm::aggregator< BV >::bvector_type_const_ptr

Definition at line 55 of file bmaggregator.h.

◆ digest_type

template<typename BV>
typedef bm::id64_t bm::aggregator< BV >::digest_type

Definition at line 56 of file bmaggregator.h.

Member Enumeration Documentation

◆ max_size

template<typename BV>
enum bm::aggregator::max_size

Maximum aggregation capacity in one pass.

Enumerator
max_aggregator_cap 

Definition at line 59 of file bmaggregator.h.

Constructor & Destructor Documentation

◆ aggregator()

template<typename BV >
bm::aggregator< BV >::aggregator ( )

Definition at line 313 of file bmaggregator.h.

◆ ~aggregator()

template<typename BV >
bm::aggregator< BV >::~aggregator ( )

Definition at line 321 of file bmaggregator.h.

Member Function Documentation

◆ add()

template<typename BV >
unsigned bm::aggregator< BV >::add ( const bvector_type bv,
unsigned  agr_group = 0 
)

Attach source bit-vector to a argument group (0 or 1).

Arg group 1 used for fused operations like (AND-SUB)

Parameters
bv- input bit-vector pointer to attach
agr_group- input argument group (0 - default, 1 - fused op)
Returns
current arg group size (0 if vector was not added (empty))
See also
reset

Definition at line 330 of file bmaggregator.h.

Referenced by main().

◆ combine_and() [1/3]

template<typename BV >
void bm::aggregator< BV >::combine_and ( bvector_type bv_target)

Aggregate added group of vectors using logical AND Operation does NOT performm an explicit reset of arg group(s)

Parameters
bv_target- target vector (input is arg group 0)
See also
add, reset

Definition at line 370 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::combine_and(), main(), and bm::aggregator< bvector_type >::reset().

◆ combine_and() [2/3]

template<typename BV >
void bm::aggregator< BV >::combine_and ( bvector_type bv_target,
const bvector_type_const_ptr bv_src,
unsigned  src_size 
)

Aggregate group of vectors using logical AND.

Parameters
bv_target- target vector
bv_src- array of pointers on bit-vector aggregate arguments
src_size- size of bv_src (how many vectors to aggregate)

Definition at line 434 of file bmaggregator.h.

◆ combine_and() [3/3]

template<typename BV >
void bm::aggregator< BV >::combine_and ( unsigned  i,
unsigned  j,
bvector_type bv_target,
const bvector_type_const_ptr bv_src,
unsigned  src_size 
)
protected

Definition at line 651 of file bmaggregator.h.

◆ combine_and_horizontal()

template<typename BV >
void bm::aggregator< BV >::combine_and_horizontal ( bvector_type bv_target,
const bvector_type_const_ptr bv_src,
unsigned  src_size 
)

Horizontal AND aggregation (potentially slower) method.

Parameters
bv_target- target vector
bv_src- array of pointers on bit-vector aggregate arguments
src_size- size of bv_src (how many vectors to aggregate)

Definition at line 1201 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::combine_and_sub_horizontal(), and bm::aggregator< bvector_type >::reset().

◆ combine_and_sub() [1/4]

template<typename BV >
bool bm::aggregator< BV >::combine_and_sub ( bvector_type bv_target)

Aggregate added group of vectors using fused logical AND-SUB Operation does NOT performm an explicit reset of arg group(s)

Parameters
bv_target- target vector (input is arg group 0(AND), 1(SUB) )
Returns
true if anything was found
See also
add, reset

Definition at line 378 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::combine_and_sub(), bm::aggregator< bvector_type >::find_first_and_sub(), main(), and bm::aggregator< bvector_type >::reset().

◆ combine_and_sub() [2/4]

template<typename BV >
bool bm::aggregator< BV >::combine_and_sub ( bvector_type bv_target,
bool  any 
)

Aggregate added group of vectors using fused logical AND-SUB Operation does NOT performm an explicit reset of arg group(s) Operation can terminate early if anything was found.

Parameters
bv_target- target vector (input is arg group 0(AND), 1(SUB) )
any- if true, search result will terminate of first found result
Returns
true if anything was found
See also
add, reset

Definition at line 388 of file bmaggregator.h.

◆ combine_and_sub() [3/4]

template<typename BV >
bool bm::aggregator< BV >::combine_and_sub ( bvector_type bv_target,
const bvector_type_const_ptr bv_src_and,
unsigned  src_and_size,
const bvector_type_const_ptr bv_src_sub,
unsigned  src_sub_size,
bool  any 
)

Fusion aggregate group of vectors using logical AND MINUS another set.

Parameters
bv_target- target vector
bv_src_and- array of pointers on bit-vectors for AND
src_and_size- size of AND group
bv_src_sub- array of pointers on bit-vectors for SUBstract
src_sub_size- size of SUB group
any- flag if caller needs any results asap (incomplete results)
Returns
true when found

Definition at line 462 of file bmaggregator.h.

◆ combine_and_sub() [4/4]

template<typename BV >
aggregator< BV >::digest_type bm::aggregator< BV >::combine_and_sub ( unsigned  i,
unsigned  j,
const bvector_type_const_ptr bv_src_and,
unsigned  src_and_size,
const bvector_type_const_ptr bv_src_sub,
unsigned  src_sub_size 
)
protected

Definition at line 705 of file bmaggregator.h.

◆ combine_and_sub_horizontal()

template<typename BV >
void bm::aggregator< BV >::combine_and_sub_horizontal ( bvector_type bv_target,
const bvector_type_const_ptr bv_src_and,
unsigned  src_and_size,
const bvector_type_const_ptr bv_src_sub,
unsigned  src_sub_size 
)

Horizontal AND-SUB aggregation (potentially slower) method.

Parameters
bv_target- target vector
bv_src_and- array of pointers on bit-vector to AND aggregate
src_and_size- size of bv_src_and
bv_src_sub- array of pointers on bit-vector to SUB aggregate
src_sub_size- size of bv_src_sub

Definition at line 1225 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::reset().

◆ combine_or() [1/3]

template<typename BV >
void bm::aggregator< BV >::combine_or ( bvector_type bv_target)

Aggregate added group of vectors using logical OR Operation does NOT performm an explicit reset of arg group(s)

Parameters
bv_target- target vector (input is arg group 0)
See also
add, reset

Definition at line 362 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::combine_or(), main(), and bm::aggregator< bvector_type >::reset().

◆ combine_or() [2/3]

template<typename BV >
void bm::aggregator< BV >::combine_or ( bvector_type bv_target,
const bvector_type_const_ptr bv_src,
unsigned  src_size 
)

Aggregate group of vectors using logical OR.

Parameters
bv_target- target vector
bv_src- array of pointers on bit-vector aggregate arguments
src_size- size of bv_src (how many vectors to aggregate)

Definition at line 408 of file bmaggregator.h.

◆ combine_or() [3/3]

template<typename BV >
void bm::aggregator< BV >::combine_or ( unsigned  i,
unsigned  j,
bvector_type bv_target,
const bvector_type_const_ptr bv_src,
unsigned  src_size 
)
protected

Definition at line 603 of file bmaggregator.h.

◆ combine_or_horizontal()

template<typename BV >
void bm::aggregator< BV >::combine_or_horizontal ( bvector_type bv_target,
const bvector_type_const_ptr bv_src,
unsigned  src_size 
)

Horizontal OR aggregation (potentially slower) method.

Parameters
bv_target- target vector
bv_src- array of pointers on bit-vector aggregate arguments
src_size- size of bv_src (how many vectors to aggregate)

Definition at line 1177 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::reset().

◆ find_effective_sub_block_size()

template<typename BV >
unsigned bm::aggregator< BV >::find_effective_sub_block_size ( unsigned  i,
const bvector_type_const_ptr bv_src,
unsigned  src_size 
)
staticprotected

◆ find_first_and_sub() [1/2]

template<typename BV >
bool bm::aggregator< BV >::find_first_and_sub ( bm::id_t idx)

◆ find_first_and_sub() [2/2]

template<typename BV >
bool bm::aggregator< BV >::find_first_and_sub ( bm::id_t idx,
const bvector_type_const_ptr bv_src_and,
unsigned  src_and_size,
const bvector_type_const_ptr bv_src_sub,
unsigned  src_sub_size 
)

Definition at line 519 of file bmaggregator.h.

◆ process_bit_blocks_and()

template<typename BV >
aggregator< BV >::digest_type bm::aggregator< BV >::process_bit_blocks_and ( unsigned  block_count,
digest_type  digest 
)
protected

◆ process_bit_blocks_or()

template<typename BV >
bool bm::aggregator< BV >::process_bit_blocks_or ( blocks_manager_type bman_target,
unsigned  i,
unsigned  j,
unsigned  block_count 
)
protected

Definition at line 924 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::combine_or().

◆ process_bit_blocks_sub()

template<typename BV >
aggregator< BV >::digest_type bm::aggregator< BV >::process_bit_blocks_sub ( unsigned  block_count,
digest_type  digest 
)
protected

Definition at line 1035 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::combine_and_sub().

◆ process_gap_blocks_and()

template<typename BV >
aggregator< BV >::digest_type bm::aggregator< BV >::process_gap_blocks_and ( unsigned  block_count,
digest_type  digest 
)
protected

◆ process_gap_blocks_or()

template<typename BV >
bool bm::aggregator< BV >::process_gap_blocks_or ( blocks_manager_type bman_target,
unsigned  i,
unsigned  j,
unsigned  block_count 
)
protected

Definition at line 778 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::combine_or().

◆ process_gap_blocks_sub()

template<typename BV >
aggregator< BV >::digest_type bm::aggregator< BV >::process_gap_blocks_sub ( unsigned  block_count,
digest_type  digest 
)
protected

Definition at line 898 of file bmaggregator.h.

Referenced by bm::aggregator< bvector_type >::combine_and_sub().

◆ reset()

template<typename BV>
void bm::aggregator< BV >::reset ( )
inline

Reset aggregate groups, forget all attached vectors.

Definition at line 88 of file bmaggregator.h.

Referenced by main().

◆ resize_target()

template<typename BV >
unsigned bm::aggregator< BV >::resize_target ( bvector_type bv_target,
const bvector_type_const_ptr bv_src,
unsigned  src_size,
bool  init_clear = true 
)
staticprotected

◆ sort_input_blocks_and()

template<typename BV >
bm::word_t * bm::aggregator< BV >::sort_input_blocks_and ( const bvector_type_const_ptr bv_src,
unsigned  src_size,
unsigned  i,
unsigned  j,
unsigned *  arg_blk_count,
unsigned *  arg_blk_gap_count 
)
protected

◆ sort_input_blocks_or()

template<typename BV >
bm::word_t * bm::aggregator< BV >::sort_input_blocks_or ( const bvector_type_const_ptr bv_src,
unsigned  src_size,
unsigned  i,
unsigned  j,
unsigned *  arg_blk_count,
unsigned *  arg_blk_gap_count 
)
protected

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