diff options
author | Maxim Pimenov <m@maps.me> | 2015-07-29 19:10:41 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:58:26 +0300 |
commit | 974687ff983a9830c3eeb35505969cb7a3956ba8 (patch) | |
tree | 0dc8d3549ce4dd9803b23d91d8c9b646c5595e28 /indexer | |
parent | a5b97c77b982969e0eec4b31fb66af9c624707ba (diff) |
More refactoring.
Diffstat (limited to 'indexer')
-rw-r--r-- | indexer/search_index_builder.cpp | 61 | ||||
-rw-r--r-- | indexer/search_trie.hpp | 19 | ||||
-rw-r--r-- | indexer/string_file.hpp | 32 |
3 files changed, 59 insertions, 53 deletions
diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index 2f20e25647..9a86a4dd9b 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -76,11 +76,12 @@ public: } } - template <class ToDo> void ForEach(string const & key, ToDo toDo) const + template <class ToDo> + void ForEach(string const & key, ToDo toDo) const { - typedef unordered_multimap<string, string>::const_iterator IterT; + using TIter = unordered_multimap<string, string>::const_iterator; - pair<IterT, IterT> range = m_map.equal_range(key); + pair<TIter, TIter> range = m_map.equal_range(key); while (range.first != range.second) { toDo(range.first->second); @@ -89,31 +90,32 @@ public: } }; -template<typename StringsFileT> +template <typename TStringsFile> struct FeatureNameInserter { SynonymsHolder * m_synonyms; - StringsFileT & m_names; - typename StringsFileT::ValueT m_val; + TStringsFile & m_names; + typename TStringsFile::ValueT m_val; - FeatureNameInserter(SynonymsHolder * synonyms, StringsFileT & names) + FeatureNameInserter(SynonymsHolder * synonyms, TStringsFile & names) : m_synonyms(synonyms), m_names(names) { } void AddToken(signed char lang, strings::UniString const & s) const { - m_names.AddString(typename StringsFileT::StringT(s, lang, m_val)); + m_names.AddString(typename TStringsFile::TString(s, lang, m_val)); } private: - typedef buffer_vector<strings::UniString, 32> TokensArrayT; + using TTokensArray = buffer_vector<strings::UniString, 32>; class PushSynonyms { - TokensArrayT & m_tokens; + TTokensArray & m_tokens; + public: - PushSynonyms(TokensArrayT & tokens) : m_tokens(tokens) {} + PushSynonyms(TTokensArray & tokens) : m_tokens(tokens) {} void operator() (string const & utf8str) const { m_tokens.push_back(search::NormalizeAndSimplifyString(utf8str)); @@ -153,15 +155,15 @@ struct ValueBuilder; template <> struct ValueBuilder<SerializedFeatureInfoValue> { - typedef trie::ValueReader SaverT; - SaverT m_valueSaver; + using TSaver = trie::ValueReader; + TSaver m_valueSaver; ValueBuilder(serial::CodingParams const & cp) : m_valueSaver(cp) {} void MakeValue(FeatureType const & ft, feature::TypesHolder const & types, uint32_t index, SerializedFeatureInfoValue & value) const { - SaverT::ValueType v; + TSaver::ValueType v; v.m_featureId = index; // get BEST geometry rect of feature @@ -184,16 +186,16 @@ struct ValueBuilder<FeatureIndexValue> } }; -template <typename StringsFileT> +template <typename TStringsFile> class FeatureInserter { SynonymsHolder * m_synonyms; - StringsFileT & m_names; + TStringsFile & m_names; CategoriesHolder const & m_categories; - typedef typename StringsFileT::ValueT ValueT; - typedef trie::ValueReader SaverT; + using ValueT = typename TStringsFile::ValueT; + using TSaver = trie::ValueReader; pair<int, int> m_scales; @@ -205,14 +207,14 @@ class FeatureInserter /// - skip specified types for features with empty names (m_enTypes) class SkipIndexing { - typedef buffer_vector<uint32_t, 16> ContT; + using TCont = buffer_vector<uint32_t, 16>; // Array index (0, 1) means type level for checking (1, 2). - ContT m_skipEn[2], m_skipF[2]; - ContT m_dontSkipEn; + TCont m_skipEn[2], m_skipF[2]; + TCont m_dontSkipEn; uint32_t m_country, m_state; - static bool HasType(ContT const & v, uint32_t t) + static bool HasType(TCont const & v, uint32_t t) { return (find(v.begin(), v.end(), t) != v.end()); } @@ -305,11 +307,14 @@ class FeatureInserter }; public: - FeatureInserter(SynonymsHolder * synonyms, StringsFileT & names, + FeatureInserter(SynonymsHolder * synonyms, TStringsFile & names, CategoriesHolder const & catHolder, pair<int, int> const & scales, ValueBuilder<ValueT> const & valueBuilder) - : m_synonyms(synonyms), m_names(names), - m_categories(catHolder), m_scales(scales), m_valueBuilder(valueBuilder) + : m_synonyms(synonyms) + , m_names(names) + , m_categories(catHolder) + , m_scales(scales) + , m_valueBuilder(valueBuilder) { } @@ -325,7 +330,7 @@ public: // Init inserter with serialized value. // Insert synonyms only for countries and states (maybe will add cities in future). - FeatureNameInserter<StringsFileT> inserter(skipIndex.IsCountryOrState(types) ? m_synonyms : 0, + FeatureNameInserter<TStringsFile> inserter(skipIndex.IsCountryOrState(types) ? m_synonyms : 0, m_names); m_valueBuilder.MakeValue(f, types, index, inserter.m_val); @@ -353,7 +358,7 @@ public: if (r.second >= m_scales.first && r.first <= m_scales.second) { - inserter.AddToken(search::CATEGORIES_LANG, + inserter.AddToken(search::kCategoriesLang, search::FeatureTypeToString(c.GetIndexForType(t))); } } @@ -414,7 +419,7 @@ void BuildSearchIndex(FilesContainerR const & cont, CategoriesHolder const & cat namespace indexer { bool BuildSearchIndexFromDatFile(string const & datFile, bool forceRebuild) { - LOG(LINFO, ("Start building search index. Bits = ", search::POINT_CODING_BITS)); + LOG(LINFO, ("Start building search index. Bits = ", search::kPointCodingBits)); try { diff --git a/indexer/search_trie.hpp b/indexer/search_trie.hpp index 27001b34dd..259b62e172 100644 --- a/indexer/search_trie.hpp +++ b/indexer/search_trie.hpp @@ -9,8 +9,8 @@ namespace search { -static const uint8_t CATEGORIES_LANG = 128; -static const uint8_t POINT_CODING_BITS = 20; +static const uint8_t kCategoriesLang = 128; +static const uint8_t kPointCodingBits = 20; } // namespace search namespace trie @@ -31,14 +31,16 @@ public: uint8_t m_rank; // Rank of feature; }; - template <typename SourceT> void operator() (SourceT & src, ValueType & v) const + template <typename TSource> + void operator()(TSource & src, ValueType & v) const { v.m_pt = serial::LoadPoint(src, m_cp); v.m_featureId = ReadPrimitiveFromSource<uint32_t>(src); v.m_rank = ReadPrimitiveFromSource<uint8_t>(src); } - template <class TSink> void Save(TSink & sink, ValueType const & v) const + template <class TSink> + void Save(TSink & sink, ValueType const & v) const { serial::SavePoint(sink, v.m_pt, m_cp); WriteToSink(sink, v.m_featureId); @@ -46,14 +48,13 @@ public: } }; -typedef EmptyValueReader EdgeValueReader; - -typedef trie::Iterator<trie::ValueReader::ValueType, trie::EdgeValueReader::ValueType> - DefaultIterator; +using TEdgeValueReader = EmptyValueReader; +using DefaultIterator = + trie::Iterator<trie::ValueReader::ValueType, trie::TEdgeValueReader::ValueType>; inline serial::CodingParams GetCodingParams(serial::CodingParams const & orig) { - return serial::CodingParams(search::POINT_CODING_BITS, + return serial::CodingParams(search::kPointCodingBits, PointU2PointD(orig.GetBasePoint(), orig.GetCoordBits())); } diff --git a/indexer/string_file.hpp b/indexer/string_file.hpp index 2bd20e8884..d2c888917c 100644 --- a/indexer/string_file.hpp +++ b/indexer/string_file.hpp @@ -21,21 +21,21 @@ public: using ValueT = TValue; using IdT = uint32_t; - class StringT + class TString { strings::UniString m_name; ValueT m_val; public: - StringT() {} - StringT(strings::UniString const & name, signed char lang, ValueT const & val) : m_val(val) + TString() {} + TString(strings::UniString const & name, signed char lang, ValueT const & val) : m_val(val) { m_name.reserve(name.size() + 1); m_name.push_back(static_cast<uint8_t>(lang)); m_name.append(name.begin(), name.end()); } - StringT(strings::UniString const & langName, ValueT const & val) : m_name(langName), m_val(val) + TString(strings::UniString const & langName, ValueT const & val) : m_name(langName), m_val(val) { } @@ -46,14 +46,14 @@ public: ValueT const & GetValue() const { return m_val; } - bool operator<(StringT const & name) const + bool operator<(TString const & name) const { if (m_name != name.m_name) return m_name < name.m_name; return m_val < name.m_val; } - bool operator==(StringT const & name) const + bool operator==(TString const & name) const { return m_name == name.m_name && m_val == name.m_val; } @@ -81,14 +81,14 @@ public: inline size_t value_size() const { return m_val.size(); } - void Swap(StringT & r) + void Swap(TString & r) { m_name.swap(r.m_name); m_val.swap(r.m_val); } }; - using StringsListT = vector<StringT>; + using StringsListT = vector<TString>; // Contains start and end offsets of file portions. using OffsetsListT = vector<pair<uint64_t, uint64_t>>; @@ -144,7 +144,7 @@ public: DISALLOW_COPY_AND_MOVE(SortAndDumpStringsTask); }; - class IteratorT : public iterator_facade<IteratorT, StringT, forward_traversal_tag, StringT> + class IteratorT : public iterator_facade<IteratorT, TString, forward_traversal_tag, TString> { StringsFile & m_file; bool m_end; @@ -160,7 +160,7 @@ public: m_end = IsEnd(); } - StringT dereference() const; + TString dereference() const; bool equal(IteratorT const & r) const { return (m_end == r.m_end); } void increment(); }; @@ -171,7 +171,7 @@ public: void OpenForRead(); /// @precondition Should be opened for writing. - void AddString(StringT const & s); + void AddString(TString const & s); IteratorT Begin() { return IteratorT(*this, false); } IteratorT End() { return IteratorT(*this, true); } @@ -194,10 +194,10 @@ private: struct QValue { - StringT m_string; + TString m_string; size_t m_index; - QValue(StringT const & s, size_t i) : m_string(s), m_index(i) {} + QValue(TString const & s, size_t i) : m_string(s), m_index(i) {} inline bool operator>(QValue const & rhs) const { return !(m_string < rhs.m_string); } }; @@ -206,7 +206,7 @@ private: }; template <typename ValueT> -void StringsFile<ValueT>::AddString(StringT const & s) +void StringsFile<ValueT>::AddString(TString const & s) { size_t const kMaxSize = 1000000; @@ -223,7 +223,7 @@ bool StringsFile<ValueT>::IteratorT::IsEnd() const } template <typename ValueT> -typename StringsFile<ValueT>::StringT StringsFile<ValueT>::IteratorT::dereference() const +typename StringsFile<ValueT>::TString StringsFile<ValueT>::IteratorT::dereference() const { ASSERT(IsValid(), ()); return m_file.m_queue.top().m_string; @@ -268,7 +268,7 @@ bool StringsFile<ValueT>::PushNextValue(size_t i) src.Skip(m_offsets[i].first); // read string - StringT s; + TString s; s.Read(src); // update offset |