| 33 | |
| 34 | template <class TGroupIdClass> |
| 35 | static void CheckGroupIds( |
| 36 | ui32 objectCount, |
| 37 | TMaybeData<TConstArrayRef<TGroupIdClass>> groupIds, |
| 38 | TMaybe<TObjectsGroupingPtr> objectsGrouping |
| 39 | ) { |
| 40 | if (!groupIds) { |
| 41 | return; |
| 42 | } |
| 43 | auto groupIdsData = *groupIds; |
| 44 | |
| 45 | CheckDataSize(groupIdsData.size(), (size_t)objectCount, "group Ids", false); |
| 46 | |
| 47 | |
| 48 | TVector<TGroupIdClass> groupGroupIds; |
| 49 | TGroupBounds currentGroupBounds(0); // used only if objectsGrouping is defined |
| 50 | |
| 51 | if (objectsGrouping.Defined()) { |
| 52 | CheckDataSize( |
| 53 | groupIdsData.size(), |
| 54 | (size_t)(*objectsGrouping)->GetObjectCount(), |
| 55 | "group Ids", |
| 56 | false, |
| 57 | "objectGrouping's object count", |
| 58 | true |
| 59 | ); |
| 60 | |
| 61 | groupGroupIds.reserve((*objectsGrouping)->GetGroupCount()); |
| 62 | currentGroupBounds = (*objectsGrouping)->GetGroup(0); |
| 63 | } |
| 64 | |
| 65 | TGroupIdClass lastGroupId = groupIdsData[0]; |
| 66 | groupGroupIds.emplace_back(lastGroupId); |
| 67 | |
| 68 | // using ui32 for counters/indices here is safe because groupIdsData' size was checked above |
| 69 | for (auto objectIdx : xrange(ui32(1), ui32(groupIdsData.size()))) { |
| 70 | if (groupIdsData[objectIdx] != lastGroupId) { |
| 71 | if (objectsGrouping.Defined()) { |
| 72 | CB_ENSURE_INTERNAL( |
| 73 | objectIdx == currentGroupBounds.End, |
| 74 | "objectsGrouping and grouping by groupId have different ends for group #" |
| 75 | << (groupGroupIds.size() - 1) |
| 76 | ); |
| 77 | currentGroupBounds = (*objectsGrouping)->GetGroup((ui32)groupGroupIds.size()); |
| 78 | } |
| 79 | |
| 80 | lastGroupId = groupIdsData[objectIdx]; |
| 81 | groupGroupIds.emplace_back(lastGroupId); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | Sort(groupGroupIds); |
| 86 | auto it = std::adjacent_find(groupGroupIds.begin(), groupGroupIds.end()); |
| 87 | CB_ENSURE(it == groupGroupIds.end(), "group Ids are not consecutive"); |
| 88 | } |
| 89 | |
| 90 | static bool HaveMoreThanOneKeyOrAnyValueMismatch( |
| 91 | const THashMap<ui32, TString>& lhs, |
nothing calls this directly
no test coverage detected