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:
authorAnatoly Serdtcev <serdtcev@maps.me>2019-01-22 19:15:37 +0300
committerAnatoly Serdtcev <serdtcev@maps.me>2019-01-31 14:15:44 +0300
commit3842ba3aacb979b924d063b397a19535cd3dc762 (patch)
treed61a3b543fa8cd4e64819ea4135e41de4b049238 /geocoder
parentcf799c1ea7c7e142db86d0427471344f2ab72a2d (diff)
Fix for review
Diffstat (limited to 'geocoder')
-rw-r--r--geocoder/geocoder.cpp4
-rw-r--r--geocoder/geocoder.hpp2
-rw-r--r--geocoder/geocoder_tests/geocoder_tests.cpp29
-rw-r--r--geocoder/hierarchy.cpp4
-rw-r--r--geocoder/hierarchy.hpp2
-rw-r--r--geocoder/hierarchy_reader.cpp8
-rw-r--r--geocoder/hierarchy_reader.hpp4
7 files changed, 40 insertions, 13 deletions
diff --git a/geocoder/geocoder.cpp b/geocoder/geocoder.cpp
index 2489ef083a..050ec420f1 100644
--- a/geocoder/geocoder.cpp
+++ b/geocoder/geocoder.cpp
@@ -193,8 +193,8 @@ vector<Geocoder::Layer> & Geocoder::Context::GetLayers() { return m_layers; }
vector<Geocoder::Layer> const & Geocoder::Context::GetLayers() const { return m_layers; }
// Geocoder ----------------------------------------------------------------------------------------
-Geocoder::Geocoder(string const & pathToJsonHierarchy, size_t readerCount)
- : m_hierarchy(pathToJsonHierarchy, readerCount), m_index(m_hierarchy)
+Geocoder::Geocoder(string const & pathToJsonHierarchy, size_t hierarchyReadersCount)
+ : m_hierarchy(pathToJsonHierarchy, hierarchyReadersCount), m_index(m_hierarchy)
{
}
diff --git a/geocoder/geocoder.hpp b/geocoder/geocoder.hpp
index 513d5c7df3..22c1452c7d 100644
--- a/geocoder/geocoder.hpp
+++ b/geocoder/geocoder.hpp
@@ -118,7 +118,7 @@ public:
std::vector<Layer> m_layers;
};
- explicit Geocoder(std::string const & pathToJsonHierarchy, std::size_t readerCount = 4);
+ explicit Geocoder(std::string const & pathToJsonHierarchy, std::size_t hierarchyReadersCount = 4);
void ProcessQuery(std::string const & query, std::vector<Result> & results) const;
diff --git a/geocoder/geocoder_tests/geocoder_tests.cpp b/geocoder/geocoder_tests/geocoder_tests.cpp
index 58c951e9fa..08d64bc6e7 100644
--- a/geocoder/geocoder_tests/geocoder_tests.cpp
+++ b/geocoder/geocoder_tests/geocoder_tests.cpp
@@ -54,6 +54,35 @@ void TestGeocoder(Geocoder & geocoder, string const & query, vector<Result> && e
}
}
+UNIT_TEST(Geocoder_EmptyFileConcurrentRead)
+{
+ ScopedFile const regionsJsonFile("regions.jsonl", "");
+ Geocoder geocoder(regionsJsonFile.GetFullPath(), 8 /* reader threads */);
+
+ TEST_EQUAL(geocoder.GetHierarchy().GetEntries().size(), 0, ());
+}
+
+UNIT_TEST(Geocoder_BigFileConcurrentRead)
+{
+ int const kEntryCount = 1000000;
+
+ stringstream s;
+ for (int i = 0; i < kEntryCount; ++i)
+ {
+ s << i << " "
+ << "{"
+ << R"("type": "Feature",)"
+ << R"("geometry": {"type": "Point", "coordinates": [0, 0]},)"
+ << R"("properties": {"name": ")" << i << R"(", "rank": 2, "address": {"country": ")" << i << R"("}})"
+ << "}\n";
+ }
+
+ ScopedFile const regionsJsonFile("regions.jsonl", s.str());
+ Geocoder geocoder(regionsJsonFile.GetFullPath(), 8 /* reader threads */);
+
+ TEST_EQUAL(geocoder.GetHierarchy().GetEntries().size(), kEntryCount, ());
+}
+
UNIT_TEST(Geocoder_Smoke)
{
ScopedFile const regionsJsonFile("regions.jsonl", kRegionsData);
diff --git a/geocoder/hierarchy.cpp b/geocoder/hierarchy.cpp
index 5c82e3b7bd..5058b3aaf6 100644
--- a/geocoder/hierarchy.cpp
+++ b/geocoder/hierarchy.cpp
@@ -136,12 +136,12 @@ bool Hierarchy::Entry::IsParentTo(Hierarchy::Entry const & e) const
}
// Hierarchy ---------------------------------------------------------------------------------------
-Hierarchy::Hierarchy(string const & pathToJsonHierarchy, size_t readerCount)
+Hierarchy::Hierarchy(string const & pathToJsonHierarchy, size_t readersCount)
{
ParsingStats stats;
HierarchyReader reader{pathToJsonHierarchy};
- m_entries = reader.ReadEntries(readerCount, stats);
+ m_entries = reader.ReadEntries(readersCount, stats);
CheckDuplicateOsmIds(m_entries, stats);
diff --git a/geocoder/hierarchy.hpp b/geocoder/hierarchy.hpp
index 88e04e21ff..fc78b9997c 100644
--- a/geocoder/hierarchy.hpp
+++ b/geocoder/hierarchy.hpp
@@ -76,7 +76,7 @@ public:
std::array<Tokens, static_cast<size_t>(Type::Count) + 1> m_address;
};
- explicit Hierarchy(std::string const & pathToJsonHierarchy, std::size_t readerCount = 4);
+ explicit Hierarchy(std::string const & pathToJsonHierarchy, std::size_t readersCount = 4);
std::vector<Entry> const & GetEntries() const;
diff --git a/geocoder/hierarchy_reader.cpp b/geocoder/hierarchy_reader.cpp
index 7d15645d85..c306e93ca6 100644
--- a/geocoder/hierarchy_reader.cpp
+++ b/geocoder/hierarchy_reader.cpp
@@ -21,8 +21,7 @@ HierarchyReader::HierarchyReader(string const & pathToJsonHierarchy) :
MYTHROW(OpenException, ("Failed to open file", pathToJsonHierarchy));
}
-auto HierarchyReader::ReadEntries(size_t readerCount, ParsingStats & stats)
- -> vector<Entry>
+vector<Hierarchy::Entry> HierarchyReader::ReadEntries(size_t readerCount, ParsingStats & stats)
{
LOG(LINFO, ("Reading entries..."));
@@ -41,7 +40,7 @@ auto HierarchyReader::ReadEntries(size_t readerCount, ParsingStats & stats)
return UnionEntries(taskEntries);
}
-auto HierarchyReader::UnionEntries(vector<multimap<base::GeoObjectId, Entry>> & entryParts) -> vector<Entry>
+vector<Hierarchy::Entry> HierarchyReader::UnionEntries(vector<multimap<base::GeoObjectId, Entry>> & entryParts)
{
auto entries = vector<Entry>{};
@@ -59,7 +58,7 @@ auto HierarchyReader::UnionEntries(vector<multimap<base::GeoObjectId, Entry>> &
if (minPart->size())
{
- entries.emplace_back(std::move(minPart->begin()->second));
+ entries.emplace_back(move(minPart->begin()->second));
minPart->erase(minPart->begin());
}
@@ -118,5 +117,4 @@ void HierarchyReader::ReadEntryMap(multimap<base::GeoObjectId, Entry> & entries,
entries = move(localEntries);
}
-
} // namespace geocoder
diff --git a/geocoder/hierarchy_reader.hpp b/geocoder/hierarchy_reader.hpp
index db460bbf4f..d964ac7f2a 100644
--- a/geocoder/hierarchy_reader.hpp
+++ b/geocoder/hierarchy_reader.hpp
@@ -21,11 +21,11 @@ public:
HierarchyReader(std::string const & pathToJsonHierarchy);
- auto ReadEntries(size_t readerCount, ParsingStats & stats) -> std::vector<Entry>;
+ std::vector<Entry> ReadEntries(size_t readerCount, ParsingStats & stats);
private:
void ReadEntryMap(std::multimap<base::GeoObjectId, Entry> & entries, ParsingStats & stats);
- auto UnionEntries(std::vector<std::multimap<base::GeoObjectId, Entry>> & entryParts) -> std::vector<Entry>;
+ std::vector<Entry> UnionEntries(std::vector<std::multimap<base::GeoObjectId, Entry>> & entryParts);
std::ifstream m_fileStm;
std::mutex m_mutex;