diff options
author | tatiana-yan <tatiana.kondakova@gmail.com> | 2018-07-17 19:14:20 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-07-18 15:11:04 +0300 |
commit | ec70731d835e820af520ad489a9ecd88d78b49d3 (patch) | |
tree | 7cf724b9971081f4e519951336ce3c525b867027 /search | |
parent | cffa89885abce4582daeff8f29fbeb095e07ed5a (diff) |
[search] Use vector for preferredCategories and CategoriesCache
Diffstat (limited to 'search')
-rw-r--r-- | search/categories_cache.cpp | 2 | ||||
-rw-r--r-- | search/categories_cache.hpp | 9 | ||||
-rw-r--r-- | search/geocoder.hpp | 3 | ||||
-rw-r--r-- | search/intermediate_result.cpp | 10 | ||||
-rw-r--r-- | search/intermediate_result.hpp | 14 | ||||
-rw-r--r-- | search/processor.cpp | 8 | ||||
-rw-r--r-- | search/processor.hpp | 3 | ||||
-rw-r--r-- | search/ranker.cpp | 4 | ||||
-rw-r--r-- | search/ranker.hpp | 3 | ||||
-rw-r--r-- | search/utils.cpp | 10 | ||||
-rw-r--r-- | search/utils.hpp | 13 |
11 files changed, 41 insertions, 38 deletions
diff --git a/search/categories_cache.cpp b/search/categories_cache.cpp index 336967f3ec..2f828d943d 100644 --- a/search/categories_cache.cpp +++ b/search/categories_cache.cpp @@ -11,7 +11,7 @@ #include "base/assert.hpp" #include "base/levenshtein_dfa.hpp" -#include "std/vector.hpp" +using namespace std; namespace search { diff --git a/search/categories_cache.hpp b/search/categories_cache.hpp index 755161fe99..e0e5d9bffd 100644 --- a/search/categories_cache.hpp +++ b/search/categories_cache.hpp @@ -7,8 +7,9 @@ #include "base/cancellable.hpp" -#include "std/map.hpp" -#include "std/set.hpp" +#include <cstdint> +#include <map> +#include <vector> namespace search { @@ -24,7 +25,7 @@ public: source.ForEachType([this](uint32_t type) { m_categories.Add(type); }); } - CategoriesCache(set<uint32_t> const & types, ::base::Cancellable const & cancellable) + CategoriesCache(std::vector<uint32_t> const & types, ::base::Cancellable const & cancellable) : m_cancellable(cancellable) { for (uint32_t type : types) @@ -42,7 +43,7 @@ private: CategoriesSet m_categories; ::base::Cancellable const & m_cancellable; - map<MwmSet::MwmId, CBV> m_cache; + std::map<MwmSet::MwmId, CBV> m_cache; }; class StreetsCache : public CategoriesCache diff --git a/search/geocoder.hpp b/search/geocoder.hpp index 749e04197e..fd49e3408f 100644 --- a/search/geocoder.hpp +++ b/search/geocoder.hpp @@ -35,7 +35,6 @@ #include "base/string_utils.hpp" #include "std/limits.hpp" -#include "std/set.hpp" #include "std/shared_ptr.hpp" #include "std/string.hpp" #include "std/unique_ptr.hpp" @@ -83,7 +82,7 @@ public: m2::RectD m_pivot; Locales m_categoryLocales; shared_ptr<hotels_filter::Rule> m_hotelsFilter; - set<uint32_t> m_preferredTypes; + vector<uint32_t> m_preferredTypes; shared_ptr<Tracer> m_tracer; }; diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index bc4d040d6a..a58d53e6d1 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -19,11 +19,14 @@ #include "base/string_utils.hpp" #include "base/logging.hpp" +#include <algorithm> #include <cstddef> #include <cstdint> #include "3party/opening_hours/opening_hours.hpp" +using namespace std; + namespace search { namespace @@ -132,13 +135,14 @@ bool RankerResult::IsStreet() const return m_geomType == feature::GEOM_LINE && ftypes::IsStreetChecker::Instance()(m_types); } -uint32_t RankerResult::GetBestType(set<uint32_t> const * pPrefferedTypes) const +uint32_t RankerResult::GetBestType(vector<uint32_t> const & preferredTypes) const { - if (pPrefferedTypes) + ASSERT(is_sorted(preferredTypes.begin(), preferredTypes.end()), ()); + if (!preferredTypes.empty()) { for (uint32_t type : m_types) { - if (pPrefferedTypes->count(type) > 0) + if (binary_search(preferredTypes.begin(), preferredTypes.end(), type)) return type; } } diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index e509b1ba0f..c564a39ad1 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -9,7 +9,9 @@ #include "indexer/feature_data.hpp" -#include "std/set.hpp" +#include <cstdint> +#include <string> +#include <vector> class FeatureType; class CategoriesHolder; @@ -62,7 +64,7 @@ public: /// For RESULT_FEATURE and RESULT_BUILDING. RankerResult(FeatureType const & f, m2::PointD const & center, m2::PointD const & pivot, - string const & displayName, string const & fileName); + std::string const & displayName, std::string const & fileName); /// For RESULT_LATLON. RankerResult(double lat, double lon); @@ -78,7 +80,7 @@ public: } FeatureID const & GetID() const { return m_id; } - string const & GetName() const { return m_str; } + std::string const & GetName() const { return m_str; } feature::TypesHolder const & GetTypes() const { return m_types; } Type const & GetResultType() const { return m_resultType; } m2::PointD GetCenter() const { return m_region.m_point; } @@ -94,7 +96,7 @@ public: bool IsEqualCommon(RankerResult const & r) const; - uint32_t GetBestType(set<uint32_t> const * pPrefferedTypes = 0) const; + uint32_t GetBestType(std::vector<uint32_t> const & preferredTypes = {}) const; private: friend class RankerResultMaker; @@ -117,7 +119,7 @@ private: RegionInfo m_region; FeatureID m_id; feature::TypesHolder m_types; - string m_str; + std::string m_str; double m_distance; Type m_resultType; RankingInfo m_info; @@ -127,5 +129,5 @@ private: void ProcessMetadata(FeatureType const & ft, Result::Metadata & meta); -string DebugPrint(RankerResult const & r); +std::string DebugPrint(RankerResult const & r); } // namespace search diff --git a/search/processor.cpp b/search/processor.cpp index 333f39d33e..0529278007 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -276,10 +276,8 @@ void Processor::SetQuery(string const & query) // Get preferred types to show in results. m_preferredTypes.clear(); ForEachCategoryType(QuerySliceOnRawStrings<decltype(m_tokens)>(m_tokens, m_prefix), - [&](size_t, uint32_t t) - { - m_preferredTypes.insert(t); - }); + [&](size_t, uint32_t t) { m_preferredTypes.push_back(t); }); + my::SortUnique(m_preferredTypes); } m2::PointD Processor::GetPivotPoint(bool viewportSearch) const @@ -503,7 +501,7 @@ void Processor::InitParams(QueryParams & params) const params.GetTypeIndices(i).push_back(index); }; auto const tokenSlice = QuerySliceOnRawStrings<decltype(m_tokens)>(m_tokens, m_prefix); - set<uint32_t> types; + vector<uint32_t> types; bool const isCategorialRequest = FillCategories(tokenSlice, GetCategoryLocales(), m_categories, types); params.SetCategorialRequest(isCategorialRequest); diff --git a/search/processor.hpp b/search/processor.hpp index 238cf789b0..a62ab42f5a 100644 --- a/search/processor.hpp +++ b/search/processor.hpp @@ -28,7 +28,6 @@ #include <cstddef> #include <cstdint> -#include <set> #include <string> #include <utility> #include <vector> @@ -123,7 +122,7 @@ protected: std::string m_query; QueryTokens m_tokens; strings::UniString m_prefix; - std::set<uint32_t> m_preferredTypes; + std::vector<uint32_t> m_preferredTypes; m2::RectD m_viewport; m2::PointD m_position; diff --git a/search/ranker.cpp b/search/ranker.cpp index 2d679db1bc..6fa6e7b225 100644 --- a/search/ranker.cpp +++ b/search/ranker.cpp @@ -424,7 +424,7 @@ Result Ranker::MakeResult(RankerResult const & rankerResult, bool needAddress, case RankerResult::Type::TYPE_FEATURE: case RankerResult::Type::TYPE_BUILDING: { - auto const type = rankerResult.GetBestType(&m_params.m_preferredTypes); + auto const type = rankerResult.GetBestType(m_params.m_preferredTypes); return Result(r.GetID(), r.GetCenter(), name, address, m_categories.GetReadableFeatureType(type, m_params.m_currentLocaleCode), type, r.GetMetadata()); @@ -643,7 +643,7 @@ void Ranker::ProcessSuggestions(vector<RankerResult> & vec) const string Ranker::GetLocalizedRegionInfoForResult(RankerResult const & result) const { - auto const type = result.GetBestType(&m_params.m_preferredTypes); + auto const type = result.GetBestType(m_params.m_preferredTypes); storage::TCountryId id; if (!result.GetCountryId(m_infoGetter, type, id)) diff --git a/search/ranker.hpp b/search/ranker.hpp index 1b702e1d35..b7df6e4f47 100644 --- a/search/ranker.hpp +++ b/search/ranker.hpp @@ -23,7 +23,6 @@ #include <cstddef> #include <cstdint> -#include <set> #include <string> #include <utility> #include <vector> @@ -52,7 +51,7 @@ public: m2::RectD m_viewport; m2::PointD m_position; string m_pivotRegion; - std::set<uint32_t> m_preferredTypes; + std::vector<uint32_t> m_preferredTypes; bool m_suggestsEnabled = false; bool m_needAddress = false; bool m_needHighlighting = false; diff --git a/search/utils.cpp b/search/utils.cpp index 817653f9a5..cca289d5f9 100644 --- a/search/utils.cpp +++ b/search/utils.cpp @@ -48,10 +48,10 @@ strings::LevenshteinDFA BuildLevenshteinDFA(strings::UniString const & s) return strings::LevenshteinDFA(s, 1 /* prefixSize */, kAllowedMisprints, GetMaxErrorsForToken(s)); } -set<uint32_t> GetCategoryTypes(string const & name, string const & locale, - CategoriesHolder const & categories) +vector<uint32_t> GetCategoryTypes(string const & name, string const & locale, + CategoriesHolder const & categories) { - set<uint32_t> types; + vector<uint32_t> types; int8_t const code = CategoriesHolder::MapLocaleToInteger(locale); Locales locales; @@ -63,6 +63,8 @@ set<uint32_t> GetCategoryTypes(string const & name, string const & locale, FillCategories(QuerySliceOnRawStrings<vector<strings::UniString>>(tokens, {} /* prefix */), locales, categories, types); + + my::SortUnique(types); return types; } @@ -88,7 +90,7 @@ MwmSet::MwmHandle FindWorld(DataSource const & dataSource) return FindWorld(dataSource, infos); } -void ForEachOfTypesInRect(DataSource const & dataSource, set<uint32_t> const & types, +void ForEachOfTypesInRect(DataSource const & dataSource, vector<uint32_t> const & types, m2::RectD const & pivot, FeatureIndexCallback const & fn) { vector<shared_ptr<MwmInfo>> infos; diff --git a/search/utils.hpp b/search/utils.hpp index aa6c21f434..0942ade6fc 100644 --- a/search/utils.hpp +++ b/search/utils.hpp @@ -21,7 +21,6 @@ #include <cstdint> #include <functional> #include <memory> -#include <set> #include <vector> class DataSource; @@ -88,7 +87,7 @@ void ForEachCategoryTypeFuzzy(StringSliceBase const & slice, Locales const & loc // and a space after it means that no errors were made. template <typename T> bool FillCategories(QuerySliceOnRawStrings<T> const & slice, Locales const & locales, - CategoriesHolder const & catHolder, std::set<uint32_t> & types) + CategoriesHolder const & catHolder, std::vector<uint32_t> & types) { types.clear(); if (slice.HasPrefixToken()) @@ -112,16 +111,16 @@ bool FillCategories(QuerySliceOnRawStrings<T> const & slice, Locales const & loc return; } - types.insert(type); + types.push_back(type); }); return !types.empty(); } -// Returns set of classificator types for category with |name| and |locale|. For metacategories +// Returns classificator types for category with |name| and |locale|. For metacategories // like "Hotel" returns all subcategories types. -std::set<uint32_t> GetCategoryTypes(std::string const & name, std::string const & locale, - CategoriesHolder const & categories); +std::vector<uint32_t> GetCategoryTypes(std::string const & name, std::string const & locale, + CategoriesHolder const & categories); MwmSet::MwmHandle FindWorld(DataSource const & dataSource, std::vector<std::shared_ptr<MwmInfo>> const & infos); @@ -129,6 +128,6 @@ MwmSet::MwmHandle FindWorld(DataSource const & dataSource); using FeatureIndexCallback = std::function<void(FeatureID const &)>; // Applies |fn| to each feature index of type from |types| in |rect|. -void ForEachOfTypesInRect(DataSource const & dataSource, std::set<uint32_t> const & types, +void ForEachOfTypesInRect(DataSource const & dataSource, std::vector<uint32_t> const & types, m2::RectD const & rect, FeatureIndexCallback const & fn); } // namespace search |