[new downloader] CountryInfoGetter. Getting limit rect by TCountryId efficiently.

This commit is contained in:
Vladimir Byko-Ianko 2016-02-09 08:13:45 +03:00 committed by Sergey Yershov
parent df54d6c55d
commit df5259cc8c
2 changed files with 22 additions and 0 deletions

View file

@ -102,6 +102,14 @@ m2::RectD CountryInfoGetter::CalcLimitRect(string const & prefix) const
return rect;
}
m2::RectD CountryInfoGetter::CalcLimitRectForLeaf(TCountryId leafCountryId) const
{
auto const index = this->m_countryIndex.find(leafCountryId);
ASSERT(index != this->m_countryIndex.end(), ());
ASSERT_LESS(index->second, this->m_countries.size(), ());
return m_countries[index->second].m_rect;
}
void CountryInfoGetter::GetMatchedRegions(string const & enNamePrefix, IdSet & regions) const
{
for (size_t i = 0; i < m_countries.size(); ++i)
@ -167,6 +175,11 @@ CountryInfoReader::CountryInfoReader(ModelReaderPtr polyR, ModelReaderPtr countr
ReaderSource<ModelReaderPtr> src(m_reader.GetReader(PACKED_POLYGONS_INFO_TAG));
rw::Read(src, m_countries);
size_t const countrySz = m_countries.size();
m_countryIndex.reserve(countrySz);
for (size_t i = 0; i < countrySz; ++i)
m_countryIndex[m_countries[i].m_name] = i;
string buffer;
countryR.ReadAsString(buffer);
LoadCountryFile2CountryInfo(buffer, m_id2info, m_isSingleMwm);

View file

@ -9,6 +9,7 @@
#include "base/cache.hpp"
#include "std/mutex.hpp"
#include "std/unordered_map.hpp"
namespace storage
{
@ -52,6 +53,10 @@ public:
// Calculates limit rect for all countries whose name starts with
// |prefix|.
m2::RectD CalcLimitRect(string const & prefix) const;
// Calculates limit rect for |countryId| (non-expandable node).
// Returns bound box in mercator coordinates if |countryId| is a country id of non-expandable node
// and zero rect otherwise.
m2::RectD CalcLimitRectForLeaf(TCountryId leafCountryId) const;
// Returns identifiers for all regions matching to |enNamePrefix|.
void GetMatchedRegions(string const & enNamePrefix, IdSet & regions) const;
@ -83,8 +88,12 @@ protected:
// Returns true when |pt| belongs to a country identified by |id|.
virtual bool IsBelongToRegionImpl(size_t id, m2::PointD const & pt) const = 0;
// @TODO(bykoianko) Probably it's possible to redesign the class to get rid of m_countryIndex.
// The possibility should be considered.
// List of all known countries.
vector<CountryDef> m_countries;
// Maps all leaf country id (file names) to their index in m_countries.
unordered_map<TCountryId, IdType> m_countryIndex;
// Maps country file name without an extension to a country info.
map<string, CountryInfo> m_id2info;