{"id":291651,"date":"2019-06-11T08:09:28","date_gmt":"2019-06-11T08:09:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=291651"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=291651","title":{"rendered":"\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041e\u043f\u0430\u0441\u043d\u044b\u0439 \u0431\u0430\u0433 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 C++ std::map::merge \u0438 std::set::merge \u0432 Visual Studio 2017"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u0415\u0441\u043b\u0438 \u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 C++17 \u0432 MS Visual Studio 2017 \u2014 \u0431\u0443\u0434\u044c\u0442\u0435 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u044b: \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0431\u0430\u0433 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 std::map::merge \u0438 std::set::merge. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u2014 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u041a\u0430\u043a \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0433?<\/h3>\n<p>  <\/p>\n<ol>\n<li>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c std::map::merge \u0438 std::set::merge \u0432\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c N*log(size()+N)), \u0433\u0434\u0435 N \u2014 \u0440\u0430\u0437\u043c\u0435\u0440 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e N \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0435.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e merge \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u2014 \u043f\u0440\u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c stack overflow.<\/li>\n<li>\u041a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0431\u043e\u0442\u044b merge \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f.<\/li>\n<\/ol>\n<p>  <\/p>\n<h3>\u0427\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 Microsoft?<\/h3>\n<p>  <a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/543975\/stdmapmarge-has-critical-bug.html\">\u0411\u0430\u0433\u0440\u0435\u043f\u043e\u0440\u0442<\/a> \u0431\u044b\u043b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043c\u043d\u043e\u0439 \u0432 Microsoft \u043f\u043e\u0447\u0442\u0438 2 \u043c\u0435\u0441\u044f\u0446\u0430 \u043d\u0430\u0437\u0430\u0434.<br \/>  \u0412 Visual Studio 2019 Update 2 Preview 2 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c.<\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Visual Studio 2017 15.9.12 \u043d\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440, \u0438, \u0441\u0443\u0434\u044f \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c, \u0436\u0434\u0430\u0442\u044c \u0435\u0449\u0435 \u0434\u043e\u043b\u0433\u043e\u2026<\/p>\n<p>  \u0411\u0430\u0433 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u043a\u0435 \u0446\u0432\u0435\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u0440\u0430\u0441\u043d\u043e-\u0447\u0451\u0440\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<h3>\u041a\u0430\u043a \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438?<\/h3>\n<p>  <\/p>\n<pre><code class=\"cpp\">\/\/#include \"pch.h\"  #include &lt;chrono&gt; #include &lt;string&gt; #include &lt;iostream&gt; #include &lt;map&gt; #include &lt;set&gt;   const size_t mainSize = 50'000; const size_t additionSize = mainSize;   auto getMainMap() {   std::map&lt;size_t, std::string&gt; result;   while( result.size() &lt; mainSize )     result.emplace(result.size(), \"SomeText\");    return result; }   auto getAdditionMap() {   std::map&lt;size_t, std::string&gt; result;   while ( result.size() &lt; additionSize )     result.emplace(mainSize + result.size(), \"SomeAdditionText\");    return result; }   int main() {   {     auto mainMap = getMainMap();     auto addition = getAdditionMap();      auto start = std::chrono::steady_clock::now();     for ( auto const &amp;elem : addition )       mainMap.emplace(elem);     auto end = std::chrono::steady_clock::now();      std::cout &lt;&lt; \"manual insertion with copy: \"               &lt;&lt; std::chrono::duration_cast&lt;std::chrono::microseconds&gt;(end - start).count()               &lt;&lt; std::endl;   }    {     auto mainMap = getMainMap();     auto addition = getAdditionMap();      auto start = std::chrono::steady_clock::now();     mainMap.merge(addition);     auto end = std::chrono::steady_clock::now();      std::cout &lt;&lt; \"std::map::merge: \"               &lt;&lt; std::chrono::duration_cast&lt;std::chrono::microseconds&gt;(end - start).count()               &lt;&lt; std::endl;   } \/\/ &lt;---- and stack overflow here because of incorrect mainMap after merge    return 0; } <\/code><\/pre>\n<p>  \u0412\u0430\u0440\u044c\u0438\u0440\u0443\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 mainSize, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u2014 \u043b\u0438\u0431\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043b\u0438\u0431\u043e \u0435\u0449\u0435 \u0438 \u043a\u0440\u0430\u0445.<\/p>\n<h3>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c?<\/h3>\n<p>  \u041f\u0435\u0440\u0435\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a merge \u0440\u0443\u0447\u043d\u043e\u0439 \u0432\u0441\u0442\u0430\u0432\u043a\u043e\u0439. \u041b\u0438\u0431\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 VS 2019.<br \/>  \u0410 \u0435\u0441\u043b\u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0443\u0436\u0435 \u0443\u0448\u0451\u043b \u043a \u0437\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0443\u2026 \u041e\u0445\u0445\u0445\u2026<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/455632\/\"> https:\/\/habr.com\/ru\/post\/455632\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u0415\u0441\u043b\u0438 \u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 C++17 \u0432 MS Visual Studio 2017 \u2014 \u0431\u0443\u0434\u044c\u0442\u0435 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u044b: \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0431\u0430\u0433 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 std::map::merge \u0438 std::set::merge. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u2014 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-291651","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=291651"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291651\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}