diff options
author | VladiMihaylenko <vxmihaylenko@gmail.com> | 2019-05-15 17:57:21 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <bykoianko@gmail.com> | 2019-05-17 16:45:03 +0300 |
commit | 9171567414303416e3d2801711b8fd1e4e268565 (patch) | |
tree | 96550a8b510499dce5a8a39e8bd8c7f1b2d6f555 /routing | |
parent | 448e9fb4c6ab5beb7125db29a7ec5b9bfcc73503 (diff) |
[routing] Fixed duplicate names in absent list.
Diffstat (limited to 'routing')
-rw-r--r-- | routing/async_router.cpp | 6 | ||||
-rw-r--r-- | routing/async_router.hpp | 3 | ||||
-rw-r--r-- | routing/online_absent_fetcher.cpp | 5 | ||||
-rw-r--r-- | routing/online_absent_fetcher.hpp | 6 | ||||
-rw-r--r-- | routing/routing_callbacks.hpp | 4 | ||||
-rw-r--r-- | routing/routing_integration_tests/routing_test_tools.cpp | 3 | ||||
-rw-r--r-- | routing/routing_tests/async_router_test.cpp | 21 | ||||
-rw-r--r-- | routing/routing_tests/online_cross_fetcher_test.cpp | 3 |
8 files changed, 26 insertions, 25 deletions
diff --git a/routing/async_router.cpp b/routing/async_router.cpp index 75b7fe29df..75038486aa 100644 --- a/routing/async_router.cpp +++ b/routing/async_router.cpp @@ -99,7 +99,7 @@ void AsyncRouter::RouterDelegateProxy::OnReady(shared_ptr<Route> route, RouterRe } void AsyncRouter::RouterDelegateProxy::OnNeedMoreMaps(uint64_t routeId, - vector<string> const & absentCounties) + set<string> const & absentCounties) { if (!m_onNeedMoreMaps) return; @@ -425,11 +425,11 @@ void AsyncRouter::CalculateRoute() bool const needFetchAbsent = (code != RouterResultCode::Cancelled); // Check online response if we have. - vector<string> absent; + set<string> absent; if (absentFetcher && needFetchAbsent) absentFetcher->GetAbsentCountries(absent); - absent.insert(absent.end(), route->GetAbsentCountries().cbegin(), route->GetAbsentCountries().cend()); + absent.insert(route->GetAbsentCountries().cbegin(), route->GetAbsentCountries().cend()); if (!absent.empty()) code = RouterResultCode::NeedMoreMaps; diff --git a/routing/async_router.hpp b/routing/async_router.hpp index 0ea19d7671..797374f267 100644 --- a/routing/async_router.hpp +++ b/routing/async_router.hpp @@ -16,6 +16,7 @@ #include <map> #include <memory> #include <mutex> +#include <set> #include <string> #include <utility> @@ -78,7 +79,7 @@ private: uint32_t timeoutSec); void OnReady(std::shared_ptr<Route> route, RouterResultCode resultCode); - void OnNeedMoreMaps(uint64_t routeId, vector<std::string> const & absentCounties); + void OnNeedMoreMaps(uint64_t routeId, std::set<std::string> const & absentCounties); void OnRemoveRoute(RouterResultCode resultCode); void Cancel(); diff --git a/routing/online_absent_fetcher.cpp b/routing/online_absent_fetcher.cpp index 1e00476b82..5d66ec6599 100644 --- a/routing/online_absent_fetcher.cpp +++ b/routing/online_absent_fetcher.cpp @@ -41,7 +41,7 @@ void OnlineAbsentCountriesFetcher::GenerateRequest(Checkpoints const & checkpoin m_fetcherThread->Create(move(fetcher)); } -void OnlineAbsentCountriesFetcher::GetAbsentCountries(vector<string> & countries) +void OnlineAbsentCountriesFetcher::GetAbsentCountries(set<string> & countries) { countries.clear(); // Check whether a request was scheduled to be run on the thread. @@ -56,11 +56,10 @@ void OnlineAbsentCountriesFetcher::GetAbsentCountries(vector<string> & countries if (name.empty() || m_countryLocalFileFn(name)) continue; - countries.emplace_back(move(name)); + countries.emplace(move(name)); } m_fetcherThread.reset(); - base::SortUnique(countries); } bool OnlineAbsentCountriesFetcher::AllPointsInSameMwm(Checkpoints const & checkpoints) const diff --git a/routing/online_absent_fetcher.hpp b/routing/online_absent_fetcher.hpp index 6ddfd8ce71..fc470c6e27 100644 --- a/routing/online_absent_fetcher.hpp +++ b/routing/online_absent_fetcher.hpp @@ -9,8 +9,8 @@ #include <functional> #include <memory> +#include <set> #include <string> -#include <vector> namespace routing { @@ -21,7 +21,7 @@ class IOnlineFetcher public: virtual ~IOnlineFetcher() = default; virtual void GenerateRequest(Checkpoints const &) = 0; - virtual void GetAbsentCountries(std::vector<std::string> & countries) = 0; + virtual void GetAbsentCountries(std::set<std::string> & countries) = 0; }; /*! @@ -35,7 +35,7 @@ public: // IOnlineFetcher overrides: void GenerateRequest(Checkpoints const &) override; - void GetAbsentCountries(std::vector<std::string> & countries) override; + void GetAbsentCountries(std::set<std::string> & countries) override; private: bool AllPointsInSameMwm(Checkpoints const &) const; diff --git a/routing/routing_callbacks.hpp b/routing/routing_callbacks.hpp index 64587f8708..6c8d6d5a72 100644 --- a/routing/routing_callbacks.hpp +++ b/routing/routing_callbacks.hpp @@ -8,8 +8,8 @@ #include <functional> #include <map> #include <memory> +#include <set> #include <string> -#include <vector> namespace routing { @@ -69,7 +69,7 @@ enum class SessionState */ using CheckpointCallback = std::function<void(size_t passedCheckpointIdx)>; -using NeedMoreMapsCallback = std::function<void(uint64_t, std::vector<std::string> const &)>; +using NeedMoreMapsCallback = std::function<void(uint64_t, std::set<std::string> const &)>; using PointCheckCallback = std::function<void(m2::PointD const &)>; using ProgressCallback = std::function<void(float)>; using ReadyCallback = std::function<void(Route const &, RouterResultCode)>; diff --git a/routing/routing_integration_tests/routing_test_tools.cpp b/routing/routing_integration_tests/routing_test_tools.cpp index 4e00fe34a5..c7e72ec215 100644 --- a/routing/routing_integration_tests/routing_test_tools.cpp +++ b/routing/routing_integration_tests/routing_test_tools.cpp @@ -35,6 +35,7 @@ #include <limits> #include <map> #include <memory> +#include <set> #include <sys/resource.h> #include <tuple> @@ -317,7 +318,7 @@ void TestOnlineFetcher(ms::LatLon const & startPoint, ms::LatLon const & finalPo routing::OnlineAbsentCountriesFetcher fetcher(countryFileGetter, localFileChecker); fetcher.GenerateRequest(Checkpoints(MercatorBounds::FromLatLon(startPoint), MercatorBounds::FromLatLon(finalPoint))); - vector<string> absent; + set<string> absent; fetcher.GetAbsentCountries(absent); if (expected.size() < 2) { diff --git a/routing/routing_tests/async_router_test.cpp b/routing/routing_tests/async_router_test.cpp index f6d78fee9c..a680258694 100644 --- a/routing/routing_tests/async_router_test.cpp +++ b/routing/routing_tests/async_router_test.cpp @@ -29,10 +29,10 @@ namespace class DummyRouter : public IRouter { RouterResultCode m_result; - vector<string> m_absent; + set<string> m_absent; public: - DummyRouter(RouterResultCode code, vector<string> const & absent) : m_result(code), m_absent(absent) {} + DummyRouter(RouterResultCode code, set<string> const & absent) : m_result(code), m_absent(absent) {} // IRouter overrides: string GetName() const override { return "Dummy"; } @@ -52,14 +52,14 @@ public: class DummyFetcher : public IOnlineFetcher { - vector<string> m_absent; + set<string> m_absent; public: - explicit DummyFetcher(vector<string> const & absent) : m_absent(absent) {} + explicit DummyFetcher(set<string> const & absent) : m_absent(absent) {} // IOnlineFetcher overrides: void GenerateRequest(Checkpoints const &) override {} - void GetAbsentCountries(vector<string> & countries) override { countries = m_absent; } + void GetAbsentCountries(set<string> & countries) override { countries = m_absent; } }; void DummyStatisticsCallback(map<string, string> const &) {} @@ -67,7 +67,7 @@ void DummyStatisticsCallback(map<string, string> const &) {} struct DummyRoutingCallbacks { vector<RouterResultCode> m_codes; - vector<vector<string>> m_absent; + vector<set<string>> m_absent; condition_variable m_cv; mutex m_lock; uint32_t const m_expected; @@ -80,16 +80,15 @@ struct DummyRoutingCallbacks { CHECK(route, ()); m_codes.push_back(code); - auto const & absent = route->GetAbsentCountries(); - m_absent.emplace_back(absent.begin(), absent.end()); + m_absent.emplace_back(route->GetAbsentCountries()); TestAndNotifyReadyCallbacks(); } // NeedMoreMapsCallback callback - void operator()(uint64_t routeId, vector<string> const & absent) + void operator()(uint64_t routeId, set<string> const & absent) { m_codes.push_back(RouterResultCode::NeedMoreMaps); - m_absent.emplace_back(absent.begin(), absent.end()); + m_absent.emplace_back(absent); TestAndNotifyReadyCallbacks(); } @@ -113,7 +112,7 @@ struct DummyRoutingCallbacks UNIT_CLASS_TEST(AsyncGuiThreadTest, NeedMoreMapsSignalTest) { - vector<string> const absentData({"test1", "test2"}); + set<string> const absentData({"test1", "test2"}); unique_ptr<IOnlineFetcher> fetcher(new DummyFetcher(absentData)); unique_ptr<IRouter> router(new DummyRouter(RouterResultCode::NoError, {})); DummyRoutingCallbacks resultCallback(2 /* expectedCalls */); diff --git a/routing/routing_tests/online_cross_fetcher_test.cpp b/routing/routing_tests/online_cross_fetcher_test.cpp index 64f7740740..50a033b980 100644 --- a/routing/routing_tests/online_cross_fetcher_test.cpp +++ b/routing/routing_tests/online_cross_fetcher_test.cpp @@ -6,6 +6,7 @@ #include "geometry/point2d.hpp" #include <algorithm> +#include <set> #include <string> #include <vector> @@ -54,7 +55,7 @@ UNIT_TEST(OnlineAbsentFetcherSingleMwmTest) { OnlineAbsentCountriesFetcher fetcher([](m2::PointD const & p){return "A";}, [](string const &){return false;}); fetcher.GenerateRequest(Checkpoints({1, 1}, {2, 2})); - vector<string> countries; + set<string> countries; fetcher.GetAbsentCountries(countries); TEST(countries.empty(), ()); } |