From 953f9c06c09b9becbb168f80334ac34ae559ae0f Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 2 Mar 2016 10:51:13 +0300 Subject: [PATCH] [new downloader] Style fixes. Review fixes. --- storage/country.hpp | 8 ++++---- storage/country_tree.hpp | 3 --- storage/country_tree_facade.hpp | 16 +++++++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/storage/country.hpp b/storage/country.hpp index ab9f9e229b..d05e73f97b 100644 --- a/storage/country.hpp +++ b/storage/country.hpp @@ -1,8 +1,8 @@ #pragma once #include "storage/country_decl.hpp" -#include "storage/index.hpp" #include "storage/country_tree_facade.hpp" +#include "storage/index.hpp" #include "storage/storage_defines.hpp" #include "platform/local_country_file.hpp" @@ -25,7 +25,7 @@ namespace storage { using TMapping = map; -/// This class keeps all the information about a country in countre tree (TCountriesFacade). +/// This class keeps all the information about a country in country tree (TCountriesFacade). /// It is guaranteed that every node represent a unique region has a unique |m_name| in country tree. /// If several nodes have the same |m_name| they represent the same region. /// It happends in case of disputed territories. @@ -75,8 +75,8 @@ public: TCountryId const & Name() const { return m_name; } }; -typedef CountryTree TCountriesContainer; -typedef CountryTreeFacade TCountriesFacade; +using TCountriesContainer = CountryTree; +using TCountriesFacade = CountryTreeFacade; /// @return version of country file or -1 if error was encountered int64_t LoadCountries(string const & jsonBuffer, TCountriesFacade & countries, TMapping * mapping = nullptr); diff --git a/storage/country_tree.hpp b/storage/country_tree.hpp index c59b0369b2..5e7f62f9f3 100644 --- a/storage/country_tree.hpp +++ b/storage/country_tree.hpp @@ -6,9 +6,6 @@ #include "std/shared_ptr.hpp" #include "std/vector.hpp" -template -bool IsEqual(T const & v1, T const & v2) { return !(v1 < v2) && !(v2 < v1); } - /// This class is developed for using in Storage. It's a implementation of a tree. /// It should be filled with AddAtDepth method. /// This class is used in Storage and filled based on countries.txt (countries_migrate.txt). diff --git a/storage/country_tree_facade.hpp b/storage/country_tree_facade.hpp index d5ca3368bb..a89b8301cb 100644 --- a/storage/country_tree_facade.hpp +++ b/storage/country_tree_facade.hpp @@ -8,13 +8,17 @@ template struct CountryTreeKeyHasher { - size_t operator()(K const & k) const { return hash()(k.Name()); } + size_t operator()(K const & k) const { return m_hash(k.Name()); } +private: + hash m_hash; }; template<> struct CountryTreeKeyHasher { - size_t operator()(int k) const { return hash()(k); } + size_t operator()(int k) const { return m_hash(k); } +private: + hash m_hash; }; /// This class is developed for using in Storage. It's a implementation of a tree. @@ -55,9 +59,6 @@ public: /// \brief Checks all nodes in tree to find an equal one. If there're several equal nodes /// returns the first found. /// \returns a poiter item in the tree if found and nullptr otherwise. - /// @TODO(bykoianko) The complexity of the method is O(n). But the structure (tree) is built on the start of the program - /// and then actively used on run time. This method (and class) should be redesigned to make the function work faster. - /// A hash table is being planned to use. void Find(T const & value, vector const *> & found) const { found.clear(); @@ -94,8 +95,10 @@ public: Find(value, found); for (auto node : found) + { if (node->ChildrenCount() == 0) return node; + } return nullptr; } @@ -132,4 +135,7 @@ public: template void ForEachAncestorExceptForTheRoot(TFunctor && f) const { return m_countryTree.ForEachAncestorExceptForTheRoot(f); } + +private: + static bool IsEqual(T const & v1, T const & v2) { return !(v1 < v2) && !(v2 < v1); } };