From 518db38b381f80fdc7d6aff454b12141b8e7f5f7 Mon Sep 17 00:00:00 2001 From: Denis Koronchik Date: Wed, 1 Oct 2014 19:18:50 +0300 Subject: [PATCH] [core] Fixed bug with scale index processing - duplicating functor was copied. --- indexer/index.hpp | 82 ++++++++++++++++---------------------- indexer/scale_index.hpp | 5 ++- search/locality_finder.cpp | 14 +++---- search/locality_finder.hpp | 1 - search/search_query.cpp | 5 +-- 5 files changed, 46 insertions(+), 61 deletions(-) diff --git a/indexer/index.hpp b/indexer/index.hpp index 0a8ae9e74e..569737c202 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -64,43 +64,38 @@ public: private: - template - class ReadFeatureFunctor - { - FeaturesVector const & m_V; - F & m_F; - unordered_set m_offsets; - MwmId m_mwmID; - - public: - ReadFeatureFunctor(FeaturesVector const & v, F & f, MwmId mwmID) - : m_V(v), m_F(f), m_mwmID(mwmID) - { - } - - void operator() (uint32_t offset) - { - if (m_offsets.insert(offset).second) - { - FeatureType feature; - - m_V.Get(offset, feature); - feature.SetID(FeatureID(m_mwmID, offset)); - - m_F(feature); - } - } - }; - - /// old style mwm reading template class ReadMWMFunctor { - public: - ReadMWMFunctor(F & f) - : m_f(f) + class ImplFunctor : private noncopyable { - } + FeaturesVector const & m_V; + F & m_F; + unordered_set m_offsets; + MwmId m_mwmID; + + public: + ImplFunctor(FeaturesVector const & v, F & f, MwmId mwmID) + : m_V(v), m_F(f), m_mwmID(mwmID) + { + } + + void operator() (uint32_t offset) + { + if (m_offsets.insert(offset).second) + { + FeatureType feature; + + m_V.Get(offset, feature); + feature.SetID(FeatureID(m_mwmID, offset)); + + m_F(feature); + } + } + }; + + public: + ReadMWMFunctor(F & f) : m_f(f) {} void operator() (MwmLock const & lock, covering::CoveringGetter & cov, uint32_t scale) const { @@ -124,9 +119,9 @@ private: pValue->m_factory); // iterate through intervals - ReadFeatureFunctor f1(fv, m_f, lock.GetID()); + ImplFunctor implF(fv, m_f, lock.GetID()); for (size_t i = 0; i < interval.size(); ++i) - index.ForEachInIntervalAndScale(f1, interval[i].first, interval[i].second, scale); + index.ForEachInIntervalAndScale(implF, interval[i].first, interval[i].second, scale); } } @@ -137,14 +132,10 @@ private: template class ReadFeatureIndexFunctor { - struct ImplFunctor + struct ImplFunctor : private noncopyable { public: - ImplFunctor(F & f, MwmId id) - : m_f(f) - , m_id(id) - { - } + ImplFunctor(F & f, MwmId id) : m_f(f), m_id(id) {} void operator() (uint32_t offset) { @@ -160,10 +151,7 @@ private: }; public: - ReadFeatureIndexFunctor(F & f) - : m_f(f) - { - } + ReadFeatureIndexFunctor(F & f) : m_f(f) {} void operator() (MwmLock const & lock, covering::CoveringGetter & cov, uint32_t scale) const { @@ -184,9 +172,9 @@ private: pValue->m_factory); // iterate through intervals - ImplFunctor implFunctor(m_f, lock.GetID()); + ImplFunctor implF(m_f, lock.GetID()); for (size_t i = 0; i < interval.size(); ++i) - index.ForEachInIntervalAndScale(implFunctor, interval[i].first, interval[i].second, scale); + index.ForEachInIntervalAndScale(implF, interval[i].first, interval[i].second, scale); } } diff --git a/indexer/scale_index.hpp b/indexer/scale_index.hpp index ca9286e632..5bcce41d1c 100644 --- a/indexer/scale_index.hpp +++ b/indexer/scale_index.hpp @@ -11,6 +11,7 @@ #include "../base/stl_add.hpp" #include "../std/algorithm.hpp" +#include "../std/bind.hpp" class ScaleIndexBase @@ -89,12 +90,12 @@ public: } template - void ForEachInIntervalAndScale(F const & f, uint64_t beg, uint64_t end, uint32_t scale) const + void ForEachInIntervalAndScale(F & f, uint64_t beg, uint64_t end, uint32_t scale) const { size_t const scaleBucket = BucketByScale(scale); if (scaleBucket < m_IndexForScale.size()) { - IntervalIndexIFace::FunctionT f1(f); + IntervalIndexIFace::FunctionT f1(bind(ref(f), _1)); for (size_t i = 0; i <= scaleBucket; ++i) m_IndexForScale[i]->DoForEach(f1, beg, end); } diff --git a/search/locality_finder.cpp b/search/locality_finder.cpp index 64a414b327..d64c2fa97b 100644 --- a/search/locality_finder.cpp +++ b/search/locality_finder.cpp @@ -14,12 +14,12 @@ double const MAX_RADIUS_CITY = 30000.0; class DoLoader { public: - DoLoader(LocalityFinder const & finder, FeaturesVector const & loader, LocalityFinder::Cache & cache, m2::RectD const & rect) - : m_finder(finder), m_loader(loader), m_cache(cache), m_rect(rect) + DoLoader(LocalityFinder const & finder, FeaturesVector const & loader, LocalityFinder::Cache & cache) + : m_finder(finder), m_loader(loader), m_cache(cache) { } - void operator() (uint32_t id) + void operator() (uint32_t id) const { FeatureType ft; m_loader.Get(id, ft); @@ -46,7 +46,7 @@ public: double const radius = ftypes::GetRadiusByPopulation(population); m2::RectD const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(ft.GetCenter(), radius); - if (!rect.IsIntersect(m_rect)) + if (!rect.IsIntersect(m_cache.m_rect)) return; // read item @@ -64,7 +64,6 @@ private: LocalityFinder const & m_finder; FeaturesVector const & m_loader; LocalityFinder::Cache & m_cache; - m2::RectD m_rect; }; @@ -150,9 +149,8 @@ void LocalityFinder::RecreateCache(Cache & cache, m2::RectD rect) const cache.m_rect = rect; for (size_t i = 0; i < interval.size(); ++i) { - index.ForEachInIntervalAndScale(DoLoader(*this, loader, cache, rect), - interval[i].first, interval[i].second, - scale); + DoLoader doLoader(*this, loader, cache); + index.ForEachInIntervalAndScale(doLoader, interval[i].first, interval[i].second, scale); } } } diff --git a/search/locality_finder.hpp b/search/locality_finder.hpp index b061f629d5..08741d5ba5 100644 --- a/search/locality_finder.hpp +++ b/search/locality_finder.hpp @@ -30,7 +30,6 @@ struct LocalityItem class LocalityFinder { - struct Cache { m4::Tree m_tree; diff --git a/search/search_query.cpp b/search/search_query.cpp index ca269be023..c6db240692 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -279,9 +279,8 @@ void Query::UpdateViewportOffsets(MWMVectorT const & mwmInfo, m2::RectD const & for (size_t i = 0; i < interval.size(); ++i) { - index.ForEachInIntervalAndScale(MakeBackInsertFunctor(offsets[mwmId]), - interval[i].first, interval[i].second, - scale); + auto collectFn = MakeBackInsertFunctor(offsets[mwmId]); + index.ForEachInIntervalAndScale(collectFn, interval[i].first, interval[i].second, scale); } sort(offsets[mwmId].begin(), offsets[mwmId].end());