diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2018-03-30 18:18:57 +0300 |
---|---|---|
committer | Tatiana Yan <tatiana.kondakova@gmail.com> | 2018-04-05 12:12:34 +0300 |
commit | 330257777ee0d827bbe5fb4c958fb70375099533 (patch) | |
tree | c7e4e4b07abbf48d041f216a9337f0b6b35bc794 /routing | |
parent | 4470291861a4e32a5fdb0262c63e1ca0a79f2aee (diff) |
Using fifo cache for road geometry in routing.
Diffstat (limited to 'routing')
-rw-r--r-- | routing/geometry.cpp | 19 | ||||
-rw-r--r-- | routing/geometry.hpp | 5 |
2 files changed, 14 insertions, 10 deletions
diff --git a/routing/geometry.cpp b/routing/geometry.cpp index 23a41ff4ca..0cb7d20809 100644 --- a/routing/geometry.cpp +++ b/routing/geometry.cpp @@ -15,6 +15,10 @@ using namespace std; namespace { +// @TODO(bykoianko) Consider setting cache size based on available memory. +// Maximum road geometry cache size in items. +size_t constexpr kRoadsCacheSize = 5000; + // GeometryLoaderImpl ------------------------------------------------------------------------------ class GeometryLoaderImpl final : public GeometryLoader { @@ -137,20 +141,21 @@ void RoadGeometry::Load(VehicleModelInterface const & vehicleModel, FeatureType } // Geometry ---------------------------------------------------------------------------------------- -Geometry::Geometry(unique_ptr<GeometryLoader> loader) : m_loader(move(loader)) +Geometry::Geometry(unique_ptr<GeometryLoader> loader) + : m_loader(move(loader)) + , m_featureIdToRoad(make_unique<FifoCache<uint32_t, RoadGeometry>>( + kRoadsCacheSize, + [this](uint32_t featureId, RoadGeometry & road) { m_loader->Load(featureId, road); })) { CHECK(m_loader, ()); } RoadGeometry const & Geometry::GetRoad(uint32_t featureId) { - auto const & it = m_roads.find(featureId); - if (it != m_roads.cend()) - return it->second; + ASSERT(m_featureIdToRoad, ()); + ASSERT(m_loader, ()); - RoadGeometry & road = m_roads[featureId]; - m_loader->Load(featureId, road); - return road; + return m_featureIdToRoad->GetValue(featureId); } // static diff --git a/routing/geometry.hpp b/routing/geometry.hpp index f49343677d..a88dd6d45c 100644 --- a/routing/geometry.hpp +++ b/routing/geometry.hpp @@ -11,11 +11,11 @@ #include "geometry/point2d.hpp" #include "base/buffer_vector.hpp" +#include "base/fifo_cache.hpp" #include <cstdint> #include <memory> #include <string> -#include <unordered_map> namespace routing { @@ -103,8 +103,7 @@ public: } private: - // Feature id to RoadGeometry map. - std::unordered_map<uint32_t, RoadGeometry> m_roads; std::unique_ptr<GeometryLoader> m_loader; + std::unique_ptr<FifoCache<uint32_t, RoadGeometry>> m_featureIdToRoad; }; } // namespace routing |