UFO
|
Partitions an array into groups of elements equivalent according to certain criteria. More...
#include <RecursiveSplitter.h>
Classes | |
class | Group |
A range of indices of all array elements belonging to a particular equivalence class. More... | |
class | GroupIterator |
An iterator over all equivalence classes. More... | |
class | GroupRange |
A range of equivalence classes. More... | |
class | MultiElementGroupIterator |
An iterator over equivalence classes consisting of more than one element. More... | |
class | MultiElementGroupRange |
A range of equivalence classes consisting of more than one element. More... | |
Public Member Functions | |
RecursiveSplitter (size_t numIds, bool opsCompatibilityMode=false) | |
Initialize partitioning of an array of numIds elements. More... | |
void | groupBy (const std::vector< size_t > &categories) |
Split existing equivalence classes according to a new criterion. More... | |
void | groupBy (const std::vector< int > &categories) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | groupBy (const std::vector< std::string > &categories) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
GroupRange | groups () const |
Return the range of equivalence classes. More... | |
MultiElementGroupRange | multiElementGroups () const |
Return the range of equivalence classes consisting of more than one element. More... | |
template<typename UnaryOperation > | |
void | sortGroupsBy (const UnaryOperation &key) |
Sort the elements in each equivalence class in ascending order. More... | |
void | shuffleGroups () |
Randomly shuffle the elements of each equivalence class. More... | |
void | setSeed (unsigned int seed, bool force) |
Initialise the random number generator used by shuffleGroups() with a seed. More... | |
Private Member Functions | |
void | initializeEncodedGroups () |
template<typename T > | |
void | groupByImpl (const std::vector< T > &categories) |
Private Attributes | |
bool | opsCompatibilityMode_ |
std::vector< size_t > | orderedIds_ |
Indices of elements of the partitioned array ordered by equivalence class. More... | |
std::vector< size_t > | encodedGroups_ |
Encoded locations of multi-element equivalence classes in orderedIds_. More... | |
Partitions an array into groups of elements equivalent according to certain criteria.
Output:
Definition at line 63 of file src/ufo/utils/RecursiveSplitter.h.
|
explicit |
Initialize partitioning of an array of numIds
elements.
Initially, all elements are assumed to belong to the same equivalence class.
By default, all sorting operations performed by this class are done using a stable sorting algorithm, but if opsCompatibilityMode
is true, the same algorithm as in the Met Office OPS system (heap sort) is used instead. This has an effect on the order of elements in each equivalence class.
Definition at line 18 of file RecursiveSplitter.cc.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 286 of file src/ufo/utils/RecursiveSplitter.h.
|
inline |
Split existing equivalence classes according to a new criterion.
categories | A vector assigning each element of the partitioned array to a unique category. |
Each existing equivalence class E consisting of N_E elements with indices E_i (0 <= i < N_E) is split into one or more classes according to the equivalence relation
E_i'th element is equivalent to E_j'th element if and only if categories[E_i] == categories[E_j].
Definition at line 281 of file src/ufo/utils/RecursiveSplitter.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 291 of file src/ufo/utils/RecursiveSplitter.h.
|
private |
Definition at line 38 of file RecursiveSplitter.cc.
|
inline |
Return the range of equivalence classes.
Definition at line 296 of file src/ufo/utils/RecursiveSplitter.h.
|
private |
|
inline |
Return the range of equivalence classes consisting of more than one element.
Definition at line 299 of file src/ufo/utils/RecursiveSplitter.h.
void ufo::RecursiveSplitter::setSeed | ( | unsigned int | seed, |
bool | force | ||
) |
Initialise the random number generator used by shuffleGroups() with a seed.
seed | Seed with which to initialise the generator. |
force | If false, the seed will only be reset if the program has not made any calls to util::shuffle() yet. |
Definition at line 94 of file RecursiveSplitter.cc.
void ufo::RecursiveSplitter::shuffleGroups | ( | ) |
Randomly shuffle the elements of each equivalence class.
Definition at line 84 of file RecursiveSplitter.cc.
void ufo::RecursiveSplitter::sortGroupsBy | ( | const UnaryOperation & | key | ) |
Sort the elements in each equivalence class in ascending order.
The elements are ranked by keys produced by the unary function key
taking the index of an element of the partitioned array.
Definition at line 335 of file src/ufo/utils/RecursiveSplitter.h.
|
private |
Encoded locations of multi-element equivalence classes in orderedIds_.
Definition at line 331 of file src/ufo/utils/RecursiveSplitter.h.
|
private |
Definition at line 327 of file src/ufo/utils/RecursiveSplitter.h.
|
private |
Indices of elements of the partitioned array ordered by equivalence class.
Definition at line 329 of file src/ufo/utils/RecursiveSplitter.h.