8 #ifndef UFO_UTILS_RECURSIVESPLITTER_H_
9 #define UFO_UTILS_RECURSIVESPLITTER_H_
71 const std::vector<size_t>::const_iterator &
end)
75 std::vector<size_t>::const_iterator
begin()
const
80 std::vector<size_t>::const_iterator
end()
const
86 std::vector<size_t>::const_iterator
begin_;
87 std::vector<size_t>::const_iterator
end_;
281 void groupBy(
const std::vector<size_t> &categories) {
286 void groupBy(
const std::vector<int> &categories) {
291 void groupBy(
const std::vector<std::string> &categories) {
305 template <
typename UnaryOperation>
318 void setSeed(
unsigned int seed,
bool force);
324 template <
typename T>
325 void groupByImpl(
const std::vector<T> &categories);
334 template <
typename UnaryOperation>
337 std::vector<size_t>::iterator nonConstGroupBegin =
339 std::vector<size_t>::iterator nonConstGroupEnd =
344 std::stable_sort(nonConstGroupBegin, nonConstGroupEnd,
345 [&key] (
size_t a,
size_t b) {
return key(a) < key(b); });
Utility class used in overloads of operator-> in forward iterators.
A range of indices of all array elements belonging to a particular equivalence class.
std::vector< size_t >::const_iterator end() const
std::vector< size_t >::const_iterator begin_
std::vector< size_t >::const_iterator begin() const
std::vector< size_t >::const_iterator end_
Group(const std::vector< size_t >::const_iterator &begin, const std::vector< size_t >::const_iterator &end)
An iterator over all equivalence classes.
GroupIterator(const RecursiveSplitter &splitter, EndTag)
bool operator==(const GroupIterator &other) const
MultiElementGroupIterator::EndTag EndTag
MultiElementGroupIterator::difference_type difference_type
bool operator!=(const GroupIterator &other) const
GroupIterator(const RecursiveSplitter &splitter, BeginTag)
GroupIterator & operator++()
ArrowProxy< Group > operator->() const
MultiElementGroupIterator::value_type value_type
MultiElementGroupIterator::BeginTag BeginTag
MultiElementGroupIterator::iterator_category iterator_category
MultiElementGroupIterator::reference reference
A range of equivalence classes.
GroupIterator end() const
GroupRange(const RecursiveSplitter &splitter)
GroupIterator begin() const
const RecursiveSplitter & splitter_
An iterator over equivalence classes consisting of more than one element.
size_t firstIndexInGroup_
ArrowProxy< Group > operator->() const
MultiElementGroupIterator(const RecursiveSplitter &splitter, EndTag)
std::forward_iterator_tag iterator_category
bool operator!=(const MultiElementGroupIterator &other) const
ArrowProxy< Group > reference
MultiElementGroupIterator(const RecursiveSplitter &splitter, BeginTag)
MultiElementGroupIterator & operator++()
const RecursiveSplitter & splitter_
bool operator==(const MultiElementGroupIterator &other) const
ptrdiff_t difference_type
A range of equivalence classes consisting of more than one element.
MultiElementGroupRange(const RecursiveSplitter &splitter)
const RecursiveSplitter & splitter_
MultiElementGroupIterator begin() const
MultiElementGroupIterator end() const
Partitions an array into groups of elements equivalent according to certain criteria.
GroupRange groups() const
Return the range of equivalence classes.
void groupBy(const std::vector< size_t > &categories)
Split existing equivalence classes according to a new criterion.
void groupByImpl(const std::vector< T > &categories)
void groupBy(const std::vector< std::string > &categories)
This is an overloaded member function, provided for convenience. It differs from the above function o...
MultiElementGroupRange multiElementGroups() const
Return the range of equivalence classes consisting of more than one element.
void shuffleGroups()
Randomly shuffle the elements of each equivalence class.
void sortGroupsBy(const UnaryOperation &key)
Sort the elements in each equivalence class in ascending order.
std::vector< size_t > orderedIds_
Indices of elements of the partitioned array ordered by equivalence class.
RecursiveSplitter(size_t numIds, bool opsCompatibilityMode=false)
Initialize partitioning of an array of numIds elements.
std::vector< size_t > encodedGroups_
Encoded locations of multi-element equivalence classes in orderedIds_.
bool opsCompatibilityMode_
void initializeEncodedGroups()
void groupBy(const std::vector< int > &categories)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setSeed(unsigned int seed, bool force)
Initialise the random number generator used by shuffleGroups() with a seed.
void metOfficeSort(RandomIt first, RandomIt last, const UnaryOperation &key)
Sort the range [first, last) in the order of ascending keys using the same algorithm as the Ops_Integ...