[generator] Added popular places loader.

This commit is contained in:
Maksim Andrianov 2019-08-13 18:34:45 +03:00 committed by LaGrunge
parent 5e39f8a55c
commit 13bdbed7d7
3 changed files with 24 additions and 2 deletions

View file

@ -6,6 +6,8 @@
#include "indexer/classificator.hpp"
#include "indexer/scales.hpp"
#include <algorithm>
namespace generator
{
FilterWorld::FilterWorld(std::string const & popularityFilename)
@ -48,7 +50,7 @@ bool FilterWorld::IsPopularAttraction(feature::FeatureBuilder const & fb, std::s
return false;
auto static const attractionTypes = search::GetCategoryTypes("attractions", "en", GetDefaultCategories());
ASSERT(is_sorted(attractionTypes.begin(), attractionTypes.end()), ());
ASSERT(std::is_sorted(attractionTypes.begin(), attractionTypes.end()), ());
auto const & featureTypes = fb.GetTypes();
if (!std::any_of(featureTypes.begin(), featureTypes.end(), [](uint32_t t) {
return std::binary_search(attractionTypes.begin(), attractionTypes.end(), t);
@ -57,7 +59,7 @@ bool FilterWorld::IsPopularAttraction(feature::FeatureBuilder const & fb, std::s
return false;
}
auto static const & m_popularPlaces = PopularPlacesLoader::GetOrLoad(popularityFilename);
auto static const & m_popularPlaces = GetOrLoadPopularPlacesLoader(popularityFilename);
auto const it = m_popularPlaces.find(fb.GetMostGenericOsmId());
if (it == m_popularPlaces.end())
return false;

View file

@ -109,4 +109,21 @@ bool BuildPopularPlacesMwmSection(std::string const & srcFilename, std::string c
search::RankTableBuilder::Create(content, cont, POPULARITY_RANKS_FILE_TAG);
return true;
}
PopularPlaces const & GetOrLoadPopularPlacesLoader(std::string const & filename)
{
static std::mutex m;
static std::unordered_map<std::string, PopularPlaces> plases;
std::lock_guard<std::mutex> lock(m);
auto const it = plases.find(filename);
if (it != plases.cend())
return it->second;
PopularPlaces places;
LoadPopularPlaces(filename, places);
auto const eIt = plases.emplace(filename, places);
return eIt.first->second;
}
} // namespace generator

View file

@ -3,6 +3,7 @@
#include "base/geo_object_id.hpp"
#include <string>
#include <mutex>
#include <unordered_map>
namespace generator
@ -14,4 +15,6 @@ void LoadPopularPlaces(std::string const & srcFilename, PopularPlaces & places);
bool BuildPopularPlacesMwmSection(std::string const & srcFilename, std::string const & mwmFile,
std::string const & osmToFeatureFilename);
PopularPlaces const & GetOrLoadPopularPlacesLoader(std::string const & filename);
} // namespace generator