From 4e8c055027ca42d90b5f511e605b232407fd4c1d Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 22 Mar 2016 13:42:22 +0300 Subject: [PATCH] [new downloader] Correct size calculation for group nodes in two component mwm case. --- storage/country.cpp | 48 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/storage/country.cpp b/storage/country.cpp index 850dafea8a..e8d57b2bba 100644 --- a/storage/country.cpp +++ b/storage/country.cpp @@ -179,8 +179,8 @@ class StoreTwoComponentMwmInterface { public: virtual ~StoreTwoComponentMwmInterface() = default; - virtual void Insert(string const & id, uint32_t mapSize, uint32_t /* routingSize */, size_t depth, - TCountryId const & parent) = 0; + virtual Country * Insert(string const & id, uint32_t mapSize, uint32_t /* routingSize */, size_t depth, + TCountryId const & parent) = 0; }; class StoreCountriesTwoComponentMwms : public StoreTwoComponentMwmInterface @@ -195,8 +195,8 @@ public: } // StoreTwoComponentMwmInterface overrides: - void Insert(string const & id, uint32_t mapSize, uint32_t routingSize, size_t depth, - TCountryId const & parent) override + virtual Country * Insert(string const & id, uint32_t mapSize, uint32_t routingSize, size_t depth, + TCountryId const & parent) override { Country country(id, parent); if (mapSize) @@ -205,7 +205,7 @@ public: countryFile.SetRemoteSizes(mapSize, routingSize); country.SetFile(countryFile); } - m_countries.AddAtDepth(depth, country); + return &m_countries.AddAtDepth(depth, country); } }; @@ -218,20 +218,21 @@ public: StoreFile2InfoTwoComponentMwms(map & file2info) : m_file2info(file2info) {} // StoreTwoComponentMwmInterface overrides: - void Insert(string const & id, uint32_t mapSize, uint32_t /* routingSize */, size_t /* depth */, - TCountryId const & /* parent */) override + virtual Country * Insert(string const & id, uint32_t mapSize, uint32_t /* routingSize */, size_t /* depth */, + TCountryId const & /* parent */) override { if (mapSize == 0) - return; + return nullptr; CountryInfo info(id); m_file2info[id] = info; + return nullptr; } }; } // namespace -void LoadGroupTwoComponentMwmsImpl(size_t depth, json_t * node, TCountryId const & parent, - StoreTwoComponentMwmInterface & store) +TMwmSubtreeAttrs LoadGroupTwoComponentMwmsImpl(size_t depth, json_t * node, TCountryId const & parent, + StoreTwoComponentMwmInterface & store) { // @TODO(bykoianko) After we stop supporting two component mwms (with routing files) // remove code below. @@ -247,13 +248,32 @@ void LoadGroupTwoComponentMwmsImpl(size_t depth, json_t * node, TCountryId const ASSERT_LESS_OR_EQUAL(0, mwmSize, ()); ASSERT_LESS_OR_EQUAL(0, routingSize, ()); - store.Insert(file, static_cast(mwmSize), static_cast(routingSize), depth, - parent); + Country * addedNode = store.Insert(file, static_cast(mwmSize), static_cast(routingSize), + depth, parent); + uint32_t countryCounter = 0; + size_t countrySize = 0; vector children; my::FromJSONObjectOptionalField(node, "g", children); - for (json_t * child : children) - LoadGroupTwoComponentMwmsImpl(depth + 1, child, file, store); + if (children.empty()) + { + countryCounter = 1; // It's a leaf. Any leaf contains one mwm. + countrySize = mwmSize + routingSize; + } + else + { + for (json_t * child : children) + { + TMwmSubtreeAttrs const childAttr = LoadGroupTwoComponentMwmsImpl(depth + 1, child, file, store); + countryCounter += childAttr.first; + countrySize += childAttr.second; + } + } + + if (addedNode != nullptr) + addedNode->SetSubtreeAttrs(countryCounter, countrySize); + + return make_pair(countryCounter, countrySize); } bool LoadCountriesTwoComponentMwmsImpl(string const & jsonBuffer,