Review fixes.

This commit is contained in:
Maxim Pimenov 2019-01-10 19:33:58 +03:00 committed by Tatiana Yan
parent 5bc2854421
commit 5028dbb86d
5 changed files with 25 additions and 24 deletions

View file

@ -337,7 +337,7 @@ bool Geocoder::HasParent(vector<Geocoder::Layer> const & layers, Hierarchy::Entr
// Note that the relationship is somewhat inverted: every ancestor
// is stored in the address but the nodes have no information
// about their children.
if (m_hierarchy.IsParent(m_index.GetDoc(docId), e))
if (m_index.GetDoc(docId).IsParentTo(e))
return true;
}
return false;

View file

@ -127,6 +127,16 @@ bool Hierarchy::Entry::DeserializeFromJSONImpl(json_t * const root, string const
return true;
}
bool Hierarchy::Entry::IsParentTo(Hierarchy::Entry const & e) const
{
for (size_t i = 0; i < static_cast<size_t>(geocoder::Type::Count); ++i)
{
if (!m_address[i].empty() && m_address[i] != e.m_address[i])
return false;
}
return true;
}
// Hierarchy ---------------------------------------------------------------------------------------
Hierarchy::Hierarchy(string const & pathToJsonHierarchy)
{
@ -206,14 +216,4 @@ Hierarchy::Entry const * Hierarchy::GetEntryForOsmId(base::GeoObjectId const & o
return &(*it);
}
bool Hierarchy::IsParent(Hierarchy::Entry const & pe, Hierarchy::Entry const & e) const
{
for (size_t i = 0; i < static_cast<size_t>(geocoder::Type::Count); ++i)
{
if (!pe.m_address[i].empty() && pe.m_address[i] != e.m_address[i])
return false;
}
return true;
}
} // namespace geocoder

View file

@ -57,6 +57,9 @@ public:
bool DeserializeFromJSONImpl(json_t * const root, std::string const & jsonStr,
ParsingStats & stats);
// Checks whether this entry is a parent of |e|.
bool IsParentTo(Entry const & e) const;
bool operator<(Entry const & rhs) const { return m_osmId < rhs.m_osmId; }
base::GeoObjectId m_osmId = base::GeoObjectId(base::GeoObjectId::kInvalid);
@ -78,9 +81,6 @@ public:
Entry const * GetEntryForOsmId(base::GeoObjectId const & osmId) const;
// Checks whether |pe| is a parent of |e|.
bool IsParent(Entry const & pe, Entry const & e) const;
private:
std::vector<Entry> m_entries;
};

View file

@ -25,7 +25,7 @@ Index::Index(Hierarchy const & hierarchy) : m_docs(hierarchy.GetEntries())
LOG(LINFO, ("Indexing hierarchy entries..."));
AddEntries();
LOG(LINFO, ("Indexing houses..."));
AddHouses(hierarchy);
AddHouses();
}
Index::Doc const & Index::GetDoc(DocId const id) const
@ -34,7 +34,8 @@ Index::Doc const & Index::GetDoc(DocId const id) const
return m_docs[static_cast<size_t>(id)];
}
string Index::MakeIndexKey(Tokens const & tokens) const
// static
string Index::MakeIndexKey(Tokens const & tokens)
{
return strings::JoinStrings(tokens, " ");
}
@ -85,10 +86,10 @@ void Index::AddStreet(DocId const & docId, Index::Doc const & doc)
}
}
void Index::AddHouses(Hierarchy const & hierarchy)
void Index::AddHouses()
{
size_t numIndexed = 0;
for (DocId docId = 0; docId < static_cast<DocId>(hierarchy.GetEntries().size()); ++docId)
for (DocId docId = 0; docId < static_cast<DocId>(m_docs.size()); ++docId)
{
auto const & buildingDoc = GetDoc(docId);
@ -99,7 +100,7 @@ void Index::AddHouses(Hierarchy const & hierarchy)
ForEachDocId(buildingDoc.m_address[t], [&](DocId const & streetCandidate) {
auto const & streetDoc = GetDoc(streetCandidate);
if (hierarchy.IsParent(streetDoc, buildingDoc))
if (streetDoc.IsParentTo(buildingDoc))
{
m_buildingsOnStreet[streetCandidate].emplace_back(docId);

View file

@ -14,11 +14,11 @@ namespace geocoder
class Index
{
public:
using Doc = Hierarchy::Entry;
// Number of the entry in the list of all hierarchy entries
// that the index was constructed from.
using DocId = uint32_t;
using Doc = Hierarchy::Entry;
using DocId = std::vector<Doc>::size_type;
explicit Index(Hierarchy const & hierarchy);
@ -56,7 +56,7 @@ public:
private:
// Converts |tokens| to a single UTF-8 string that can be used
// as a key in the |m_docIdsByTokens| map.
std::string MakeIndexKey(Tokens const & tokens) const;
static std::string MakeIndexKey(Tokens const & tokens);
// Adds address information of |m_docs| to the index.
void AddEntries();
@ -66,7 +66,7 @@ private:
void AddStreet(DocId const & docId, Doc const & e);
// Fills the |m_buildingsOnStreet| field.
void AddHouses(Hierarchy const & hierarchy);
void AddHouses();
std::vector<Doc> const & m_docs;