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 16:36:26 +0300
committerSergey Yershov <syershov@maps.me>2019-01-31 14:04:45 +0300
commite8bb1273d00944db35fb5e1130fe604a30ddf9c0 (patch)
tree509f163995c1d722b1b253fbe9bb0f1d56c14efc /indexer
parenta576f983e44496819acaa0cfdba2a6dcbf390610 (diff)
Fix for review
Diffstat (limited to 'indexer')
-rw-r--r--indexer/data_source.cpp6
-rw-r--r--indexer/indexer_tests/interval_index_test.cpp33
-rw-r--r--indexer/indexer_tests/locality_index_test.cpp2
-rw-r--r--indexer/indexer_tests/scale_index_reading_tests.cpp2
-rw-r--r--indexer/interval_index.hpp14
-rw-r--r--indexer/locality_index.hpp28
-rw-r--r--indexer/scale_index.hpp3
7 files changed, 38 insertions, 50 deletions
diff --git a/indexer/data_source.cpp b/indexer/data_source.cpp
index f393e7cbe5..dcfb77b827 100644
--- a/indexer/data_source.cpp
+++ b/indexer/data_source.cpp
@@ -55,10 +55,10 @@ public:
// iterate through intervals
for (auto const & i : intervals)
{
- index.ForEachInIntervalAndScale(i.first, i.second, scale, [&](uint32_t index) {
- if (!checkUnique(index))
+ index.ForEachInIntervalAndScale(i.first, i.second, scale, [&](uint64_t /* key */, uint32_t value) {
+ if (!checkUnique(value))
return;
- m_fn(index, *src);
+ m_fn(value, *src);
});
if (m_stop())
break;
diff --git a/indexer/indexer_tests/interval_index_test.cpp b/indexer/indexer_tests/interval_index_test.cpp
index 5df8e658c7..2b19519a15 100644
--- a/indexer/indexer_tests/interval_index_test.cpp
+++ b/indexer/indexer_tests/interval_index_test.cpp
@@ -28,6 +28,12 @@ struct CellIdFeaturePairForTest
uint64_t m_cell;
uint32_t m_value;
};
+
+auto indexValueInserter = [](auto & values)
+{
+ return [inserter = base::MakeBackInsertFunctor(values)] (uint64_t, auto value) { inserter(value); };
+};
+
}
UNIT_TEST(IntervalIndex_LevelCount)
@@ -133,7 +139,7 @@ UNIT_TEST(IntervalIndex_Serialized)
uint32_t expected [] = {0, 1, 2};
vector<uint32_t> values;
TEST_EQUAL(index.KeyEnd(), 0x10000, ());
- index.ForEach(base::MakeBackInsertFunctor(values), 0, 0x10000);
+ index.ForEach(indexValueInserter(values), 0, 0x10000);
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
@@ -152,41 +158,41 @@ UNIT_TEST(IntervalIndex_Simple)
{
uint32_t expected [] = {0, 1, 2};
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0ULL, index.KeyEnd());
+ index.ForEach(indexValueInserter(values), 0ULL, index.KeyEnd());
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
{
uint32_t expected [] = {0, 1};
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0xA0B1C2D100ULL, 0xA0B1C2D201ULL);
+ index.ForEach(indexValueInserter(values), 0xA0B1C2D100ULL, 0xA0B1C2D201ULL);
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
{
uint32_t expected [] = {0, 1};
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0x0ULL, 0xA0B1C30000ULL);
+ index.ForEach(indexValueInserter(values), 0x0ULL, 0xA0B1C30000ULL);
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
{
uint32_t expected [] = {0};
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0xA0B1C2D100ULL, 0xA0B1C2D101ULL);
+ index.ForEach(indexValueInserter(values), 0xA0B1C2D100ULL, 0xA0B1C2D101ULL);
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
{
uint32_t expected [] = {0};
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0xA0B1C2D100ULL, 0xA0B1C2D200ULL);
+ index.ForEach(indexValueInserter(values), 0xA0B1C2D100ULL, 0xA0B1C2D200ULL);
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
{
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0xA0B1C2D100ULL, 0xA0B1C2D100ULL);
+ index.ForEach(indexValueInserter(values), 0xA0B1C2D100ULL, 0xA0B1C2D100ULL);
TEST_EQUAL(values, vector<uint32_t>(), ());
}
{
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0xA0B1000000ULL, 0xA0B1B20000ULL);
+ index.ForEach(indexValueInserter(values), 0xA0B1000000ULL, 0xA0B1B20000ULL);
TEST_EQUAL(values, vector<uint32_t>(), ());
}
}
@@ -201,7 +207,7 @@ UNIT_TEST(IntervalIndex_Empty)
IntervalIndex<MemReader, uint32_t> index(reader);
{
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0ULL, 0xFFFFFFFFFFULL);
+ index.ForEach(indexValueInserter(values), 0ULL, 0xFFFFFFFFFFULL);
TEST_EQUAL(values, vector<uint32_t>(), ());
}
}
@@ -221,7 +227,7 @@ UNIT_TEST(IntervalIndex_Simple2)
{
uint32_t expected [] = {0, 1, 2, 3};
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0, 0xFFFFFFFFFFULL);
+ index.ForEach(indexValueInserter(values), 0, 0xFFFFFFFFFFULL);
sort(values.begin(), values.end());
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
@@ -240,7 +246,7 @@ UNIT_TEST(IntervalIndex_Simple3)
{
uint32_t expected [] = {0, 1};
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0, 0xFFFFULL);
+ index.ForEach(indexValueInserter(values), 0, 0xFFFFULL);
sort(values.begin(), values.end());
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
@@ -259,7 +265,7 @@ UNIT_TEST(IntervalIndex_Simple4)
{
uint32_t expected [] = {0, 1};
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0, 0xFFFFFFFFULL);
+ index.ForEach(indexValueInserter(values), 0, 0xFFFFFFFFULL);
sort(values.begin(), values.end());
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
@@ -280,9 +286,8 @@ UNIT_TEST(IntervalIndex_Simple5)
{
uint32_t expected [] = {0, 1, 2, 3};
vector<uint32_t> values;
- index.ForEach(base::MakeBackInsertFunctor(values), 0, 0xFFFFFFFFFFULL);
+ index.ForEach(indexValueInserter(values), 0, 0xFFFFFFFFFFULL);
sort(values.begin(), values.end());
TEST_EQUAL(values, vector<uint32_t>(expected, expected + ARRAY_SIZE(expected)), ());
}
}
-
diff --git a/indexer/indexer_tests/locality_index_test.cpp b/indexer/indexer_tests/locality_index_test.cpp
index c15b8a8eff..27a9e56c7e 100644
--- a/indexer/indexer_tests/locality_index_test.cpp
+++ b/indexer/indexer_tests/locality_index_test.cpp
@@ -64,7 +64,7 @@ RankedIds GetRankedIds(LocalityIndex const & index, m2::PointD const & center,
{
RankedIds ids;
index.ForClosestToPoint(
- [&ids](base::GeoObjectId const & id) { ids.push_back(id.GetEncodedId()); }, center,
+ [&ids](base::GeoObjectId const & id, auto) { ids.push_back(id.GetEncodedId()); }, center,
MercatorBounds::DistanceOnEarth(center, border), topSize);
return ids;
};
diff --git a/indexer/indexer_tests/scale_index_reading_tests.cpp b/indexer/indexer_tests/scale_index_reading_tests.cpp
index 6448411a8e..23a73ed3ea 100644
--- a/indexer/indexer_tests/scale_index_reading_tests.cpp
+++ b/indexer/indexer_tests/scale_index_reading_tests.cpp
@@ -51,7 +51,7 @@ public:
for (auto const & interval : covering.Get<RectId::DEPTH_LEVELS>(scale))
{
index.ForEachInIntervalAndScale(interval.first, interval.second, scale,
- [&](uint32_t index) { indices.push_back(index); });
+ [&](uint64_t /* key */, uint32_t value) { indices.push_back(value); });
}
FeaturesLoaderGuard loader(m_dataSource, id);
diff --git a/indexer/interval_index.hpp b/indexer/interval_index.hpp
index 5ed7f2b673..b046441da8 100644
--- a/indexer/interval_index.hpp
+++ b/indexer/interval_index.hpp
@@ -94,7 +94,7 @@ private:
break;
value += ReadVarInt<int64_t>(src);
if (key >= beg)
- Invoke(f, keyBase + key, value, 0 /* fake argument for invocation choice of |f| */);
+ f(keyBase + key, value);
}
}
@@ -170,18 +170,6 @@ private:
}
}
- template <typename F, typename = decltype(std::declval<F>()(uint64_t{0}, uint64_t{0}))>
- static void Invoke(F const & f, uint64_t key, Value storedId, int /* best candidate (overload) */)
- {
- f(key, storedId);
- }
-
- template <typename F>
- static void Invoke(F const & f, uint64_t key, Value storedId, ... /* default candidate (overload )*/)
- {
- f(storedId);
- }
-
ReaderT m_Reader;
Header m_Header;
buffer_vector<uint32_t, 7> m_LevelOffsets;
diff --git a/indexer/locality_index.hpp b/indexer/locality_index.hpp
index 4d0722001c..c58ce2c251 100644
--- a/indexer/locality_index.hpp
+++ b/indexer/locality_index.hpp
@@ -47,7 +47,7 @@ public:
for (auto const & i : intervals)
{
m_intervalIndex->ForEach(
- [&processObject](uint64_t storedId) {
+ [&processObject](uint64_t /* key */, uint64_t storedId) {
processObject(LocalityObject::FromStoredId(storedId));
},
i.first, i.second);
@@ -89,9 +89,9 @@ public:
auto const centralCellXY = centralCell.XY();
auto chebyshevDistance = [centralCellXY] (auto && cellXY) {
- auto abs = [](auto && a, auto && b) { return a > b ? a - b : b - a; };
- auto const distanceX = abs(centralCellXY.first, cellXY.first);
- auto const distanceY = abs(centralCellXY.second, cellXY.second);
+ auto absDiff = [](auto && a, auto && b) { return a > b ? a - b : b - a; };
+ auto const distanceX = absDiff(centralCellXY.first, cellXY.first);
+ auto const distanceY = absDiff(centralCellXY.second, cellXY.second);
return std::max(distanceX, distanceY);
};
@@ -101,34 +101,28 @@ public:
auto const cell = m2::CellId<DEPTH_LEVELS>::FromInt64(cellNumber, cellDepth);
auto const distance = chebyshevDistance(cell.XY());
- CHECK_GREATER(distance, 0, ());
+ CHECK_GREATER(distance, 1, ());
return 1.0 / distance;
};
- auto processAll = [&] (int64_t cellNumber, uint64_t storedId) {
+ auto insertObject = [&] (int64_t cellNumber, uint64_t storedId) {
auto const objectId = LocalityObject::FromStoredId(storedId).GetEncodedId();
auto & objectWeight = objectWeights[objectId];
objectWeight = max(objectWeight, cellRelativeWeight(cellNumber));
};
- auto process = [&](int64_t cellNumber, uint64_t storedId) {
+ auto insertObjectWithinSizeLimit = [&](int64_t cellNumber, uint64_t storedId) {
if (objectWeights.size() < sizeHint)
- processAll(cellNumber, storedId);
+ insertObject(cellNumber, storedId);
};
for (auto const & i : intervals)
{
if (bestCells.find(i.first) != bestCells.end())
- {
- m_intervalIndex->ForEach(processAll, i.first, i.second);
- }
- else
- {
- m_intervalIndex->ForEach(process, i.first, i.second);
- if (objectWeights.size() >= sizeHint)
- return;
- }
+ m_intervalIndex->ForEach(insertObject, i.first, i.second);
+ else if (objectWeights.size() < sizeHint)
+ m_intervalIndex->ForEach(insertObjectWithinSizeLimit, i.first, i.second);
}
std::vector<std::pair<uint64_t, double>> result(objectWeights.begin(), objectWeights.end());
diff --git a/indexer/scale_index.hpp b/indexer/scale_index.hpp
index b1ccd16eb9..e709646b36 100644
--- a/indexer/scale_index.hpp
+++ b/indexer/scale_index.hpp
@@ -52,7 +52,8 @@ public:
m_IndexForScale.push_back(factory.CreateIndex(treesReader.SubReader(i)));
}
- void ForEachInIntervalAndScale(uint64_t beg, uint64_t end, int scale, std::function<void(uint32_t)> const & fn) const
+ void ForEachInIntervalAndScale(uint64_t beg, uint64_t end, int scale,
+ std::function<void(uint64_t, uint32_t)> const & fn) const
{
auto const scaleBucket = BucketByScale(scale);
if (scaleBucket < m_IndexForScale.size())