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 +#include +#include namespace search { @@ -24,7 +25,7 @@ public: source.ForEachType([this](uint32_t type) { m_categories.Add(type); }); } - CategoriesCache(set const & types, ::base::Cancellable const & cancellable) + CategoriesCache(std::vector 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 m_cache; + std::map 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 m_hotelsFilter; - set m_preferredTypes; + vector m_preferredTypes; shared_ptr 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 #include #include #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 const * pPrefferedTypes) const +uint32_t RankerResult::GetBestType(vector 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 +#include +#include 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 const * pPrefferedTypes = 0) const; + uint32_t GetBestType(std::vector 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(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(m_tokens, m_prefix); - set types; + vector 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 #include -#include #include #include #include @@ -123,7 +122,7 @@ protected: std::string m_query; QueryTokens m_tokens; strings::UniString m_prefix; - std::set m_preferredTypes; + std::vector 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 & 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 #include -#include #include #include #include @@ -52,7 +51,7 @@ public: m2::RectD m_viewport; m2::PointD m_position; string m_pivotRegion; - std::set m_preferredTypes; + std::vector 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 GetCategoryTypes(string const & name, string const & locale, - CategoriesHolder const & categories) +vector GetCategoryTypes(string const & name, string const & locale, + CategoriesHolder const & categories) { - set types; + vector types; int8_t const code = CategoriesHolder::MapLocaleToInteger(locale); Locales locales; @@ -63,6 +63,8 @@ set GetCategoryTypes(string const & name, string const & locale, FillCategories(QuerySliceOnRawStrings>(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 const & types, +void ForEachOfTypesInRect(DataSource const & dataSource, vector const & types, m2::RectD const & pivot, FeatureIndexCallback const & fn) { vector> 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 #include #include -#include #include 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 bool FillCategories(QuerySliceOnRawStrings const & slice, Locales const & locales, - CategoriesHolder const & catHolder, std::set & types) + CategoriesHolder const & catHolder, std::vector & types) { types.clear(); if (slice.HasPrefixToken()) @@ -112,16 +111,16 @@ bool FillCategories(QuerySliceOnRawStrings 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 GetCategoryTypes(std::string const & name, std::string const & locale, - CategoriesHolder const & categories); +std::vector GetCategoryTypes(std::string const & name, std::string const & locale, + CategoriesHolder const & categories); MwmSet::MwmHandle FindWorld(DataSource const & dataSource, std::vector> const & infos); @@ -129,6 +128,6 @@ MwmSet::MwmHandle FindWorld(DataSource const & dataSource); using FeatureIndexCallback = std::function; // Applies |fn| to each feature index of type from |types| in |rect|. -void ForEachOfTypesInRect(DataSource const & dataSource, std::set const & types, +void ForEachOfTypesInRect(DataSource const & dataSource, std::vector const & types, m2::RectD const & rect, FeatureIndexCallback const & fn); } // namespace search