20#ifndef SAYONARA_PLAYER_RANGES_H
21#define SAYONARA_PLAYER_RANGES_H
23#include "Utils/Algorithm.h"
30 using Range = std::pair<int, int>;
31 using RangeList = std::vector<Range>;
33 template<
typename Element,
template<
typename>
typename Container>
34 Range getNextRange(
const Container<Element>& ids,
int startIndex)
36 if(startIndex >= ids.size())
38 return std::make_pair(-1, -1);
41 auto result = std::make_pair(startIndex, startIndex);
43 auto currentIndex = startIndex;
44 auto currentValue = ids[currentIndex];
45 auto expectedValue = currentValue;
47 while(currentValue == expectedValue)
49 result.second = currentIndex;
53 if(currentIndex == ids.size())
59 currentValue = ids[currentIndex];
65 template<
typename Element,
template<
typename>
typename Container>
66 RangeList getRangesFromList(
const Container<Element>& ids)
74 auto p = getNextRange(ids, 0);
78 p = getNextRange(ids, p.second + 1);
84 template<
typename Element,
template<
typename>
typename Container>
85 auto prepareContainerForRangeCalculation(Container<Element> container) -> Container<Element>
87 std::sort(container.begin(), container.end());
88 Util::Algorithm::remove_duplicates(container);
Helper functions.
Definition: Utils.h:38