@@ -432,6 +432,29 @@ parse_turn_penalty_lookup_from_csv_files(const std::vector<std::string> &turn_pe
432
432
433
433
tbb::parallel_for (std::size_t {0 }, turn_penalty_filenames.size (), parse_turn_penalty_file);
434
434
435
+ // With flattened map-ish view of all the files, sort and unique them on from,to,source
436
+ // The greater '>' is used here since we want to give files later on higher precedence
437
+ const auto sort_by = [](const TurnPenaltySource &lhs, const TurnPenaltySource &rhs) {
438
+ return std::tie (lhs.segment .from , lhs.segment .via , lhs.segment .to , lhs.penalty_source .source ) >
439
+ std::tie (rhs.segment .from , rhs.segment .via , rhs.segment .to , rhs.penalty_source .source );
440
+ };
441
+
442
+ std::stable_sort (begin (map), end (map), sort_by);
443
+
444
+ // Unique only on from,to to take the source precedence into account and remove duplicates
445
+ const auto unique_by = [](const TurnPenaltySource &lhs, const TurnPenaltySource &rhs) {
446
+ return std::tie (lhs.segment .from , lhs.segment .via , lhs.segment .to ) ==
447
+ std::tie (rhs.segment .from , rhs.segment .via , rhs.segment .to );
448
+ };
449
+
450
+ const auto it = std::unique (begin (map), end (map), unique_by);
451
+
452
+ map.erase (it, end (map));
453
+
454
+ util::SimpleLogger ().Write () << " In total loaded " << turn_penalty_filenames.size ()
455
+ << " turn penalty file(s) with a total of " << map.size ()
456
+ << " unique values" ;
457
+
435
458
return map;
436
459
}
437
460
} // anon ns
0 commit comments