From 4c8ff9c22e36cb08d643cd42ee1cb02bed9088b4 Mon Sep 17 00:00:00 2001 From: x7z4w Date: Fri, 7 Nov 2025 13:40:04 +0000 Subject: [PATCH] [routing] Faster IndexGraph Signed-off-by: x7z4w --- libs/routing/cross_mwm_connector.hpp | 13 +++++++--- libs/routing/index_graph.cpp | 27 ++++++++------------- libs/routing/index_graph.hpp | 2 -- libs/routing/index_graph_starter_joints.hpp | 15 +++++++----- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/libs/routing/cross_mwm_connector.hpp b/libs/routing/cross_mwm_connector.hpp index 64312c238..987203b80 100644 --- a/libs/routing/cross_mwm_connector.hpp +++ b/libs/routing/cross_mwm_connector.hpp @@ -11,6 +11,7 @@ #include "base/assert.hpp" #include "base/buffer_vector.hpp" +#include #include #include #include @@ -117,27 +118,31 @@ public: template void ForEachEnter(FnT && fn) const { - for (auto const & [key, transit] : m_transitions) + std::for_each(std::execution::par_unseq, m_transitions.begin(), m_transitions.end(), [&](auto const & pair) { + auto const & [key, transit] = pair; + if (transit.m_forwardIsEnter) fn(transit.m_enterIdx, Segment(m_mwmId, key.m_featureId, key.m_segmentIdx, true)); if (!transit.m_oneWay && !transit.m_forwardIsEnter) fn(transit.m_enterIdx, Segment(m_mwmId, key.m_featureId, key.m_segmentIdx, false)); - } + }); } template void ForEachExit(FnT && fn) const { - for (auto const & [key, transit] : m_transitions) + std::for_each(std::execution::par_unseq, m_transitions.begin(), m_transitions.end(), [&](auto const & pair) { + auto const & [key, transit] = pair; + if (!transit.m_forwardIsEnter) fn(transit.m_exitIdx, Segment(m_mwmId, key.m_featureId, key.m_segmentIdx, true)); if (!transit.m_oneWay && transit.m_forwardIsEnter) fn(transit.m_exitIdx, Segment(m_mwmId, key.m_featureId, key.m_segmentIdx, false)); - } + }); } void GetOutgoingEdgeList(Segment const & segment, EdgeListT & edges) const diff --git a/libs/routing/index_graph.cpp b/libs/routing/index_graph.cpp index a2de29691..91e49442c 100644 --- a/libs/routing/index_graph.cpp +++ b/libs/routing/index_graph.cpp @@ -4,16 +4,14 @@ #include "routing/routing_options.hpp" #include "routing/world_graph.hpp" -#include "platform/settings.hpp" - #include "base/assert.hpp" #include "base/checked_cast.hpp" -#include "base/exception.hpp" #include "base/timer.hpp" #include "geometry/distance_on_sphere.hpp" #include +#include #include #include @@ -321,7 +319,9 @@ void IndexGraph::ReconstructJointSegment(astar::VertexData const & fromVertexData, Segment const & to, diff --git a/libs/routing/index_graph.hpp b/libs/routing/index_graph.hpp index 881956d63..4fb7392f2 100644 --- a/libs/routing/index_graph.hpp +++ b/libs/routing/index_graph.hpp @@ -18,8 +18,6 @@ #include "indexer/feature_meta.hpp" -#include "geometry/point2d.hpp" - #include #include #include diff --git a/libs/routing/index_graph_starter_joints.hpp b/libs/routing/index_graph_starter_joints.hpp index e6c260978..70209e898 100644 --- a/libs/routing/index_graph_starter_joints.hpp +++ b/libs/routing/index_graph_starter_joints.hpp @@ -13,6 +13,7 @@ #include "3party/skarupke/bytell_hash_map.hpp" // needed despite of IDE warning #include +#include #include #include #include @@ -474,7 +475,8 @@ void IndexGraphStarterJoints::GetEdgeList(astar::VertexDatasecond; - for (size_t i = 0; i < edges.size(); ++i) + auto const range = std::ranges::views::iota(0uz, edges.size()); + std::for_each(std::execution::par_unseq, range.begin(), range.end(), [&, this](auto const i) { // Saving weight of current edges for returning in the next iterations. auto & w = edges[i].GetWeight(); @@ -490,7 +492,7 @@ void IndexGraphStarterJoints::GetEdgeList(astar::VertexData::GetEdgeList(astar::VertexData::GetEdgeList(astar::VertexDatav2 transition moving backward (v2 ingoing). This is impossible in current (m_savedWeight) /// logic, so I moved Cross-MWM penalty into separate block here after _all_ weights calculations. - for (auto & e : edges) + std::for_each(std::execution::par_unseq, edges.begin(), edges.end(), [&, this](auto & e) { auto const targetMwmId = e.GetTarget().GetMwmId(); if (targetMwmId != kFakeNumMwmId && vertexMwmId != targetMwmId) e.GetWeight() += m_graph.GetCrossBorderPenalty(vertexMwmId, targetMwmId); - } + }); } }