Split the keys of a single file into groups (as before)
| 325 | |
| 326 | /// Split the keys of a single file into groups (as before) |
| 327 | static std::vector<KeyGroup> group_keys(const FileMap& file) { |
| 328 | std::vector<KeyGroup> groups; |
| 329 | groups.reserve(file.size()); |
| 330 | |
| 331 | size_t i = 0; |
| 332 | while (i < file.size()) { |
| 333 | const std::string& key = file[i].first; |
| 334 | |
| 335 | SeqKey sk; |
| 336 | if (parse_sequential_key(key, sk)) { |
| 337 | KeyGroup group; |
| 338 | group.prefix = sk.prefix; |
| 339 | group.keys.push_back(key); |
| 340 | |
| 341 | I32 expected = sk.index + 1; |
| 342 | size_t j = i + 1; |
| 343 | |
| 344 | while (j < file.size()) { |
| 345 | const std::string& next_key = file[j].first; |
| 346 | SeqKey next; |
| 347 | |
| 348 | if (parse_sequential_key(next_key, next) && next.prefix == sk.prefix && next.index == expected) { |
| 349 | group.keys.push_back(next_key); |
| 350 | expected++; |
| 351 | j++; |
| 352 | } else { |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | groups.push_back(group); |
| 358 | i = j; |
| 359 | } else { |
| 360 | KeyGroup group; |
| 361 | group.prefix = ""; |
| 362 | group.keys.push_back(key); |
| 363 | groups.push_back(group); |
| 364 | i++; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | return groups; |
| 369 | } |
| 370 | |
| 371 | /// Insert groups from a file into the basic sequence (anchor merging) |
| 372 | static void merge_groups(std::vector<KeyGroup>& base, const std::vector<KeyGroup>& next) { |
no test coverage detected