| 31 | */ |
| 32 | template <typename Iter, typename Idx> |
| 33 | void RunLengthEncode(Iter begin, Iter end, std::vector<Idx>* p_out) { |
| 34 | auto& out = *p_out; |
| 35 | out = std::vector<Idx>{0}; |
| 36 | size_t n = std::distance(begin, end); |
| 37 | for (size_t i = 1; i < n; ++i) { |
| 38 | if (begin[i] != begin[i - 1]) { |
| 39 | out.push_back(i); |
| 40 | } |
| 41 | } |
| 42 | if (out.back() != n) { |
| 43 | out.push_back(n); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @brief Variant of std::partial_sum, out_it should point to a container that has n + 1 |
no outgoing calls