diff --git a/routing/geometry.cpp b/routing/geometry.cpp index 98aa30e2ff..e87b16d604 100644 --- a/routing/geometry.cpp +++ b/routing/geometry.cpp @@ -262,6 +262,15 @@ Geometry::Geometry(unique_ptr loader) CHECK(m_loader, ()); } +Geometry::Geometry(std::unique_ptr loader, size_t roadsCacheSize) + : m_loader(move(loader)) + , m_featureIdToRoad(make_unique( + roadsCacheSize, + [this](uint32_t featureId, RoadGeometry & road) { m_loader->Load(featureId, road); })) +{ + CHECK(m_loader, ()); +} + RoadGeometry const & Geometry::GetRoad(uint32_t featureId) { ASSERT(m_featureIdToRoad, ()); diff --git a/routing/geometry.hpp b/routing/geometry.hpp index 1d60cc4f3c..2605543c30 100644 --- a/routing/geometry.hpp +++ b/routing/geometry.hpp @@ -136,6 +136,7 @@ class Geometry final public: Geometry() = default; explicit Geometry(std::unique_ptr loader); + Geometry(std::unique_ptr loader, size_t roadsCacheSize); /// \note The reference returned by the method is valid until the next call of GetRoad() /// of GetPoint() methods. diff --git a/routing/index_graph_loader.cpp b/routing/index_graph_loader.cpp index 95adc4d4d6..a8ca36e978 100644 --- a/routing/index_graph_loader.cpp +++ b/routing/index_graph_loader.cpp @@ -273,4 +273,12 @@ void DeserializeIndexGraph(MwmValue const & mwmValue, VehicleType vehicleType, I if (ReadRoadAccessFromMwm(mwmValue, vehicleType, roadAccess)) graph.SetRoadAccess(move(roadAccess)); } + +uint32_t DeserializeIndexGraphNumRoads(MwmValue const & mwmValue, VehicleType vehicleType) +{ + FilesContainerR::TReader reader(mwmValue.m_cont.GetReader(ROUTING_FILE_TAG)); + ReaderSource src(reader); + return IndexGraphSerializer::DeserializeNumRoads(src, GetVehicleMask(vehicleType)); +} + } // namespace routing diff --git a/routing/index_graph_loader.hpp b/routing/index_graph_loader.hpp index 110f24c661..b459e43025 100644 --- a/routing/index_graph_loader.hpp +++ b/routing/index_graph_loader.hpp @@ -36,4 +36,7 @@ public: }; void DeserializeIndexGraph(MwmValue const & mwmValue, VehicleType vehicleType, IndexGraph & graph); + +uint32_t DeserializeIndexGraphNumRoads(MwmValue const & mwmValue, VehicleType vehicleType); + } // namespace routing diff --git a/routing/index_graph_serialization.hpp b/routing/index_graph_serialization.hpp index b9abec9fed..9dec21b4d1 100644 --- a/routing/index_graph_serialization.hpp +++ b/routing/index_graph_serialization.hpp @@ -123,6 +123,27 @@ public: graph.Build(jointsFilter.GetCount()); } + template + static uint32_t DeserializeNumRoads(Source & src, VehicleMask requiredMask) { + Header header; + header.Deserialize(src); + + uint32_t numRoads = 0; + for (uint32_t i = 0; i < header.GetNumSections(); ++i) + { + Section const & section = header.GetSection(i); + VehicleMask const mask = section.GetMask(); + + if ((mask & requiredMask)) + { + numRoads += section.GetNumRoads(); + } + src.Skip(section.GetSize()); + } + + return numRoads; + } + private: static uint8_t constexpr kLastVersion = 0; static uint8_t constexpr kNewJointIdBit = 0;