{"id":40833,"date":"2025-05-30T11:16:14","date_gmt":"2025-05-30T03:16:14","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/40833.html"},"modified":"2025-05-30T11:16:14","modified_gmt":"2025-05-30T03:16:14","slug":"c%e5%ae%b9%e5%99%a8%e8%bf%9b%e9%98%b6%ef%bc%9a%e6%b7%b1%e5%85%a5%e8%a7%a3%e6%9e%90unordered_map%e4%b8%8eunordered_set%e7%9a%84%e5%89%8d%e4%b8%96%e4%bb%8a%e7%94%9f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/40833.html","title":{"rendered":"C++\u5bb9\u5668\u8fdb\u9636\uff1a\u6df1\u5165\u89e3\u6790unordered_map\u4e0eunordered_set\u7684\u524d\u4e16\u4eca\u751f"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%F0%9F%9A%80%20%E5%BC%95%E8%A8%80%EF%BC%9A%E7%8E%B0%E4%BB%A3C%2B%2B%E5%AE%B9%E5%99%A8%E7%9A%84%E7%8E%8B%E8%80%85-toc\" style=\"margin-left:40px\">&#x1f680; \u5f15\u8a00&#xff1a;\u73b0\u4ee3C&#043;&#043;\u5bb9\u5668\u7684\u738b\u8005<\/p>\n<p id=\"%F0%9F%8E%AF%20%E5%AD%A6%E4%B9%A0%E8%B7%AF%E5%BE%84-toc\" style=\"margin-left:80px\">&#x1f3af; \u5b66\u4e60\u8def\u5f84<\/p>\n<p id=\"%E7%AC%AC%E4%B8%80%E7%AB%A0%EF%BC%9A%E5%93%88%E5%B8%8C%E8%A1%A8%E7%9A%84%E6%95%B0%E5%AD%A6%E9%AD%94%E6%B3%95-toc\" style=\"margin-left:40px\">\u7b2c\u4e00\u7ae0&#xff1a;\u54c8\u5e0c\u8868\u7684\u6570\u5b66\u9b54\u6cd5<\/p>\n<p id=\"1.1%20%E5%93%88%E5%B8%8C%E8%A1%A8%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:80px\">1.1 \u54c8\u5e0c\u8868\u7684\u57fa\u672c\u6982\u5ff5<\/p>\n<p id=\"%E5%93%88%E5%B8%8C%E8%A1%A8%E7%9A%84%E6%95%B0%E5%AD%A6%E6%A8%A1%E5%9E%8B-toc\" style=\"margin-left:120px\">\u54c8\u5e0c\u8868\u7684\u6570\u5b66\u6a21\u578b<\/p>\n<p id=\"1.2%20%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%E7%9A%84%E8%AE%BE%E8%AE%A1%E8%89%BA%E6%9C%AF-toc\" style=\"margin-left:80px\">1.2 \u54c8\u5e0c\u51fd\u6570\u7684\u8bbe\u8ba1\u827a\u672f<\/p>\n<p id=\"%E7%AC%AC%E4%BA%8C%E7%AB%A0%EF%BC%9Aunordered_map%E7%9A%84%E6%B7%B1%E5%BA%A6%E8%A7%A3%E6%9E%90-toc\" style=\"margin-left:40px\">\u7b2c\u4e8c\u7ae0&#xff1a;unordered_map\u7684\u6df1\u5ea6\u89e3\u6790<\/p>\n<p id=\"2.1%20unordered_map%E7%9A%84%E8%AE%BE%E8%AE%A1%E5%93%B2%E5%AD%A6-toc\" style=\"margin-left:80px\">2.1 unordered_map\u7684\u8bbe\u8ba1\u54f2\u5b66<\/p>\n<p id=\"2.2%20unordered_map%E7%9A%84%E5%85%B8%E5%9E%8B%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:80px\">2.2 unordered_map\u7684\u5178\u578b\u4f7f\u7528\u573a\u666f<\/p>\n<p id=\"2.3%20unordered_map%E7%9A%84%E5%86%85%E9%83%A8%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86-toc\" style=\"margin-left:80px\">2.3 unordered_map\u7684\u5185\u90e8\u5b9e\u73b0\u539f\u7406<\/p>\n<p id=\"%E7%AC%AC%E4%B8%89%E7%AB%A0%EF%BC%9Aunordered_set%E7%9A%84%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86-toc\" style=\"margin-left:40px\">\u7b2c\u4e09\u7ae0&#xff1a;unordered_set\u7684\u5b9e\u73b0\u539f\u7406<\/p>\n<p id=\"3.1%20unordered_set%E7%9A%84%E5%9F%BA%E6%9C%AC%E7%89%B9%E5%BE%81-toc\" style=\"margin-left:80px\">3.1 unordered_set\u7684\u57fa\u672c\u7279\u5f81<\/p>\n<p id=\"3.2%20unordered_set%E7%9A%84%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8-toc\" style=\"margin-left:80px\">3.2 unordered_set\u7684\u5b9e\u9645\u5e94\u7528<\/p>\n<p id=\"%E7%AC%AC%E5%9B%9B%E7%AB%A0%EF%BC%9A%E6%80%A7%E8%83%BD%E5%88%86%E6%9E%90%E4%B8%8E%E4%BC%98%E5%8C%96-toc\" style=\"margin-left:40px\">\u7b2c\u56db\u7ae0&#xff1a;\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316<\/p>\n<p id=\"4.1%20%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6%E5%AF%B9%E6%AF%94-toc\" style=\"margin-left:80px\">4.1 \u65f6\u95f4\u590d\u6742\u5ea6\u5bf9\u6bd4<\/p>\n<p id=\"4.2%20%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E6%8A%80%E5%B7%A7-toc\" style=\"margin-left:80px\">4.2 \u6027\u80fd\u4f18\u5316\u6280\u5de7<\/p>\n<p id=\"%E7%AC%AC%E4%BA%94%E7%AB%A0%EF%BC%9A%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:40px\">\u7b2c\u4e94\u7ae0&#xff1a;\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/p>\n<p id=\"5.1%20%E7%BC%93%E5%AD%98%E7%B3%BB%E7%BB%9F-toc\" style=\"margin-left:80px\">5.1 \u7f13\u5b58\u7cfb\u7edf<\/p>\n<p id=\"5.2%20%E8%AF%8D%E9%A2%91%E7%BB%9F%E8%AE%A1-toc\" style=\"margin-left:80px\">5.2 \u8bcd\u9891\u7edf\u8ba1<\/p>\n<p id=\"%E7%AC%AC%E5%85%AD%E7%AB%A0%EF%BC%9A%E9%AB%98%E7%BA%A7%E4%B8%BB%E9%A2%98-toc\" style=\"margin-left:40px\">\u7b2c\u516d\u7ae0&#xff1a;\u9ad8\u7ea7\u4e3b\u9898<\/p>\n<p id=\"6.1%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:80px\">6.1 \u81ea\u5b9a\u4e49\u54c8\u5e0c\u51fd\u6570<\/p>\n<p id=\"%E7%AC%AC%E4%B8%83%E7%AB%A0%EF%BC%9A%E5%93%88%E5%B8%8C%E5%86%B2%E7%AA%81%E7%9A%84%E6%B7%B1%E5%BA%A6%E8%A7%A3%E6%9E%90-toc\" style=\"margin-left:40px\">\u7b2c\u4e03\u7ae0&#xff1a;\u54c8\u5e0c\u51b2\u7a81\u7684\u6df1\u5ea6\u89e3\u6790<\/p>\n<p id=\"7.1%20%E5%93%88%E5%B8%8C%E5%86%B2%E7%AA%81%E7%9A%84%E6%9C%AC%E8%B4%A8-toc\" style=\"margin-left:80px\">7.1 \u54c8\u5e0c\u51b2\u7a81\u7684\u672c\u8d28<\/p>\n<p id=\"%E5%93%88%E5%B8%8C%E5%86%B2%E7%AA%81%E7%9A%84%E6%95%B0%E5%AD%A6%E6%A8%A1%E5%9E%8B-toc\" style=\"margin-left:120px\">\u54c8\u5e0c\u51b2\u7a81\u7684\u6570\u5b66\u6a21\u578b<\/p>\n<p id=\"7.2%20%E5%86%B2%E7%AA%81%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%E8%AF%A6%E8%A7%A3-toc\" style=\"margin-left:80px\">7.2 \u51b2\u7a81\u89e3\u51b3\u65b9\u6848\u8be6\u89e3<\/p>\n<p id=\"7.2.1%20%E9%93%BE%E5%9C%B0%E5%9D%80%E6%B3%95%EF%BC%88%E6%8B%89%E9%93%BE%E6%B3%95%EF%BC%89-toc\" style=\"margin-left:120px\">7.2.1 \u94fe\u5730\u5740\u6cd5&#xff08;\u62c9\u94fe\u6cd5&#xff09;<\/p>\n<p id=\"7.2.2%20%E5%BC%80%E6%94%BE%E5%AF%BB%E5%9D%80%E6%B3%95-toc\" style=\"margin-left:120px\">7.2.2 \u5f00\u653e\u5bfb\u5740\u6cd5<\/p>\n<p id=\"%E7%AC%AC%E5%85%AB%E7%AB%A0%EF%BC%9A%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E7%9A%84%E8%89%BA%E6%9C%AF-toc\" style=\"margin-left:40px\">\u7b2c\u516b\u7ae0&#xff1a;\u5185\u5b58\u7ba1\u7406\u7684\u827a\u672f<\/p>\n<p id=\"8.1%20%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D%E7%AD%96%E7%95%A5-toc\" style=\"margin-left:80px\">8.1 \u5185\u5b58\u5206\u914d\u7b56\u7565<\/p>\n<p id=\"8.1.1%20%E9%A2%84%E5%88%86%E9%85%8D%E5%86%85%E5%AD%98-toc\" style=\"margin-left:120px\">8.1.1 \u9884\u5206\u914d\u5185\u5b58<\/p>\n<p id=\"8.2%20%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90%E4%B8%8E%E7%BC%93%E5%AD%98%E5%8F%8B%E5%A5%BD-toc\" style=\"margin-left:80px\">8.2 \u5185\u5b58\u5bf9\u9f50\u4e0e\u7f13\u5b58\u53cb\u597d<\/p>\n<p id=\"-toc\" style=\"margin-left:40px\">\n<p id=\"%E7%BB%93%E8%AF%AD-toc\" style=\"margin-left:40px\">\u7ed3\u8bed<\/p>\n<p id=\"%E6%8E%A8%E8%8D%90%E9%98%85%E8%AF%BB-toc\" style=\"margin-left:40px\">\u63a8\u8350\u9605\u8bfb<\/p>\n<hr id=\"hr-toc\" \/>\n<h3>&#x1f680; \u5f15\u8a00&#xff1a;\u73b0\u4ee3C&#043;&#043;\u5bb9\u5668\u7684\u738b\u8005<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"140\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530031613-683922fdc3516.png\" width=\"263\" \/><\/p>\n<p>\u5728C&#043;&#043;\u7684\u6d69\u701a\u661f\u7a7a\u4e2d&#xff0c;unordered_map\u548cunordered_set\u5c31\u50cf\u4e24\u9897\u7480\u74a8\u7684\u660e\u73e0&#xff0c;\u5b83\u4eecrevolutionize\u4e86\u6211\u4eec\u5904\u7406\u5173\u8054\u5bb9\u5668\u7684\u65b9\u5f0f\u3002\u672c\u6587\u5c06\u5e26\u4f60\u7a7f\u8d8a\u8fd9\u4e24\u4e2a\u5bb9\u5668\u7684\u5185\u90e8\u4e16\u754c&#xff0c;\u63ed\u793a\u5b83\u4eec\u7684\u8bbe\u8ba1\u54f2\u5b66\u3001\u5b9e\u73b0\u539f\u7406\u548c\u5e94\u7528\u9b54\u6cd5&#xff01;<\/p>\n<h4 id=\"%F0%9F%8E%AF%20%E5%AD%A6%E4%B9%A0%E8%B7%AF%E5%BE%84\">&#x1f3af; \u5b66\u4e60\u8def\u5f84<\/h4>\n<ul>\n<li>\n<p>\u7406\u89e3\u54c8\u5e0c\u8868\u7684\u5185\u90e8\u673a\u5236<\/p>\n<\/li>\n<li>\n<p>\u638c\u63e1unordered_map\u548cunordered_set\u7684\u4f7f\u7528<\/p>\n<\/li>\n<li>\n<p>\u6df1\u5165\u63a2\u7d22\u5b83\u4eec\u7684\u6027\u80fd\u7279\u5f81<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u6218\u9879\u76ee\u5b9e\u8df5<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"%E7%AC%AC%E4%B8%80%E7%AB%A0%EF%BC%9A%E5%93%88%E5%B8%8C%E8%A1%A8%E7%9A%84%E6%95%B0%E5%AD%A6%E9%AD%94%E6%B3%95\">\u7b2c\u4e00\u7ae0&#xff1a;\u54c8\u5e0c\u8868\u7684\u6570\u5b66\u9b54\u6cd5&#xff08;C&#043;&#043;&#xff09;<\/h3>\n<h4 id=\"1.1%20%E5%93%88%E5%B8%8C%E8%A1%A8%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\">1.1 \u54c8\u5e0c\u8868\u7684\u57fa\u672c\u6982\u5ff5<\/h4>\n<p>\u54c8\u5e0c\u8868\u662f\u73b0\u4ee3\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\u6700\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\u4e4b\u4e00\u3002\u5b83\u901a\u8fc7\u4e00\u4e2a\u795e\u5947\u7684&#034;\u54c8\u5e0c\u51fd\u6570&#034;&#xff0c;\u5c06\u952e\u6620\u5c04\u5230\u7279\u5b9a\u7684\u5b58\u50a8\u4f4d\u7f6e&#xff0c;\u5b9e\u73b0\u4e86\u8fd1\u4e4eO(1)\u7684\u67e5\u627e\u3001\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u3002<\/p>\n<h5 id=\"%E5%93%88%E5%B8%8C%E8%A1%A8%E7%9A%84%E6%95%B0%E5%AD%A6%E6%A8%A1%E5%9E%8B\">\u54c8\u5e0c\u8868\u7684\u6570\u5b66\u6a21\u578b<\/h5>\n<p>\u8bbe\u8ba1\u4e00\u4e2a\u5b8c\u7f8e\u7684\u54c8\u5e0c\u8868\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u6570\u5b66\u539f\u7406&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u54c8\u5e0c\u51fd\u6570\u7684\u5747\u5300\u5206\u5e03\u6027<\/p>\n<\/li>\n<li>\n<p>\u51b2\u7a81\u89e3\u51b3\u7b56\u7565<\/p>\n<\/li>\n<li>\n<p>\u8d1f\u8f7d\u56e0\u5b50\u7684\u5e73\u8861<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"1.2%20%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0%E7%9A%84%E8%AE%BE%E8%AE%A1%E8%89%BA%E6%9C%AF\">1.2 \u54c8\u5e0c\u51fd\u6570\u7684\u8bbe\u8ba1\u827a\u672f<\/h4>\n<p>\/\/ \u7b80\u5355\u54c8\u5e0c\u51fd\u6570\u793a\u4f8b<br \/>\nsize_t simpleHash(const std::string&amp; key) {<br \/>\n    size_t hash &#061; 0;<br \/>\n    for (char c : key) {<br \/>\n        hash &#061; hash * 31 &#043; c;<br \/>\n    }<br \/>\n    return hash;<br \/>\n}<\/p>\n<p>\/\/ \u73b0\u4ee3\u54c8\u5e0c\u51fd\u6570&#xff08;\u6a21\u677f\u7248\u672c&#xff09;<br \/>\ntemplate &lt;typename T&gt;<br \/>\nstruct HashFunction {<br \/>\n    size_t operator()(const T&amp; key) const {<br \/>\n        return std::hash&lt;T&gt;{}(key);<br \/>\n    }<br \/>\n};<\/p>\n<h3 id=\"%E7%AC%AC%E4%BA%8C%E7%AB%A0%EF%BC%9Aunordered_map%E7%9A%84%E6%B7%B1%E5%BA%A6%E8%A7%A3%E6%9E%90\">\u7b2c\u4e8c\u7ae0&#xff1a;unordered_map\u7684\u6df1\u5ea6\u89e3\u6790<\/h3>\n<h4 id=\"2.1%20unordered_map%E7%9A%84%E8%AE%BE%E8%AE%A1%E5%93%B2%E5%AD%A6\">2.1 unordered_map\u7684\u8bbe\u8ba1\u54f2\u5b66<\/h4>\n<p>unordered_map\u662f\u57fa\u4e8e\u54c8\u5e0c\u8868\u5b9e\u73b0\u7684\u5173\u8054\u5bb9\u5668&#xff0c;\u5177\u6709\u4ee5\u4e0b\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u952e\u503c\u5bf9\u5b58\u50a8<\/p>\n<\/li>\n<li>\n<p>\u5e73\u5747O(1)\u7684\u67e5\u627e\u3001\u63d2\u5165\u548c\u5220\u9664<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u4fdd\u8bc1\u5143\u7d20\u987a\u5e8f<\/p>\n<\/li>\n<li>\n<p>\u5141\u8bb8\u81ea\u5b9a\u4e49\u54c8\u5e0c\u51fd\u6570<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"2.2%20unordered_map%E7%9A%84%E5%85%B8%E5%9E%8B%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF\">2.2 unordered_map\u7684\u5178\u578b\u4f7f\u7528\u573a\u666f<\/h4>\n<p>\/\/ \u7528\u6237\u4fe1\u606f\u7f13\u5b58<br \/>\nstd::unordered_map&lt;std::string, UserInfo&gt; userCache;<\/p>\n<p>\/\/ \u63d2\u5165\u64cd\u4f5c<br \/>\nuserCache[&#034;john_doe&#034;] &#061; {<br \/>\n    &#034;John Doe&#034;,<br \/>\n    25,<br \/>\n    &#034;Software Engineer&#034;<br \/>\n};<\/p>\n<p>\/\/ \u67e5\u627e\u64cd\u4f5c<br \/>\nauto it &#061; userCache.find(&#034;john_doe&#034;);<br \/>\nif (it !&#061; userCache.end()) {<br \/>\n    std::cout &lt;&lt; &#034;User found: &#034; &lt;&lt; it-&gt;second.name &lt;&lt; std::endl;<br \/>\n}<\/p>\n<h4 id=\"2.3%20unordered_map%E7%9A%84%E5%86%85%E9%83%A8%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86\">2.3 unordered_map\u7684\u5185\u90e8\u5b9e\u73b0\u539f\u7406<\/h4>\n<p>template &lt;typename Key, typename Value, typename Hash &#061; std::hash&lt;Key&gt;&gt;<br \/>\nclass MyUnorderedMap {<br \/>\nprivate:<br \/>\n    \/\/ \u5185\u90e8\u6876\u6570\u7ec4<br \/>\n    std::vector&lt;std::list&lt;std::pair&lt;Key, Value&gt;&gt;&gt; buckets;<\/p>\n<p>    \/\/ \u54c8\u5e0c\u51fd\u6570<br \/>\n    Hash hashFunc;<\/p>\n<p>    \/\/ \u8ba1\u7b97\u6876\u7684\u7d22\u5f15<br \/>\n    size_t getBucketIndex(const Key&amp; key) {<br \/>\n        return hashFunc(key) % buckets.size();<br \/>\n    }<\/p>\n<p>public:<br \/>\n    \/\/ \u63d2\u5165\u64cd\u4f5c<br \/>\n    void insert(const std::pair&lt;Key, Value&gt;&amp; kvPair) {<br \/>\n        size_t index &#061; getBucketIndex(kvPair.first);<br \/>\n        auto&amp; bucket &#061; buckets[index];<\/p>\n<p>        \/\/ \u68c0\u67e5\u662f\u5426\u5df2\u5b58\u5728<br \/>\n        for (auto&amp; item : bucket) {<br \/>\n            if (item.first &#061;&#061; kvPair.first) {<br \/>\n                item.second &#061; kvPair.second;<br \/>\n                return;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        bucket.push_back(kvPair);<br \/>\n    }<br \/>\n};<\/p>\n<h3 id=\"%E7%AC%AC%E4%B8%89%E7%AB%A0%EF%BC%9Aunordered_set%E7%9A%84%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86\">\u7b2c\u4e09\u7ae0&#xff1a;unordered_set\u7684\u5b9e\u73b0\u539f\u7406<\/h3>\n<h4 id=\"3.1%20unordered_set%E7%9A%84%E5%9F%BA%E6%9C%AC%E7%89%B9%E5%BE%81\">3.1 unordered_set\u7684\u57fa\u672c\u7279\u5f81<\/h4>\n<p>unordered_set\u662f\u53ea\u5b58\u50a8\u552f\u4e00\u952e\u7684\u54c8\u5e0c\u5bb9\u5668&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5143\u7d20\u552f\u4e00<\/p>\n<\/li>\n<li>\n<p>\u5e73\u5747O(1)\u7684\u63d2\u5165\u548c\u67e5\u627e<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u4fdd\u8bc1\u5143\u7d20\u987a\u5e8f<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301\u81ea\u5b9a\u4e49\u54c8\u5e0c\u51fd\u6570<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"3.2%20unordered_set%E7%9A%84%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8\">3.2 unordered_set\u7684\u5b9e\u9645\u5e94\u7528<\/h4>\n<p>\/\/ \u53bb\u91cd\u573a\u666f<br \/>\nstd::unordered_set&lt;std::string&gt; uniqueWords;<\/p>\n<p>\/\/ \u63d2\u5165\u5143\u7d20<br \/>\nuniqueWords.insert(&#034;hello&#034;);<br \/>\nuniqueWords.insert(&#034;world&#034;);<br \/>\nuniqueWords.insert(&#034;hello&#034;);  \/\/ \u4e0d\u4f1a\u91cd\u590d\u63d2\u5165<\/p>\n<p>\/\/ \u67e5\u627e\u64cd\u4f5c<br \/>\nif (uniqueWords.count(&#034;hello&#034;) &gt; 0) {<br \/>\n    std::cout &lt;&lt; &#034;\u627e\u5230\u5143\u7d20&#034; &lt;&lt; std::endl;<br \/>\n}<\/p>\n<h3 id=\"%E7%AC%AC%E5%9B%9B%E7%AB%A0%EF%BC%9A%E6%80%A7%E8%83%BD%E5%88%86%E6%9E%90%E4%B8%8E%E4%BC%98%E5%8C%96\">\u7b2c\u56db\u7ae0&#xff1a;\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316<\/h3>\n<h4 id=\"4.1%20%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6%E5%AF%B9%E6%AF%94\">4.1 \u65f6\u95f4\u590d\u6742\u5ea6\u5bf9\u6bd4<\/h4>\n<table>\n<tr>\u64cd\u4f5cunordered_mapmapunordered_setset<\/tr>\n<tbody>\n<tr>\n<td>\u63d2\u5165<\/td>\n<td>O(1)\u5e73\u5747<\/td>\n<td>O(log n)<\/td>\n<td>O(1)\u5e73\u5747<\/td>\n<td>O(log n)<\/td>\n<\/tr>\n<tr>\n<td>\u67e5\u627e<\/td>\n<td>O(1)\u5e73\u5747<\/td>\n<td>O(log n)<\/td>\n<td>O(1)\u5e73\u5747<\/td>\n<td>O(log n)<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664<\/td>\n<td>O(1)\u5e73\u5747<\/td>\n<td>O(log n)<\/td>\n<td>O(1)\u5e73\u5747<\/td>\n<td>O(log n)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 id=\"4.2%20%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E6%8A%80%E5%B7%A7\">4.2 \u6027\u80fd\u4f18\u5316\u6280\u5de7<\/h4>\n<li>\n<p>\u9884\u5206\u914d\u6876\u7684\u5927\u5c0f<\/p>\n<\/li>\n<li>\n<p>\u81ea\u5b9a\u4e49\u9ad8\u6548\u7684\u54c8\u5e0c\u51fd\u6570<\/p>\n<\/li>\n<li>\n<p>\u5408\u7406\u8bbe\u7f6e\u8d1f\u8f7d\u56e0\u5b50<\/p>\n<\/li>\n<li>\n<p>\u907f\u514d\u9891\u7e41\u6269\u5bb9<\/p>\n<\/li>\n<p>\/\/ \u6027\u80fd\u4f18\u5316\u793a\u4f8b<br \/>\nstd::unordered_map&lt;std::string, int&gt; performanceMap;<br \/>\nperformanceMap.reserve(1000);  \/\/ \u9884\u5206\u914d\u7a7a\u95f4<\/p>\n<h3 id=\"%E7%AC%AC%E4%BA%94%E7%AB%A0%EF%BC%9A%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF\">\u7b2c\u4e94\u7ae0&#xff1a;\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h3>\n<h4 id=\"5.1%20%E7%BC%93%E5%AD%98%E7%B3%BB%E7%BB%9F\">5.1 \u7f13\u5b58\u7cfb\u7edf<\/h4>\n<p>class LRUCache {<br \/>\nprivate:<br \/>\n    std::unordered_map&lt;int, int&gt; cache;<br \/>\n    std::list&lt;int&gt; lruList;<br \/>\n    int capacity;<\/p>\n<p>public:<br \/>\n    void put(int key, int value) {<br \/>\n        if (cache.size() &gt;&#061; capacity) {<br \/>\n            \/\/ \u79fb\u9664\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7684\u5143\u7d20<br \/>\n            int lruKey &#061; lruList.front();<br \/>\n            cache.erase(lruKey);<br \/>\n            lruList.pop_front();<br \/>\n        }<\/p>\n<p>        cache[key] &#061; value;<br \/>\n        lruList.push_back(key);<br \/>\n    }<br \/>\n};<\/p>\n<h4 id=\"5.2%20%E8%AF%8D%E9%A2%91%E7%BB%9F%E8%AE%A1\">5.2 \u8bcd\u9891\u7edf\u8ba1<\/h4>\n<p>std::unordered_map&lt;std::string, int&gt; wordFrequency;<\/p>\n<p>void countWords(const std::string&amp; text) {<br \/>\n    std::istringstream iss(text);<br \/>\n    std::string word;<\/p>\n<p>    while (iss &gt;&gt; word) {<br \/>\n        wordFrequency[word]&#043;&#043;;<br \/>\n    }<br \/>\n}<\/p>\n<h3 id=\"%E7%AC%AC%E5%85%AD%E7%AB%A0%EF%BC%9A%E9%AB%98%E7%BA%A7%E4%B8%BB%E9%A2%98\">\u7b2c\u516d\u7ae0&#xff1a;\u9ad8\u7ea7\u4e3b\u9898<\/h3>\n<h4 id=\"6.1%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%93%88%E5%B8%8C%E5%87%BD%E6%95%B0\">6.1 \u81ea\u5b9a\u4e49\u54c8\u5e0c\u51fd\u6570<\/h4>\n<p>struct Point {<br \/>\n    int x, y;<\/p>\n<p>    \/\/ \u81ea\u5b9a\u4e49\u54c8\u5e0c\u51fd\u6570<br \/>\n    size_t hash() const {<br \/>\n        return std::hash&lt;int&gt;{}(x) ^ (std::hash&lt;int&gt;{}(y) &lt;&lt; 1);<br \/>\n    }<br \/>\n};<\/p>\n<p>\/\/ \u7279\u5316\u6807\u51c6\u54c8\u5e0c<br \/>\nnamespace std {<br \/>\n    template &lt;&gt;<br \/>\n    struct hash&lt;Point&gt; {<br \/>\n        size_t operator()(const Point&amp; p) const {<br \/>\n            return p.hash();<br \/>\n        }<br \/>\n    };<br \/>\n}<\/p>\n<h3 id=\"%E7%AC%AC%E4%B8%83%E7%AB%A0%EF%BC%9A%E5%93%88%E5%B8%8C%E5%86%B2%E7%AA%81%E7%9A%84%E6%B7%B1%E5%BA%A6%E8%A7%A3%E6%9E%90\">\u7b2c\u4e03\u7ae0&#xff1a;\u54c8\u5e0c\u51b2\u7a81\u7684\u6df1\u5ea6\u89e3\u6790<\/h3>\n<h4 id=\"7.1%20%E5%93%88%E5%B8%8C%E5%86%B2%E7%AA%81%E7%9A%84%E6%9C%AC%E8%B4%A8\">7.1 \u54c8\u5e0c\u51b2\u7a81\u7684\u672c\u8d28<\/h4>\n<p>\u54c8\u5e0c\u51b2\u7a81\u662f\u6307\u4e0d\u540c\u7684\u952e\u7ecf\u8fc7\u54c8\u5e0c\u51fd\u6570\u8ba1\u7b97\u540e\u5f97\u5230\u76f8\u540c\u7684\u5b58\u50a8\u4f4d\u7f6e\u3002\u8fd9\u662f\u54c8\u5e0c\u8868\u5b9e\u73b0\u4e2d\u6700\u6838\u5fc3\u7684\u6311\u6218\u4e4b\u4e00\u3002<\/p>\n<h5 id=\"%E5%93%88%E5%B8%8C%E5%86%B2%E7%AA%81%E7%9A%84%E6%95%B0%E5%AD%A6%E6%A8%A1%E5%9E%8B\">\u54c8\u5e0c\u51b2\u7a81\u7684\u6570\u5b66\u6a21\u578b<\/h5>\n<p>\u8bbe\u8ba1\u4e00\u4e2a\u4f18\u79c0\u7684\u54c8\u5e0c\u51fd\u6570\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u6570\u5b66\u539f\u7406&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5747\u5300\u5206\u5e03\u6027<\/p>\n<\/li>\n<li>\n<p>\u786e\u5b9a\u6027<\/p>\n<\/li>\n<li>\n<p>\u4f4e\u78b0\u649e\u6982\u7387<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"7.2%20%E5%86%B2%E7%AA%81%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%E8%AF%A6%E8%A7%A3\">7.2 \u51b2\u7a81\u89e3\u51b3\u65b9\u6848\u8be6\u89e3<\/h4>\n<h5 id=\"7.2.1%20%E9%93%BE%E5%9C%B0%E5%9D%80%E6%B3%95%EF%BC%88%E6%8B%89%E9%93%BE%E6%B3%95%EF%BC%89\">7.2.1 \u94fe\u5730\u5740\u6cd5&#xff08;\u62c9\u94fe\u6cd5&#xff09;<\/h5>\n<p>template &lt;typename Key, typename Value&gt;<br \/>\nclass HashTable {<br \/>\nprivate:<br \/>\n    \/\/ \u4f7f\u7528\u94fe\u8868\u6570\u7ec4\u89e3\u51b3\u51b2\u7a81<br \/>\n    std::vector&lt;std::list&lt;std::pair&lt;Key, Value&gt;&gt;&gt; buckets;<\/p>\n<p>    \/\/ \u54c8\u5e0c\u51fd\u6570<br \/>\n    size_t hash(const Key&amp; key) {<br \/>\n        return std::hash&lt;Key&gt;{}(key) % buckets.size();<br \/>\n    }<\/p>\n<p>public:<br \/>\n    void insert(const Key&amp; key, const Value&amp; value) {<br \/>\n        size_t index &#061; hash(key);<br \/>\n        auto&amp; bucket &#061; buckets[index];<\/p>\n<p>        \/\/ \u68c0\u67e5\u662f\u5426\u5df2\u5b58\u5728<br \/>\n        for (auto&amp; item : bucket) {<br \/>\n            if (item.first &#061;&#061; key) {<br \/>\n                item.second &#061; value;<br \/>\n                return;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        \/\/ \u4e0d\u5b58\u5728\u5219\u6dfb\u52a0<br \/>\n        bucket.emplace_back(key, value);<br \/>\n    }<\/p>\n<p>    \/\/ \u67e5\u627e\u64cd\u4f5c<br \/>\n    Value* find(const Key&amp; key) {<br \/>\n        size_t index &#061; hash(key);<br \/>\n        auto&amp; bucket &#061; buckets[index];<\/p>\n<p>        for (auto&amp; item : bucket) {<br \/>\n            if (item.first &#061;&#061; key) {<br \/>\n                return &amp;item.second;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        return nullptr;<br \/>\n    }<br \/>\n};<\/p>\n<h5 id=\"7.2.2%20%E5%BC%80%E6%94%BE%E5%AF%BB%E5%9D%80%E6%B3%95\">7.2.2 \u5f00\u653e\u5bfb\u5740\u6cd5<\/h5>\n<p>template &lt;typename Key, typename Value&gt;<br \/>\nclass OpenAddressingHashTable {<br \/>\nprivate:<br \/>\n    struct Entry {<br \/>\n        Key key;<br \/>\n        Value value;<br \/>\n        bool occupied;<\/p>\n<p>        Entry() : occupied(false) {}<br \/>\n    };<\/p>\n<p>    std::vector&lt;Entry&gt; table;<br \/>\n    size_t size;<br \/>\n    size_t capacity;<\/p>\n<p>    \/\/ \u7ebf\u6027\u63a2\u6d4b<br \/>\n    size_t findSlot(const Key&amp; key) {<br \/>\n        size_t index &#061; std::hash&lt;Key&gt;{}(key) % capacity;<br \/>\n        size_t originalIndex &#061; index;<\/p>\n<p>        do {<br \/>\n            if (!table[index].occupied || table[index].key &#061;&#061; key) {<br \/>\n                return index;<br \/>\n            }<br \/>\n            index &#061; (index &#043; 1) % capacity;<br \/>\n        } while (index !&#061; originalIndex);<\/p>\n<p>        \/\/ \u8868\u5df2\u6ee1<br \/>\n        throw std::runtime_error(&#034;Hash table is full&#034;);<br \/>\n    }<\/p>\n<p>public:<br \/>\n    OpenAddressingHashTable(size_t initialCapacity &#061; 16)<br \/>\n        : table(initialCapacity), size(0), capacity(initialCapacity) {}<\/p>\n<p>    void insert(const Key&amp; key, const Value&amp; value) {<br \/>\n        \/\/ \u8d1f\u8f7d\u56e0\u5b50\u63a7\u5236<br \/>\n        if (static_cast&lt;double&gt;(size) \/ capacity &gt; 0.75) {<br \/>\n            rehash();<br \/>\n        }<\/p>\n<p>        size_t index &#061; findSlot(key);<\/p>\n<p>        if (!table[index].occupied) {<br \/>\n            table[index].key &#061; key;<br \/>\n            table[index].value &#061; value;<br \/>\n            table[index].occupied &#061; true;<br \/>\n            size&#043;&#043;;<br \/>\n        } else {<br \/>\n            \/\/ \u66f4\u65b0\u5df2\u5b58\u5728\u7684\u503c<br \/>\n            table[index].value &#061; value;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u91cd\u54c8\u5e0c&#xff1a;\u6269\u5bb9<br \/>\n    void rehash() {<br \/>\n        size_t newCapacity &#061; capacity * 2;<br \/>\n        std::vector&lt;Entry&gt; newTable(newCapacity);<\/p>\n<p>        \/\/ \u91cd\u65b0\u63d2\u5165\u6240\u6709\u5143\u7d20<br \/>\n        for (const auto&amp; entry : table) {<br \/>\n            if (entry.occupied) {<br \/>\n                size_t index &#061; std::hash&lt;Key&gt;{}(entry.key) % newCapacity;<\/p>\n<p>                while (newTable[index].occupied) {<br \/>\n                    index &#061; (index &#043; 1) % newCapacity;<br \/>\n                }<\/p>\n<p>                newTable[index] &#061; entry;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        table &#061; std::move(newTable);<br \/>\n        capacity &#061; newCapacity;<br \/>\n    }<br \/>\n};<\/p>\n<h3 id=\"%E7%AC%AC%E5%85%AB%E7%AB%A0%EF%BC%9A%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E7%9A%84%E8%89%BA%E6%9C%AF\">\u7b2c\u516b\u7ae0&#xff1a;\u5185\u5b58\u7ba1\u7406\u7684\u827a\u672f<\/h3>\n<h4 id=\"8.1%20%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D%E7%AD%96%E7%95%A5\">8.1 \u5185\u5b58\u5206\u914d\u7b56\u7565<\/h4>\n<h5 id=\"8.1.1%20%E9%A2%84%E5%88%86%E9%85%8D%E5%86%85%E5%AD%98\">8.1.1 \u9884\u5206\u914d\u5185\u5b58<\/h5>\n<p>class MemoryOptimizedHashMap {<br \/>\nprivate:<br \/>\n    \/\/ \u4f7f\u7528\u5185\u5b58\u6c60\u51cf\u5c11\u52a8\u6001\u5206\u914d\u5f00\u9500<br \/>\n    std::vector&lt;std::pair&lt;Key, Value&gt;&gt; memoryPool;<br \/>\n    size_t poolSize;<\/p>\n<p>public:<br \/>\n    MemoryOptimizedHashMap(size_t initialSize &#061; 1024) {<br \/>\n        \/\/ \u9884\u5206\u914d\u5185\u5b58<br \/>\n        memoryPool.reserve(initialSize);<br \/>\n    }<\/p>\n<p>    void optimizedInsert(const Key&amp; key, const Value&amp; value) {<br \/>\n        \/\/ \u76f4\u63a5\u5728\u5185\u5b58\u6c60\u4e2d\u6784\u9020<br \/>\n        memoryPool.emplace_back(key, value);<br \/>\n    }<br \/>\n};<\/p>\n<h4 id=\"8.2%20%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90%E4%B8%8E%E7%BC%93%E5%AD%98%E5%8F%8B%E5%A5%BD\">8.2 \u5185\u5b58\u5bf9\u9f50\u4e0e\u7f13\u5b58\u53cb\u597d<\/h4>\n<p>\/\/ \u7f13\u5b58\u53cb\u597d\u7684\u6570\u636e\u7ed3\u6784<br \/>\nstruct alignas(64) CacheOptimizedEntry {<br \/>\n    Key key;<br \/>\n    Value value;<br \/>\n    std::atomic&lt;bool&gt; lock;<br \/>\n};<\/p>\n<h3 id=\"\"><\/h3>\n<h3 id=\"%E7%BB%93%E8%AF%AD\" style=\"background-color:transparent\">\u7ed3\u8bed<\/h3>\n<p>unordered_map\u548cunordered_set\u4e0d\u4ec5\u4ec5\u662f\u5bb9\u5668&#xff0c;\u66f4\u662f\u73b0\u4ee3C&#043;&#043;\u7f16\u7a0b\u4e2d\u7684\u7470\u5b9d\u3002\u5b83\u4eec\u4f53\u73b0\u4e86\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\u9ad8\u6548\u3001\u7075\u6d3b\u7684\u8bbe\u8ba1\u54f2\u5b66\u3002\u613f\u6bcf\u4e00\u4f4d\u8bfb\u8005\u90fd\u80fd\u5728\u63a2\u7d22\u7684\u65c5\u7a0b\u4e2d&#xff0c;\u627e\u5230\u5c5e\u4e8e\u81ea\u5df1\u7684\u7f16\u7a0b\u4e4b\u7f8e&#xff01;&#x1f680;<\/p>\n<p>&#x1f449; \u70b9\u8d5e &#043; \u6536\u85cf &#061; \u7a0b\u5e8f\u5458\u8fdb\u9636\u4e4b\u8def&#xff01;<\/p>\n<h3 id=\"%E6%8E%A8%E8%8D%90%E9%98%85%E8%AF%BB\">\u63a8\u8350\u9605\u8bfb<\/h3>\n<ul>\n<li>\n<p>\u300a\u6df1\u5165\u5e94\u7528C&#043;&#043;11\u300b &#8211; \u9648\u7855<\/p>\n<\/li>\n<li>\n<p>\u300aEffective Modern C&#043;&#043;\u300b &#8211; Scott Meyers<\/p>\n<\/li>\n<li>\n<p>\u300aC&#043;&#043; Primer\u300b &#8211; Stanley B. Lippman<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb596\u6b21\uff0c\u70b9\u8d5e21\u6b21\uff0c\u6536\u85cf28\u6b21\u3002\u672c\u6587\u6df1\u5165\u89e3\u6790C++\u4e2dunordered_map\u548cunordered_set\u7684\u5b9e\u73b0\u539f\u7406\u4e0e\u5e94\u7528\u3002\u9996\u5148\u4ecb\u7ecd\u54c8\u5e0c\u8868\u7684\u6570\u5b66\u57fa\u7840\u4e0e\u54c8\u5e0c\u51fd\u6570\u8bbe\u8ba1\u827a\u672f\uff0c\u91cd\u70b9\u8bb2\u89e3\u4e24\u79cd\u5bb9\u5668\u7684\u8bbe\u8ba1\u54f2\u5b66\u3001\u5178\u578b\u4f7f\u7528\u573a\u666f\u548c\u5185\u90e8\u5b9e\u73b0\u673a\u5236\u3002\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u5176\u6838\u5fc3\u64cd\u4f5c\uff0c\u5bf9\u6bd4\u5206\u6790\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u5e76\u63d0\u4f9b\u6027\u80fd\u4f18\u5316\u6280\u5de7\u3002\u6587\u7ae0\u8fd8\u6db5\u76d6\u5b9e\u9645\u5e94\u7528\u573a\u666f\u5982\u7f13\u5b58\u7cfb\u7edf\u548c\u8bcd\u9891\u7edf\u8ba1\uff0c\u6df1\u5165\u63a2\u8ba8\u54c8\u5e0c\u51b2\u7a81\u89e3\u51b3\u65b9\u6848\u548c\u5185\u5b58\u7ba1\u7406\u7b56\u7565\u3002\u6700\u540e\u63a8\u8350\u76f8\u5173\u8fdb\u9636\u4e66\u7c4d\uff0c\u5e2e\u52a9\u8bfb\u8005\u5145\u5206\u638c\u63e1\u8fd9\u4e24\u79cd\u9ad8\u6548\u5bb9\u5668\u7684\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n","protected":false},"author":2,"featured_media":40832,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,3520,427],"topic":[],"class_list":["post-40833","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-3520","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++\u5bb9\u5668\u8fdb\u9636\uff1a\u6df1\u5165\u89e3\u6790unordered_map\u4e0eunordered_set\u7684\u524d\u4e16\u4eca\u751f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/40833.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u5bb9\u5668\u8fdb\u9636\uff1a\u6df1\u5165\u89e3\u6790unordered_map\u4e0eunordered_set\u7684\u524d\u4e16\u4eca\u751f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb596\u6b21\uff0c\u70b9\u8d5e21\u6b21\uff0c\u6536\u85cf28\u6b21\u3002\u672c\u6587\u6df1\u5165\u89e3\u6790C++\u4e2dunordered_map\u548cunordered_set\u7684\u5b9e\u73b0\u539f\u7406\u4e0e\u5e94\u7528\u3002\u9996\u5148\u4ecb\u7ecd\u54c8\u5e0c\u8868\u7684\u6570\u5b66\u57fa\u7840\u4e0e\u54c8\u5e0c\u51fd\u6570\u8bbe\u8ba1\u827a\u672f\uff0c\u91cd\u70b9\u8bb2\u89e3\u4e24\u79cd\u5bb9\u5668\u7684\u8bbe\u8ba1\u54f2\u5b66\u3001\u5178\u578b\u4f7f\u7528\u573a\u666f\u548c\u5185\u90e8\u5b9e\u73b0\u673a\u5236\u3002\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u5176\u6838\u5fc3\u64cd\u4f5c\uff0c\u5bf9\u6bd4\u5206\u6790\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u5e76\u63d0\u4f9b\u6027\u80fd\u4f18\u5316\u6280\u5de7\u3002\u6587\u7ae0\u8fd8\u6db5\u76d6\u5b9e\u9645\u5e94\u7528\u573a\u666f\u5982\u7f13\u5b58\u7cfb\u7edf\u548c\u8bcd\u9891\u7edf\u8ba1\uff0c\u6df1\u5165\u63a2\u8ba8\u54c8\u5e0c\u51b2\u7a81\u89e3\u51b3\u65b9\u6848\u548c\u5185\u5b58\u7ba1\u7406\u7b56\u7565\u3002\u6700\u540e\u63a8\u8350\u76f8\u5173\u8fdb\u9636\u4e66\u7c4d\uff0c\u5e2e\u52a9\u8bfb\u8005\u5145\u5206\u638c\u63e1\u8fd9\u4e24\u79cd\u9ad8\u6548\u5bb9\u5668\u7684\u4f7f\u7528\u65b9\u6cd5\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/40833.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-30T03:16:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530031613-683922fdc3516.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40833.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/40833.html\",\"name\":\"C++\u5bb9\u5668\u8fdb\u9636\uff1a\u6df1\u5165\u89e3\u6790unordered_map\u4e0eunordered_set\u7684\u524d\u4e16\u4eca\u751f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-30T03:16:14+00:00\",\"dateModified\":\"2025-05-30T03:16:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/40833.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/40833.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40833.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++\u5bb9\u5668\u8fdb\u9636\uff1a\u6df1\u5165\u89e3\u6790unordered_map\u4e0eunordered_set\u7684\u524d\u4e16\u4eca\u751f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++\u5bb9\u5668\u8fdb\u9636\uff1a\u6df1\u5165\u89e3\u6790unordered_map\u4e0eunordered_set\u7684\u524d\u4e16\u4eca\u751f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/40833.html","og_locale":"zh_CN","og_type":"article","og_title":"C++\u5bb9\u5668\u8fdb\u9636\uff1a\u6df1\u5165\u89e3\u6790unordered_map\u4e0eunordered_set\u7684\u524d\u4e16\u4eca\u751f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb596\u6b21\uff0c\u70b9\u8d5e21\u6b21\uff0c\u6536\u85cf28\u6b21\u3002\u672c\u6587\u6df1\u5165\u89e3\u6790C++\u4e2dunordered_map\u548cunordered_set\u7684\u5b9e\u73b0\u539f\u7406\u4e0e\u5e94\u7528\u3002\u9996\u5148\u4ecb\u7ecd\u54c8\u5e0c\u8868\u7684\u6570\u5b66\u57fa\u7840\u4e0e\u54c8\u5e0c\u51fd\u6570\u8bbe\u8ba1\u827a\u672f\uff0c\u91cd\u70b9\u8bb2\u89e3\u4e24\u79cd\u5bb9\u5668\u7684\u8bbe\u8ba1\u54f2\u5b66\u3001\u5178\u578b\u4f7f\u7528\u573a\u666f\u548c\u5185\u90e8\u5b9e\u73b0\u673a\u5236\u3002\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u5176\u6838\u5fc3\u64cd\u4f5c\uff0c\u5bf9\u6bd4\u5206\u6790\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u5e76\u63d0\u4f9b\u6027\u80fd\u4f18\u5316\u6280\u5de7\u3002\u6587\u7ae0\u8fd8\u6db5\u76d6\u5b9e\u9645\u5e94\u7528\u573a\u666f\u5982\u7f13\u5b58\u7cfb\u7edf\u548c\u8bcd\u9891\u7edf\u8ba1\uff0c\u6df1\u5165\u63a2\u8ba8\u54c8\u5e0c\u51b2\u7a81\u89e3\u51b3\u65b9\u6848\u548c\u5185\u5b58\u7ba1\u7406\u7b56\u7565\u3002\u6700\u540e\u63a8\u8350\u76f8\u5173\u8fdb\u9636\u4e66\u7c4d\uff0c\u5e2e\u52a9\u8bfb\u8005\u5145\u5206\u638c\u63e1\u8fd9\u4e24\u79cd\u9ad8\u6548\u5bb9\u5668\u7684\u4f7f\u7528\u65b9\u6cd5\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/40833.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-30T03:16:14+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530031613-683922fdc3516.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/40833.html","url":"https:\/\/www.wsisp.com\/helps\/40833.html","name":"C++\u5bb9\u5668\u8fdb\u9636\uff1a\u6df1\u5165\u89e3\u6790unordered_map\u4e0eunordered_set\u7684\u524d\u4e16\u4eca\u751f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-30T03:16:14+00:00","dateModified":"2025-05-30T03:16:14+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/40833.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/40833.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/40833.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++\u5bb9\u5668\u8fdb\u9636\uff1a\u6df1\u5165\u89e3\u6790unordered_map\u4e0eunordered_set\u7684\u524d\u4e16\u4eca\u751f"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=40833"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40833\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/40832"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=40833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=40833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=40833"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=40833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}