Given a vector of fragment indices (one per batch) return a vector (one per fragment) mapping fragment index to the last occurrence of that index in order This allows us to know when to mark a fragment as finished
| 1778 | // |
| 1779 | // This allows us to know when to mark a fragment as finished |
| 1780 | std::vector<int> GetLastIndices(const std::vector<int>& order) { |
| 1781 | std::vector<int> last_indices(kNumFragments); |
| 1782 | for (std::size_t i = 0; i < kNumFragments; i++) { |
| 1783 | auto last_p = std::find(order.rbegin(), order.rend(), static_cast<int>(i)); |
| 1784 | EXPECT_NE(last_p, order.rend()); |
| 1785 | last_indices[i] = static_cast<int>(std::distance(last_p, order.rend())) - 1; |
| 1786 | } |
| 1787 | return last_indices; |
| 1788 | } |
| 1789 | |
| 1790 | /// We buffer one item in order to enumerate it (technically this could be avoided if |
| 1791 | /// delivering in order but easier to have a single code path). We also can't deliver |