fpmas 1.6
Public Member Functions | Static Public Member Functions | List of all members
fpmas::random::Index< K > Class Template Reference

#include <random.h>

Public Member Functions

 Index (const std::map< K, std::size_t > *item_counts)
 
 Index (const std::map< K, std::size_t > *item_counts, typename std::map< K, std::size_t >::const_iterator it)
 
 Index (const std::map< K, std::size_t > *item_counts, K key, std::size_t offset)
 
key () const
 
std::size_t offset () const
 
Indexoperator++ ()
 
Index operator++ (int)
 
Index operator+ (std::size_t n) const
 
bool operator== (const Index &index) const
 
bool operator!= (const Index &index) const
 
bool operator< (const Index &index) const
 

Static Public Member Functions

static Index begin (const std::map< K, std::size_t > *item_counts)
 
static Index end (const std::map< K, std::size_t > *item_counts)
 
static std::size_t distance (const Index &i1, const Index &i2)
 

Detailed Description

template<typename K>
class fpmas::random::Index< K >

Implements a generic index that can be used to iterate hover a set of items such has an item count is associated to each key.

For exemple:

Keys are ordered, so that the same pass is always performed. The index starts at the offset 0 from the first key that is assigned to a non null item count. The index then increments its offset until reaching the last item associated to the key, and then go to the next key. Entries associated to 0 items are automatically ignored by the index.

For example, the let's consider the following item_counts input:

k1: 2
k2: 1
k3: 0
k4: 2

An associated index will generate the following sequence, from begin() to end():

(k1, 0), (k1, 1), (k2, 0), (k4, 0), (k4, 1)

The Index usage is based on iterator like operations.

Template Parameters
Kkey type to which objects counts are associated. K must be a valid std::map key, i.e. K must implement the operator<.

Constructor & Destructor Documentation

◆ Index() [1/3]

template<typename K >
fpmas::random::Index< K >::Index ( const std::map< K, std::size_t > *  item_counts)
inline

Initializes an index representing item_counts.

offset() and key() are left undefined.

◆ Index() [2/3]

template<typename K >
fpmas::random::Index< K >::Index ( const std::map< K, std::size_t > *  item_counts,
typename std::map< K, std::size_t >::const_iterator  it 
)
inline

Initializes an index representing item_counts.

The key() is deduced from the specified iterator, and offset() is set to 0.

◆ Index() [3/3]

template<typename K >
fpmas::random::Index< K >::Index ( const std::map< K, std::size_t > *  item_counts,
key,
std::size_t  offset 
)
inline

Initializes an index representing item_counts, that points to offset from key.

Member Function Documentation

◆ key()

template<typename K >
K fpmas::random::Index< K >::key ( ) const
inline

Key index.

◆ offset()

template<typename K >
std::size_t fpmas::random::Index< K >::offset ( ) const
inline

Local offset.

◆ begin()

template<typename K >
Index< K > fpmas::random::Index< K >::begin ( const std::map< K, std::size_t > *  item_counts)
static

Begin of the index associated to item_counts, i.e. (k0, 0) where k0 is the first key that owns at least one item.

◆ end()

template<typename K >
Index< K > fpmas::random::Index< K >::end ( const std::map< K, std::size_t > *  item_counts)
static

End of the distributed index associated to item_counts.

◆ operator++() [1/2]

template<typename K >
Index< K > & fpmas::random::Index< K >::operator++

Increments the current Index.

◆ operator++() [2/2]

template<typename K >
Index< K > fpmas::random::Index< K >::operator++ ( int  )

Increments the current Index and returns the index value before the increment.

◆ operator+()

template<typename K >
Index< K > fpmas::random::Index< K >::operator+ ( std::size_t  n) const

Returns a copy of the current Index incremented by n.

◆ distance()

template<typename K >
std::size_t fpmas::random::Index< K >::distance ( const Index< K > &  i1,
const Index< K > &  i2 
)
static

Returns the distance between i1 and i2, i.e. the number of increments to reach i2 from i1. The behavior is undefined if i2 cannot be reached from i1.

distance(begin(item_counts), end(item_counts)) notably returns the total number of items owned by all keys.

◆ operator==()

template<typename K >
bool fpmas::random::Index< K >::operator== ( const Index< K > &  index) const

Returns true iff index is equal to this.

item_counts are not taken into account in the comparison process.

◆ operator!=()

template<typename K >
bool fpmas::random::Index< K >::operator!= ( const Index< K > &  index) const

Equivalent to !(*this==index).

◆ operator<()

template<typename K >
bool fpmas::random::Index< K >::operator< ( const Index< K > &  index) const

Compares two indexes.


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