![]() |
fpmas 1.6
|
#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) | |
K | key () const |
std::size_t | offset () const |
Index & | operator++ () |
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) |
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:
item_counts[rank]
(see DistributedIndex)item_counts[grid coordinate]
) (see model::GridAgentIndex)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:
An associated index will generate the following sequence, from begin() to end():
The Index usage is based on iterator like operations.
K | key type to which objects counts are associated. K must be a valid std::map key, i.e. K must implement the operator< . |
|
inline |
|
inline |
|
inline |
Initializes an index representing item_counts
, that points to offset
from key
.
|
inline |
Key index.
|
inline |
Local offset.
|
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.
|
static |
End of the distributed index associated to item_counts
.
Index< K > & fpmas::random::Index< K >::operator++ |
Increments the current Index.
Index< K > fpmas::random::Index< K >::operator++ | ( | int | ) |
Increments the current Index and returns the index value before the increment.
Index< K > fpmas::random::Index< K >::operator+ | ( | std::size_t | n | ) | const |
Returns a copy of the current Index incremented by n
.
|
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.
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.
bool fpmas::random::Index< K >::operator!= | ( | const Index< K > & | index | ) | const |
Equivalent to !(*this==index)
.
bool fpmas::random::Index< K >::operator< | ( | const Index< K > & | index | ) | const |
Compares two indexes.