From 20faf97e15cda565899cfa6ced0c40e7f8262071 Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 27 Sep 2011 12:05:59 +0300 Subject: [PATCH] Minor changes with rect cover getting in index. --- indexer/index.cpp | 30 ++++++++++++++++++------------ indexer/index.hpp | 37 +++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/indexer/index.cpp b/indexer/index.cpp index 6087e8cd02..a85ba97aa4 100644 --- a/indexer/index.cpp +++ b/indexer/index.cpp @@ -38,22 +38,28 @@ Index::~Index() using namespace covering; -void Index::GetCovering(m2::RectD const & rect, int mode, int cellDepth, IntervalsT & res) +IntervalsT const & Index::CoveringGetter::Get(feature::DataHeader const & header) { - ASSERT ( res.empty(), () ); + int const cellDepth = GetCodingDepth(header.GetScaleRange()); + int const ind = (cellDepth == RectId::DEPTH_LEVELS ? 0 : 1); - switch (mode) + if (m_res[ind].empty()) { - case 0: - CoverViewportAndAppendLowerLevels(rect, cellDepth, res); - break; + switch (m_mode) + { + case 0: + CoverViewportAndAppendLowerLevels(m_rect, cellDepth, m_res[ind]); + break; - case 1: - AppendLowerLevels(GetRectIdAsIs(rect), cellDepth, res); - break; + case 1: + AppendLowerLevels(GetRectIdAsIs(m_rect), cellDepth, m_res[ind]); + break; - case 2: - res.push_back(IntervalsT::value_type(0, static_cast((1ULL << 63) - 1))); - break; + case 2: + m_res[ind].push_back(IntervalsT::value_type(0, static_cast((1ULL << 63) - 1))); + break; + } } + + return m_res[ind]; } diff --git a/indexer/index.hpp b/indexer/index.hpp index 51793b78b7..51585f5fd1 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -89,13 +89,23 @@ private: } }; - /// @param[in] mode\n - /// - 0 - cover viewport with low lovels;\n - /// - 1 - cover append low levels only;\n - /// - 2 - make full cover\n - static void GetCovering(m2::RectD const & rect, - int mode, int cellDepth, - covering::IntervalsT & res); + class CoveringGetter + { + typedef covering::IntervalsT ResT; + ResT m_res[2]; + + m2::RectD const & m_rect; + int m_mode; + + public: + /// @param[in] mode\n + /// - 0 - cover viewport with low lovels;\n + /// - 1 - cover append low levels only;\n + /// - 2 - make full cover\n + CoveringGetter(m2::RectD const & r, int mode) : m_rect(r), m_mode(mode) {} + + ResT const & Get(feature::DataHeader const & header); + }; template void ForEachInIntervals(F & f, int mode, m2::RectD const & rect, uint32_t scale) const @@ -103,7 +113,7 @@ private: vector mwm; GetMwmInfo(mwm); - covering::IntervalsT intervals[2]; + CoveringGetter cov(rect, mode); for (MwmId id = 0; id < mwm.size(); ++id) { @@ -117,11 +127,7 @@ private: feature::DataHeader const & header = pValue->GetHeader(); // prepare needed covering - int const cellDepth = covering::GetCodingDepth(header.GetScaleRange()); - int const ind = (cellDepth == RectId::DEPTH_LEVELS ? 0 : 1); - - if (intervals[ind].empty()) - GetCovering(rect, mode, cellDepth, intervals[ind]); + covering::IntervalsT const & interval = cov.Get(header); // prepare features reading FeaturesVector fv(pValue->m_cont, header); @@ -131,10 +137,9 @@ private: // iterate through intervals unordered_set offsets; ReadFeatureFunctor f1(fv, f, offsets); - for (size_t i = 0; i < intervals[ind].size(); ++i) + for (size_t i = 0; i < interval.size(); ++i) { - index.ForEachInIntervalAndScale(f1, intervals[ind][i].first, intervals[ind][i].second, - scale); + index.ForEachInIntervalAndScale(f1, interval[i].first, interval[i].second, scale); } } }