Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2019-01-10 19:33:58 +0300
committerTatiana Yan <tatiana.kondakova@gmail.com>2019-01-17 17:30:50 +0300
commit5028dbb86da59e9edd08849c4974f9b516c9fbc7 (patch)
tree3cc7144637346e710124315011dab6b732dd669d /geocoder
parent5bc28544212d997c0045e68c64edc4314124a8d8 (diff)
Review fixes.
Diffstat (limited to 'geocoder')
-rw-r--r--geocoder/geocoder.cpp2
-rw-r--r--geocoder/hierarchy.cpp20
-rw-r--r--geocoder/hierarchy.hpp6
-rw-r--r--geocoder/index.cpp11
-rw-r--r--geocoder/index.hpp10
5 files changed, 25 insertions, 24 deletions
diff --git a/geocoder/geocoder.cpp b/geocoder/geocoder.cpp
index 3ef10c88b0..9442cf99f8 100644
--- a/geocoder/geocoder.cpp
+++ b/geocoder/geocoder.cpp
@@ -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;
diff --git a/geocoder/hierarchy.cpp b/geocoder/hierarchy.cpp
index 8579ad3ff2..43e334b0bf 100644
--- a/geocoder/hierarchy.cpp
+++ b/geocoder/hierarchy.cpp
@@ -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
diff --git a/geocoder/hierarchy.hpp b/geocoder/hierarchy.hpp
index 952ab6bbc0..bae7d2fc38 100644
--- a/geocoder/hierarchy.hpp
+++ b/geocoder/hierarchy.hpp
@@ -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;
};
diff --git a/geocoder/index.cpp b/geocoder/index.cpp
index eed857fe3b..86e89ea0c7 100644
--- a/geocoder/index.cpp
+++ b/geocoder/index.cpp
@@ -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);
diff --git a/geocoder/index.hpp b/geocoder/index.hpp
index bc9b283c3f..8a56fb4271 100644
--- a/geocoder/index.hpp
+++ b/geocoder/index.hpp
@@ -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;