diff options
author | vng <viktor.govako@gmail.com> | 2015-07-17 17:27:55 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:57:15 +0300 |
commit | 5399343271ccb738d2624fb25250ba3e9694e21c (patch) | |
tree | 164387f96c2c8a2b8d6e704fe3d74db2d2d8560f /indexer | |
parent | 6b9892d72ad0bbe54a7a7f7ef7664e517c8d54fc (diff) |
Review fixes.
Diffstat (limited to 'indexer')
-rw-r--r-- | indexer/feature_decl.cpp | 2 | ||||
-rw-r--r-- | indexer/feature_decl.hpp | 10 | ||||
-rw-r--r-- | indexer/feature_loader.cpp | 4 | ||||
-rw-r--r-- | indexer/features_vector.cpp | 5 | ||||
-rw-r--r-- | indexer/features_vector.hpp | 14 | ||||
-rw-r--r-- | indexer/index.cpp | 6 | ||||
-rw-r--r-- | indexer/index.hpp | 18 | ||||
-rw-r--r-- | indexer/indexer.pro | 2 | ||||
-rw-r--r-- | indexer/indexer_tests/test_mwm_set.hpp | 1 | ||||
-rw-r--r-- | indexer/mwm_set.cpp | 24 | ||||
-rw-r--r-- | indexer/mwm_set.hpp | 3 | ||||
-rw-r--r-- | indexer/scale_index_builder.hpp | 18 | ||||
-rw-r--r-- | indexer/search_index_builder.cpp | 16 | ||||
-rw-r--r-- | indexer/unique_index.hpp | 50 |
14 files changed, 80 insertions, 93 deletions
diff --git a/indexer/feature_decl.cpp b/indexer/feature_decl.cpp index e3df79d2f6..c697f6948c 100644 --- a/indexer/feature_decl.cpp +++ b/indexer/feature_decl.cpp @@ -6,6 +6,6 @@ string DebugPrint(FeatureID const & id) { ostringstream ss; - ss << "{ " << DebugPrint(id.m_mwmId) << ", " << id.m_ind << " }"; + ss << "{ " << DebugPrint(id.m_mwmId) << ", " << id.m_index << " }"; return ss.str(); } diff --git a/indexer/feature_decl.hpp b/indexer/feature_decl.hpp index b0f706fa7d..6c89648b5f 100644 --- a/indexer/feature_decl.hpp +++ b/indexer/feature_decl.hpp @@ -20,24 +20,24 @@ enum EGeomType struct FeatureID { MwmSet::MwmId m_mwmId; - uint32_t m_ind; + uint32_t m_index; - FeatureID() : m_ind(0) {} - FeatureID(MwmSet::MwmId const & mwmId, uint32_t ind) : m_mwmId(mwmId), m_ind(ind) {} + FeatureID() : m_index(0) {} + FeatureID(MwmSet::MwmId const & mwmId, uint32_t index) : m_mwmId(mwmId), m_index(index) {} bool IsValid() const { return m_mwmId.IsAlive(); } inline bool operator<(FeatureID const & r) const { if (m_mwmId == r.m_mwmId) - return m_ind < r.m_ind; + return m_index < r.m_index; else return m_mwmId < r.m_mwmId; } inline bool operator==(FeatureID const & r) const { - return (m_mwmId == r.m_mwmId && m_ind == r.m_ind); + return (m_mwmId == r.m_mwmId && m_index == r.m_index); } inline bool operator!=(FeatureID const & r) const { return !(*this == r); } diff --git a/indexer/feature_loader.cpp b/indexer/feature_loader.cpp index 85e03bb9d9..0e79af92bd 100644 --- a/indexer/feature_loader.cpp +++ b/indexer/feature_loader.cpp @@ -260,11 +260,11 @@ void LoaderCurrent::ParseMetadata() DDVector<IdxElementT, FilesContainerR::ReaderT> idx(m_Info.GetMetadataIndexReader()); auto it = lower_bound(idx.begin(), idx.end() - , make_pair(uint32_t(m_pF->m_id.m_ind), uint32_t(0)) + , make_pair(uint32_t(m_pF->m_id.m_index), uint32_t(0)) , [](IdxElementT const & v1, IdxElementT const & v2) { return v1.first < v2.first; } ); - if (it != idx.end() && m_pF->m_id.m_ind == it->first) + if (it != idx.end() && m_pF->m_id.m_index == it->first) { ReaderSource<FilesContainerR::ReaderT> reader(m_Info.GetMetadataReader()); reader.Skip(it->second); diff --git a/indexer/features_vector.cpp b/indexer/features_vector.cpp index 32bdab3adc..e1329cc85c 100644 --- a/indexer/features_vector.cpp +++ b/indexer/features_vector.cpp @@ -6,10 +6,11 @@ #include "platform/constants.hpp" -void FeaturesVector::GetByIndex(uint32_t ind, FeatureType & ft) const +void FeaturesVector::GetByIndex(uint32_t index, FeatureType & ft) const { uint32_t offset = 0, size = 0; - m_RecordReader.ReadRecord(m_table ? m_table->GetFeatureOffset(ind) : ind, m_buffer, offset, size); + auto const ftOffset = m_table ? m_table->GetFeatureOffset(index) : index; + m_RecordReader.ReadRecord(ftOffset, m_buffer, offset, size); ft.Deserialize(m_LoadInfo.GetLoader(), &m_buffer[offset]); } diff --git a/indexer/features_vector.hpp b/indexer/features_vector.hpp index 3c63fc3833..53d8c46d66 100644 --- a/indexer/features_vector.hpp +++ b/indexer/features_vector.hpp @@ -20,20 +20,20 @@ public: { } - void GetByIndex(uint32_t ind, FeatureType & ft) const; + void GetByIndex(uint32_t index, FeatureType & ft) const; - template <class ToDo> void ForEach(ToDo toDo) const + template <class ToDo> void ForEach(ToDo && toDo) const { - uint32_t ind = 0; + uint32_t index = 0; m_RecordReader.ForEachRecord([&] (uint32_t pos, char const * data, uint32_t /*size*/) { FeatureType ft; ft.Deserialize(m_LoadInfo.GetLoader(), data); - toDo(ft, m_table ? ind++ : pos); + toDo(ft, m_table ? index++ : pos); }); } - template <class ToDo> static void ForEachOffset(ModelReaderPtr reader, ToDo toDo) + template <class ToDo> static void ForEachOffset(ModelReaderPtr reader, ToDo && toDo) { VarRecordReader<ModelReaderPtr, &VarRecordSizeReaderVarint> recordReader(reader, 256); recordReader.ForEachRecord([&] (uint32_t pos, char const * /*data*/, uint32_t /*size*/) @@ -43,11 +43,11 @@ public: } private: + friend class FeaturesVectorTest; + feature::SharedLoadInfo m_LoadInfo; VarRecordReader<FilesContainerR::ReaderT, &VarRecordSizeReaderVarint> m_RecordReader; mutable vector<char> m_buffer; - - friend class FeaturesVectorTest; feature::FeaturesOffsetsTable const * m_table; }; diff --git a/indexer/index.cpp b/indexer/index.cpp index 560e38aac2..c34db7002a 100644 --- a/indexer/index.cpp +++ b/indexer/index.cpp @@ -108,8 +108,8 @@ bool Index::FeaturesLoaderGuard::IsWorld() const return m_handle.GetValue<MwmValue>()->GetHeader().GetType() == feature::DataHeader::world; } -void Index::FeaturesLoaderGuard::GetFeatureByIndex(uint32_t ind, FeatureType & ft) +void Index::FeaturesLoaderGuard::GetFeatureByIndex(uint32_t index, FeatureType & ft) { - m_vector.GetByIndex(ind, ft); - ft.SetID(FeatureID(m_handle.GetId(), ind)); + m_vector.GetByIndex(index, ft); + ft.SetID(FeatureID(m_handle.GetId(), index)); } diff --git a/indexer/index.hpp b/indexer/index.hpp index d7c21ba0d5..611fd7e8da 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -125,14 +125,14 @@ private: for (auto const & i : interval) { - index.ForEachInIntervalAndScale([&] (uint32_t ind) + index.ForEachInIntervalAndScale([&] (uint32_t index) { - if (checkUnique(ind)) + if (checkUnique(index)) { FeatureType feature; - fv.GetByIndex(ind, feature); - feature.SetID(FeatureID(mwmID, ind)); + fv.GetByIndex(index, feature); + feature.SetID(FeatureID(mwmID, index)); m_f(feature); } @@ -172,10 +172,10 @@ private: for (auto const & i : interval) { - index.ForEachInIntervalAndScale([&] (uint32_t ind) + index.ForEachInIntervalAndScale([&] (uint32_t index) { - if (checkUnique(ind)) - m_f(FeatureID(mwmID, ind)); + if (checkUnique(index)) + m_f(FeatureID(mwmID, index)); }, i.first, i.second, scale); } } @@ -230,7 +230,7 @@ public: inline MwmSet::MwmId GetId() const { return m_handle.GetId(); } string GetCountryFileName() const; bool IsWorld() const; - void GetFeatureByIndex(uint32_t ind, FeatureType & ft); + void GetFeatureByIndex(uint32_t index, FeatureType & ft); private: MwmHandle m_handle; @@ -271,7 +271,7 @@ private: FeatureID const & featureId = features[result]; FeatureType featureType; - featureReader.GetByIndex(featureId.m_ind, featureType); + featureReader.GetByIndex(featureId.m_index, featureType); featureType.SetID(featureId); f(featureType); diff --git a/indexer/indexer.pro b/indexer/indexer.pro index 5bbb1c88f4..dd251aa629 100644 --- a/indexer/indexer.pro +++ b/indexer/indexer.pro @@ -29,6 +29,7 @@ SOURCES += \ feature_utils.cpp \ feature_visibility.cpp \ features_offsets_table.cpp \ + features_vector.cpp \ ftypes_matcher.cpp \ geometry_coding.cpp \ geometry_serialization.cpp \ @@ -46,7 +47,6 @@ SOURCES += \ search_index_builder.cpp \ search_string_utils.cpp \ types_mapping.cpp \ - features_vector.cpp \ HEADERS += \ categories_holder.hpp \ diff --git a/indexer/indexer_tests/test_mwm_set.hpp b/indexer/indexer_tests/test_mwm_set.hpp index 8206465f7c..853d78b927 100644 --- a/indexer/indexer_tests/test_mwm_set.hpp +++ b/indexer/indexer_tests/test_mwm_set.hpp @@ -25,6 +25,7 @@ protected: info->m_version.format = version::lastFormat; return info; } + MwmValueBase * CreateValue(MwmInfo &) const override { return new MwmValueBase(); diff --git a/indexer/mwm_set.cpp b/indexer/mwm_set.cpp index 389354f314..3ced9905c6 100644 --- a/indexer/mwm_set.cpp +++ b/indexer/mwm_set.cpp @@ -291,24 +291,14 @@ void MwmSet::ClearCacheImpl(CacheType::iterator beg, CacheType::iterator end) m_cache.erase(beg, end); } -namespace -{ - struct MwmIdIsEqualTo - { - MwmSet::MwmId m_id; - - explicit MwmIdIsEqualTo(MwmSet::MwmId const & id) : m_id(id) {} - - bool operator()(pair<MwmSet::MwmId, MwmSet::TMwmValueBasePtr> const & p) const - { - return p.first == m_id; - } - }; -} - void MwmSet::ClearCache(MwmId const & id) { - ClearCacheImpl(RemoveIfKeepValid(m_cache.begin(), m_cache.end(), MwmIdIsEqualTo(id)), m_cache.end()); + ClearCacheImpl(RemoveIfKeepValid(m_cache.begin(), m_cache.end(), + [&id] (pair<MwmSet::MwmId, MwmSet::TMwmValueBasePtr> const & p) + { + return (p.first == id); + }), + m_cache.end()); } string DebugPrint(MwmSet::RegResult result) @@ -324,6 +314,6 @@ string DebugPrint(MwmSet::RegResult result) case MwmSet::RegResult::BadFile: return "BadFile"; case MwmSet::RegResult::UnsupportedFileFormat: - return "UnsupportedFileFormat"; + return "UnsupportedFileFormat"; } } diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp index a5663da83b..8370a0f482 100644 --- a/indexer/mwm_set.hpp +++ b/indexer/mwm_set.hpp @@ -84,13 +84,12 @@ public: friend class MwmSet; MwmId() = default; - MwmId(MwmId const & id) = default; MwmId(shared_ptr<MwmInfo> const & info) : m_info(info) {} void Reset() { m_info.reset(); } bool IsAlive() const { - return m_info.get() != nullptr && m_info->GetStatus() != MwmInfo::STATUS_DEREGISTERED; + return (m_info && m_info->GetStatus() != MwmInfo::STATUS_DEREGISTERED); } shared_ptr<MwmInfo> const & GetInfo() const { return m_info; } diff --git a/indexer/scale_index_builder.hpp b/indexer/scale_index_builder.hpp index b644ea6d6c..94376b8c29 100644 --- a/indexer/scale_index_builder.hpp +++ b/indexer/scale_index_builder.hpp @@ -101,10 +101,10 @@ public: } template <class TFeature> - void operator() (TFeature const & f, uint32_t ind) const + void operator() (TFeature const & ft, uint32_t index) const { m_scalesIdx = 0; - uint32_t minScaleClassif = feature::GetMinDrawableScaleClassifOnly(f); + uint32_t minScaleClassif = feature::GetMinDrawableScaleClassifOnly(ft); // The classificator won't allow this feature to be drawable for smaller // scales so the first buckets can be safely skipped. // todo(@pimenov) Parallelizing this loop may be helpful. @@ -114,14 +114,14 @@ public: // This is not immediately obvious and in fact there was an idea to map // a bucket to a contiguous range of scales. // todo(@pimenov): We probably should remove scale_index.hpp altogether. - if (!FeatureShouldBeIndexed(f, bucket, bucket == minScaleClassif /* needReset */)) + if (!FeatureShouldBeIndexed(ft, bucket, bucket == minScaleClassif /* needReset */)) { continue; } - vector<int64_t> const cells = covering::CoverFeature(f, m_codingDepth, 250); + vector<int64_t> const cells = covering::CoverFeature(ft, m_codingDepth, 250); for (int64_t cell : cells) - m_sorter.Add(CellFeatureBucketTuple(CellFeaturePair(cell, ind), bucket)); + m_sorter.Add(CellFeatureBucketTuple(CellFeaturePair(cell, index), bucket)); m_featuresInBucket[bucket] += 1; m_cellsInBucket[bucket] += cells.size(); @@ -137,7 +137,7 @@ private: // -- it is allowed by the classificator. // If the feature is invisible at all scales, do not index it. template <class TFeature> - bool FeatureShouldBeIndexed(TFeature const & f, uint32_t scale, bool needReset) const + bool FeatureShouldBeIndexed(TFeature const & ft, uint32_t scale, bool needReset) const { while (m_scalesIdx < m_header.GetScalesCount() && m_header.GetScale(m_scalesIdx) < scale) { @@ -146,16 +146,16 @@ private: } if (needReset) - f.ResetGeometry(); + ft.ResetGeometry(); // This function invokes geometry reading for the needed scale. - if (f.IsEmptyGeometry(scale)) + if (ft.IsEmptyGeometry(scale)) return false; // This function assumes that geometry rect for the needed scale is already initialized. // Note: it works with FeatureBase so in fact it does not use the information about // the feature's geometry except for the type and the LimitRect. - return feature::IsDrawableForIndexGeometryOnly(f, scale); + return feature::IsDrawableForIndexGeometryOnly(ft, scale); } // We do not need to parse a feature's geometry for every bucket. diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index b4d2b5a110..7ca3488fa1 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -158,15 +158,15 @@ struct ValueBuilder<SerializedFeatureInfoValue> ValueBuilder(serial::CodingParams const & cp) : m_valueSaver(cp) {} - void MakeValue(FeatureType const & f, feature::TypesHolder const & types, uint32_t ind, + void MakeValue(FeatureType const & ft, feature::TypesHolder const & types, uint32_t index, SerializedFeatureInfoValue & value) const { SaverT::ValueType v; - v.m_featureId = ind; + v.m_featureId = index; // get BEST geometry rect of feature - v.m_pt = feature::GetCenter(f); - v.m_rank = feature::GetSearchRank(types, v.m_pt, f.GetPopulation()); + v.m_pt = feature::GetCenter(ft); + v.m_rank = feature::GetSearchRank(types, v.m_pt, ft.GetPopulation()); // write to buffer PushBackByteSink<SerializedFeatureInfoValue::ValueT> sink(value.m_value); @@ -178,9 +178,9 @@ template <> struct ValueBuilder<FeatureIndexValue> { void MakeValue(FeatureType const & /* f */, feature::TypesHolder const & /* types */, - uint32_t ind, FeatureIndexValue & value) const + uint32_t index, FeatureIndexValue & value) const { - value.m_value = ind; + value.m_value = index; } }; @@ -313,7 +313,7 @@ public: { } - void operator() (FeatureType const & f, uint32_t ind) const + void operator() (FeatureType const & f, uint32_t index) const { feature::TypesHolder types(f); @@ -327,7 +327,7 @@ public: // Insert synonyms only for countries and states (maybe will add cities in future). FeatureNameInserter<StringsFileT> inserter(skipIndex.IsCountryOrState(types) ? m_synonyms : 0, m_names); - m_valueBuilder.MakeValue(f, types, ind, inserter.m_val); + m_valueBuilder.MakeValue(f, types, index, inserter.m_val); // Skip types for features without names. if (!f.ForEachNameRef(inserter)) diff --git a/indexer/unique_index.hpp b/indexer/unique_index.hpp index 41865773d0..14007b55a2 100644 --- a/indexer/unique_index.hpp +++ b/indexer/unique_index.hpp @@ -1,9 +1,9 @@ #pragma once -#include "../base/base.hpp" +#include "base/base.hpp" -#include "../std/unordered_set.hpp" -#include "../std/vector.hpp" +#include "std/unordered_set.hpp" +#include "std/vector.hpp" class CheckUniqueIndexes @@ -14,44 +14,40 @@ class CheckUniqueIndexes /// Add index to the set. /// @return true If index was absent. - bool Add(uint32_t ind) + bool Add(uint32_t index) { - if (m_useBits) - { - if (m_v.size() <= ind) - m_v.resize(ind + 1); - bool const ret = !m_v[ind]; - m_v[ind] = true; - return ret; - } - else - return m_s.insert(ind).second; + if (!m_useBits) + return m_s.insert(index).second; + + if (m_v.size() <= index) + m_v.resize(index + 1); + bool const ret = !m_v[index]; + m_v[index] = true; + return ret; } /// Remove index from the set. /// @return true If index was present. - bool Remove(uint32_t ind) + bool Remove(uint32_t index) { - if (m_useBits) + if (!m_useBits) + return (m_s.erase(index) > 0); + + if (m_v.size() > index) { - if (m_v.size() > ind) - { - bool const ret = m_v[ind]; - m_v[ind] = false; - return ret; - } - else - return false; + bool const ret = m_v[index]; + m_v[index] = false; + return ret; } else - return (m_s.erase(ind) > 0); + return false; } public: explicit CheckUniqueIndexes(bool useBits) : m_useBits(useBits) {} - bool operator()(uint32_t ind) + bool operator()(uint32_t index) { - return Add(ind); + return Add(index); } }; |