MADNESS  0.10.1
Public Types | Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
madness::Range< iteratorT > Class Template Reference

Range, vaguely a la Intel TBB, to encapsulate a random-access, STL-like start and end iterator with chunksize. More...

#include <range.h>

Public Types

using iterator = iteratorT
 Alias for the iterator type. More...
 

Public Member Functions

 Range (const iterator &start, const iterator &finish, int chunk=1)
 Makes the range [start, finish). More...
 
 Range (const Range &r)
 Copy constructor. Cost is O(1). More...
 
 Range (Range &left, const Split &)
 Splits range between new and old (r) objects. Cost is O(1). More...
 
const iteratorbegin () const
 Access the beginning. More...
 
bool empty () const
 Returns true if size == 0. More...
 
const iteratorend () const
 Access the end. More...
 
unsigned int get_chunksize () const
 Access the chunk size. More...
 
bool is_divisible () const
 Return true if this iteration range can be divided; that is, there are more items than the chunk size. More...
 
size_t size () const
 Returns the number of items in the range (cost is O(1)). More...
 

Static Private Member Functions

template<typename integralT , typename distanceT >
static std::enable_if< std::is_integral< integralT >::value, void >::type advance (integralT &i, distanceT n)
 Advance by n elements in the range. More...
 
template<typename iterT , typename distanceT >
static std::enable_if<!std::is_integral< iterT >::value, void >::type advance (iterT &it, distanceT n)
 Advance by n elements in the range. More...
 
template<class integralT >
static std::enable_if< std::is_integral< integralT >::value, integralT >::type distance (integralT first, integralT last)
 Calculate the distance between two iterators. More...
 
template<class iterT >
static auto distance (iterT first, iterT last, typename std::enable_if<!std::is_integral< iterT >::value >::type *=nullptr) -> decltype(std::distance(first, last))
 Calculate the distance between two iterators. More...
 

Private Attributes

int chunksize
 Number of items to give to each thread/process. More...
 
iteratorT finish
 Last item for iteration (first past the end, conventionally). More...
 
long n
 Number of items to iterator over. More...
 
iteratorT start
 First item for iteration. More...
 

Detailed Description

template<typename iteratorT>
class madness::Range< iteratorT >

Range, vaguely a la Intel TBB, to encapsulate a random-access, STL-like start and end iterator with chunksize.

Template Parameters
iteratorTThe iterator type.

Member Typedef Documentation

◆ iterator

template<typename iteratorT >
using madness::Range< iteratorT >::iterator = iteratorT

Alias for the iterator type.

Constructor & Destructor Documentation

◆ Range() [1/3]

template<typename iteratorT >
madness::Range< iteratorT >::Range ( const iterator start,
const iterator finish,
int  chunk = 1 
)
inline

Makes the range [start, finish).

The motivated reader should look at the Intel TBB range, partitioner, split, concepts, etc.

Parameters
[in]startThe first item to iterate over.
[in]finishThe last item for iteration (one past the end).
[in]chunkThe number of items to give to each thread/process.

References madness::Range< iteratorT >::chunksize.

◆ Range() [2/3]

template<typename iteratorT >
madness::Range< iteratorT >::Range ( const Range< iteratorT > &  r)
inline

Copy constructor. Cost is O(1).

Todo:
Can we make this = default?
Parameters
[in]rThe Range to copy.

◆ Range() [3/3]

template<typename iteratorT >
madness::Range< iteratorT >::Range ( Range< iteratorT > &  left,
const Split  
)
inline

Splits range between new and old (r) objects. Cost is O(1).

Parameters
[in]leftThe range to be split.

References madness::Range< iteratorT >::advance(), madness::Range< iteratorT >::chunksize, madness::Range< iteratorT >::finish, madness::Range< iteratorT >::n, and madness::Range< iteratorT >::start.

Member Function Documentation

◆ advance() [1/2]

template<typename iteratorT >
template<typename integralT , typename distanceT >
static std::enable_if<std::is_integral<integralT>::value, void>::type madness::Range< iteratorT >::advance ( integralT &  i,
distanceT  n 
)
inlinestaticprivate

Advance by n elements in the range.

This version is for cases where the "iterator type" is integral.

Template Parameters
integralTThe integral iterator type.
distanceTThe distance type.
Parameters
[in,out]iThe integral iterator.
[in]nThe number of elements to advance.

References madness::Range< iteratorT >::n.

Referenced by madness::Range< iteratorT >::Range().

◆ advance() [2/2]

template<typename iteratorT >
template<typename iterT , typename distanceT >
static std::enable_if<!std::is_integral<iterT>::value, void>::type madness::Range< iteratorT >::advance ( iterT &  it,
distanceT  n 
)
inlinestaticprivate

Advance by n elements in the range.

This version is for cases where the "iterator type" is not integral.

Template Parameters
iterTThe non-integral iterator type.
distanceTThe distance type.
Parameters
[in,out]itThe iterator.
[in]nThe number of elements to advance.

References std::advance(), and madness::Range< iteratorT >::n.

◆ begin()

template<typename iteratorT >
const iterator& madness::Range< iteratorT >::begin ( ) const
inline

Access the beginning.

Returns
Iterator to the first element.

References madness::Range< iteratorT >::start.

◆ distance() [1/2]

template<typename iteratorT >
template<class integralT >
static std::enable_if<std::is_integral<integralT>::value, integralT>::type madness::Range< iteratorT >::distance ( integralT  first,
integralT  last 
)
inlinestaticprivate

Calculate the distance between two iterators.

This version is for cases where the "iterator type" is integral.

Template Parameters
integralTThe integral iterator type.
Parameters
[in]firstOne iterator.
[in]lastThe other iterator.
Returns
The distance between the first and last iterators.

◆ distance() [2/2]

template<typename iteratorT >
template<class iterT >
static auto madness::Range< iteratorT >::distance ( iterT  first,
iterT  last,
typename std::enable_if<!std::is_integral< iterT >::value >::type = nullptr 
) -> decltype(std::distance(first, last))
inlinestaticprivate

Calculate the distance between two iterators.

This version is for cases where the "iterator type" is not integral.

Template Parameters
iterTThe non-integral iterator type.
Parameters
[in]firstOne iterator.
[in]lastThe other iterator.
Returns
The distance between the first and last iterators.

References std::distance().

◆ empty()

template<typename iteratorT >
bool madness::Range< iteratorT >::empty ( ) const
inline

Returns true if size == 0.

Returns
True if size == 0.

References madness::Range< iteratorT >::n.

◆ end()

template<typename iteratorT >
const iterator& madness::Range< iteratorT >::end ( ) const
inline

Access the end.

Returns
Iterator to the last element (one past the end).

References madness::Range< iteratorT >::finish.

◆ get_chunksize()

template<typename iteratorT >
unsigned int madness::Range< iteratorT >::get_chunksize ( ) const
inline

Access the chunk size.

Todo:
Should this return long, or size_t?
Returns
The chunk size.

References madness::Range< iteratorT >::chunksize.

◆ is_divisible()

template<typename iteratorT >
bool madness::Range< iteratorT >::is_divisible ( ) const
inline

Return true if this iteration range can be divided; that is, there are more items than the chunk size.

Returns
True if this range can be divided.

References madness::Range< iteratorT >::chunksize, and madness::Range< iteratorT >::n.

◆ size()

template<typename iteratorT >
size_t madness::Range< iteratorT >::size ( ) const
inline

Returns the number of items in the range (cost is O(1)).

Returns
The number of items in the range.

References madness::Range< iteratorT >::n.

Referenced by split().

Member Data Documentation

◆ chunksize

template<typename iteratorT >
int madness::Range< iteratorT >::chunksize
private

◆ finish

template<typename iteratorT >
iteratorT madness::Range< iteratorT >::finish
private

Last item for iteration (first past the end, conventionally).

Referenced by madness::Range< iteratorT >::Range(), and madness::Range< iteratorT >::end().

◆ n

template<typename iteratorT >
long madness::Range< iteratorT >::n
private

◆ start

template<typename iteratorT >
iteratorT madness::Range< iteratorT >::start
private

First item for iteration.

Referenced by madness::Range< iteratorT >::Range(), and madness::Range< iteratorT >::begin().


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