JASSv2
Public Member Functions | Static Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes | Friends | List of all members
JASS::accumulator_block_max< ELEMENT, NUMBER_OF_ACCUMULATORS, typename > Class Template Reference

Store the accumulators in a block-max array as originally used in IOQP. More...

#include <accumulator_block_max.h>

Collaboration diagram for JASS::accumulator_block_max< ELEMENT, NUMBER_OF_ACCUMULATORS, typename >:
Collaboration graph
[legend]

Public Member Functions

 accumulator_block_max ()
 Constructor.
 
virtual ~accumulator_block_max ()
 Destructor.
 
void init (size_t number_of_accumulators, size_t preferred_width=0)
 Initialise this object before first use. More...
 
forceinline size_t which_block (size_t element) const
 Return the id of the block to use. More...
 
forceinline void add (size_t which, ELEMENT value)
 add value to a given accumulator. i.e. accumulator[which] += value; More...
 
forceinline ELEMENT & operator[] (size_t which)
 Return a reference to the given accumulator. More...
 
forceinline size_t get_index (ELEMENT *pointer)
 Given a pointer to an accumulator, return the acumulator index. More...
 
size_t size (void) const
 Return the number of accumulators in the array. More...
 
void rewind (void)
 Clear the accumulators ready for use.
 

Static Public Member Functions

template<typename ACCUMULATOR_TYPE >
static void unittest_example (ACCUMULATOR_TYPE &instance)
 Unit test a single 2D accumulator instance making sure its correct.
 
static void unittest (void)
 Unit test this class.
 

Public Attributes

ELEMENT block_max [maximum_number_of_blocks]
 The dirty flags are kept as bytes for faster lookup.
 
ELEMENT accumulator [maximum_number_of_accumulators_allocated]
 The accumulators are kept in an array.
 
uint32_t shift
 The amount to shift to get the right dirty flag.
 
size_t width
 Each dirty flag represents this number of accumulators in a "row".
 
size_t number_of_blocks
 The number of "rows" (i.e. dirty flags)
 

Private Attributes

size_t number_of_accumulators_allocated
 The numner of accumulators that were actually allocated (recall that this is a 2D array)
 
size_t number_of_accumulators
 The number of accumulators that the user asked for.
 

Static Private Attributes

static constexpr size_t maximum_number_of_blocks = NUMBER_OF_ACCUMULATORS
 
static constexpr size_t maximum_number_of_accumulators_allocated = NUMBER_OF_ACCUMULATORS + NUMBER_OF_ACCUMULATORS / 2
 The numner of accumulators that were actually allocated (so that the last block is a full block)
 

Friends

template<typename A , size_t B, typename C >
class accumulator_block_max
 

Detailed Description

template<typename ELEMENT, size_t NUMBER_OF_ACCUMULATORS, typename = typename std::enable_if<std::is_arithmetic<ELEMENT>::value, ELEMENT>::type>
class JASS::accumulator_block_max< ELEMENT, NUMBER_OF_ACCUMULATORS, typename >

Store the accumulators in a block-max array as originally used in IOQP.

Template Parameters
ELEMENTThe type of accumulator being used (default is uint16_t)
NUMBER_OF_ACCUMULATORSThe maxium number of documents allowed in any index

Member Function Documentation

◆ add()

template<typename ELEMENT, size_t NUMBER_OF_ACCUMULATORS, typename = typename std::enable_if<std::is_arithmetic<ELEMENT>::value, ELEMENT>::type>
forceinline void JASS::accumulator_block_max< ELEMENT, NUMBER_OF_ACCUMULATORS, typename >::add ( size_t  which,
ELEMENT  value 
)
inline

add value to a given accumulator. i.e. accumulator[which] += value;

Parameters
which[in] Which accumulator to add to
value[in] The value to add

◆ get_index()

template<typename ELEMENT, size_t NUMBER_OF_ACCUMULATORS, typename = typename std::enable_if<std::is_arithmetic<ELEMENT>::value, ELEMENT>::type>
forceinline size_t JASS::accumulator_block_max< ELEMENT, NUMBER_OF_ACCUMULATORS, typename >::get_index ( ELEMENT *  pointer)
inline

Given a pointer to an accumulator, return the acumulator index.

Parameters
returna value such that get_index(&accumulator[x]) == x

◆ init()

template<typename ELEMENT, size_t NUMBER_OF_ACCUMULATORS, typename = typename std::enable_if<std::is_arithmetic<ELEMENT>::value, ELEMENT>::type>
void JASS::accumulator_block_max< ELEMENT, NUMBER_OF_ACCUMULATORS, typename >::init ( size_t  number_of_accumulators,
size_t  preferred_width = 0 
)
inline

Initialise this object before first use.

Parameters
number_of_accumulators[in] The numnber of elements in the array being managed.
preferred_width[in] The preferred width of each block, where the actual width is 2^preferred_width (if possible)

◆ operator[]()

template<typename ELEMENT, size_t NUMBER_OF_ACCUMULATORS, typename = typename std::enable_if<std::is_arithmetic<ELEMENT>::value, ELEMENT>::type>
forceinline ELEMENT& JASS::accumulator_block_max< ELEMENT, NUMBER_OF_ACCUMULATORS, typename >::operator[] ( size_t  which)
inline

Return a reference to the given accumulator.

The only valid way to access the accumulators is through this interface. It ensures the accumulator has been initialised before the first time it is returned to the caller.

Parameters
which[in] The accumulator to return.
Returns
The accumulator.

◆ size()

template<typename ELEMENT, size_t NUMBER_OF_ACCUMULATORS, typename = typename std::enable_if<std::is_arithmetic<ELEMENT>::value, ELEMENT>::type>
size_t JASS::accumulator_block_max< ELEMENT, NUMBER_OF_ACCUMULATORS, typename >::size ( void  ) const
inline

Return the number of accumulators in the array.

Return the number of accumulators in the array which may be fewer than have been allocated.

Returns
Size of the accumulator array.

◆ which_block()

template<typename ELEMENT, size_t NUMBER_OF_ACCUMULATORS, typename = typename std::enable_if<std::is_arithmetic<ELEMENT>::value, ELEMENT>::type>
forceinline size_t JASS::accumulator_block_max< ELEMENT, NUMBER_OF_ACCUMULATORS, typename >::which_block ( size_t  element) const
inline

Return the id of the block to use.

Parameters
element[in] The accumulator number.
Returns
The block number.

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