{"id":40978,"date":"2025-05-30T12:27:07","date_gmt":"2025-05-30T04:27:07","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/40978.html"},"modified":"2025-05-30T12:27:07","modified_gmt":"2025-05-30T04:27:07","slug":"stl%ef%bc%9a%e4%bd%8d%e5%9b%be%e5%92%8c%e5%b8%83%e9%9a%86%e8%bf%87%e6%bb%a4%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/40978.html","title":{"rendered":"STL\uff1a\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668"},"content":{"rendered":"<h2 style=\"text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"322\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042702-68393396aa816.gif\" width=\"628\" \/><\/h2>\n<h2>\u4e00&#xff0c;\u4f4d\u56fe<\/h2>\n<h3>1.1 \u4f4d\u56fe\u7684\u6982\u5ff5<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u7a76\u7adf\u4ec0\u4e48\u662f\u4f4d\u56fe\u5462&#xff1f;&#xff1f;\u6211\u4eec\u7528\u4e00\u9053\u95ee\u9898\u6765\u5f15\u5165<\/p>\n<p><span style=\"color:#fe2c24\">\u95ee\u9898&#xff1a;\u7ed940\u4ebf\u4e2a\u4e0d\u91cd\u590d\u7684\u65e0\u7b26\u53f7\u6574\u6570&#xff0c;\u6ca1\u6392\u8fc7\u5e8f\u3002\u7ed9\u4e00\u4e2a\u65e0\u7b26\u53f7\u6574\u6570&#xff0c;\u5982\u4f55\u5feb\u901f\u5224\u65ad\u4e00\u4e2a\u6570\u662f\u5426\u5728 \u8fd940\u4ebf\u4e2a\u6570\u4e2d\u3002\u3010\u817e\u8baf\u3011<\/span><\/p>\n<p> \u6839\u636e\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7528\u4ec0\u4e48\u65b9\u6cd5\u6765\u89e3\u51b3\u5462&#xff1f;&#xff1f;&#xff1f;\u6211\u4eec\u53ef\u4ee5\u5f88\u8fc5\u901f\u5730\u60f3\u5230\u4e00\u4e0b\u65b9\u6cd5&#xff1a;<\/p>\n<p>\u65b9\u6cd51&#xff1a;\u6392\u5e8f&#043;\u4e8c\u5206\u67e5\u627e<\/p>\n<p>\u65b9\u6cd52&#xff1a;\u5c06\u6574\u6570\u4e22\u8fdb\u54c8\u5e0c\u8868\u6216\u8005\u7ea2\u9ed1\u6811\u4e2d<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<span style=\"color:#fe2c24\"> \u770b\u4f3c\u597d\u50cf\u90fd\u80fd\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u4f46\u662f\u6211\u4eec\u6765\u5ba1\u89c6\u4e00\u4e0b\u8fd9\u4e2a\u95ee\u9898\u7684\u5173\u952e\u2014\u2014\u5185\u5b58<\/span><\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<span style=\"color:#fe2c24\">1G&#061;1024MB&#061;1024*1024KB&#061;1024*1024*1024Byte \u7ea6\u7b49\u4e8e10\u4ebfByte&#xff0c;\u4e5f\u5c31\u662f\u8bf440\u4ebf\u4e2a\u6570\u5927\u7ea6\u9700\u898116G\u5185\u5b58&#xff01;&#xff01;\u6ca1\u6709\u529e\u6cd5\u5c06\u6570\u636e\u4e00\u6b21\u6027\u653e\u5230\u5185\u5b58\u53bb\u5904\u7406\u3002<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 &#xff08;1&#xff09;\u5206\u6790\u65b9\u6cd51&#xff1a;\u5982\u679c\u6211\u4eec\u5c06\u6570\u636e\u5206\u5728\u4e0d\u540c\u7684\u6587\u4ef6\u91cc&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7528\u5f52\u5e76\u6392\u5e8f\u53bb\u5b8c\u6210\u6587\u4ef6\u4e4b\u95f4\u7684\u6392\u5e8f&#xff0c;\u4f46\u662f\u65e0\u6cd5\u4f7f\u7528\u4e8c\u5206\u67e5\u627e\u6cd5&#xff0c;<\/span><span style=\"color:#ff9900\">\u56e0\u4e3a\u6ca1\u6709\u529e\u6cd5\u901a\u8fc7\u4e0b\u6807\u53bb\u76f4\u63a5\u8bbf\u95ee\u5143\u7d20<\/span><span style=\"color:#fe2c24\">&#xff01;&#xff01;&#xff01;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 &#xff08;2&#xff09;\u5206\u6790\u65b9\u6cd52&#xff1a;\u95ee\u9898\u5c31\u662f\u6240\u9700\u8981\u7684\u5185\u5b58\u592a\u5927\u4e86&#xff0c;\u5149\u662f\u6570\u636e\u5c3116G\u4e86&#xff0c;\u66f4\u4f55\u51b5\u7ea2\u9ed1\u6811\u548c\u54c8\u5e0c\u8868\u7684\u5e95\u5c42\u7684\u5c01\u88c5\u8fd8\u9700\u8981\u4e00\u5b9a\u7684\u635f\u8017&#xff0c;\u6211\u4eec\u5982\u679c\u8981\u4f7f\u7528\u7684\u8bdd\u4e5f\u53ea\u80fd\u662f\u4e00\u90e8\u5206\u4e00\u90e8\u5206\u4e22\u8fdb\u5bb9\u5668&#xff0c;\u7136\u540e\u518d\u5220\u6389\u4e22\u4e0b\u4e00\u90e8\u5206&#xff0c;<\/span><span style=\"color:#ff9900\">\u8fd9\u6837\u4e00\u65b9\u9762\u7684\u95ee\u9898\u662f\u6211\u4eec\u5176\u5b9e\u5728\u4e00\u5f00\u59cb\u4e22\u8fdb\u5bb9\u5668\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u53bb\u505a\u6bd4\u5bf9\u4e86&#xff0c;\u6ca1\u6709\u5fc5\u8981\u4e22\u5230\u5bb9\u5668\u91cc&#xff0c;\u53e6\u4e00\u65b9\u9762\u7684\u95ee\u9898\u5c31\u662f\u4e0d\u9002\u5e94\u9700\u8981\u591a\u6b21\u67e5\u627e\u6bd4\u5bf9\u7684\u573a\u666f\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u00a0 \u00a0 \u00a0 \u56e0\u6b64\u4e0a\u9762\u4e24\u79cd\u65b9\u6cd5\u90fd\u662f\u4e0d\u592a\u73b0\u5b9e\u7684&#xff0c;\u4f46\u662f\u6709\u4e00\u79cd\u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u90a3\u5c31\u662f<\/span><span style=\"color:#fe2c24\">\u4f4d\u56fe\u2014\u2014\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u4e2d\u7684\u76f4\u63a5\u5b9a\u5740\u6cd5\u786e\u5b9a\u6574\u578b\u5728\u4e0d\u5728\u7684\u6a21\u578b&#xff08;<\/span><span style=\"color:#ff9900\">\u5c31\u662f\u7528\u6bcf\u4e00\u4f4d\u6765\u5b58\u653e\u67d0\u79cd\u72b6\u6001&#xff0c;\u9002\u7528\u4e8e\u6d77\u91cf\u6570\u636e&#xff0c;\u6570\u636e\u65e0\u91cd\u590d\u7684\u573a\u666f\u3002\u901a\u5e38\u662f\u7528\u6765\u5224\u65ad\u67d0\u4e2a\u6570\u636e\u5b58\u4e0d\u5b58\u5728\u7684\u3002<\/span><span style=\"color:#fe2c24\">&#xff09;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 \u00a0<\/span><span style=\"color:#0d0016\">\u00a0\u6240\u4ee5\u65b9\u6cd53&#xff1a;\u7528\u4f4d\u56fe\u53bb\u89e3\u51b3\u00a0\u00a0<\/span><\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u6570\u636e\u662f\u5426\u5728\u7ed9\u5b9a\u7684\u6574\u5f62\u6570\u636e\u4e2d&#xff0c;\u7ed3\u679c\u662f\u5728\u6216\u8005\u4e0d\u5728&#xff0c;\u521a\u597d\u662f\u4e24\u79cd\u72b6\u6001&#xff0c;\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6bd4\u7279\u4f4d\u6765\u4ee3\u8868\u6570\u636e\u662f\u5426\u5b58\u5728\u7684\u4fe1\u606f&#xff0c;\u5982\u679c\u4e8c\u8fdb\u5236\u6bd4\u7279\u4f4d\u4e3a1&#xff0c;\u4ee3\u8868\u5b58\u5728&#xff0c;\u4e3a0\u4ee3\u8868\u4e0d\u5b58\u5728\u3002\u6bd4\u5982&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"319\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042702-68393396baa75.png\" width=\"845\" \/><\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0<span style=\"color:#fe2c24\">\u4f60\u53ef\u80fd\u4f1a\u6709\u8fd9\u6837\u7684\u7591\u60d1&#xff0c;\u4e3a\u4ec0\u4e48\u4e0a\u9762\u7684\u6392\u5e03\u662f\u53cd\u7740\u6765\u7684&#xff0c;\u5373\u4ece7\u2014&gt;1&#xff0c;\u4f46\u5176\u5b9e\u8fd9\u6837\u624d\u662f\u7b26\u5408\u6211\u4eec\u7684\u4eba\u4e3a\u7684\u8ba4\u77e5\u7684&#xff0c;\u6bd4\u59821234&#xff0c;\u53f3\u8fb9\u7684\u662f\u4f4e\u4f4d&#xff0c;\u5de6\u8fb9\u624d\u662f\u9ad8\u4f4d\u3002\u5728\u8ba1\u7b97\u673a\u4e2d\u5177\u4f53\u662f\u600e\u4e48\u6392\u5e03\u7684\u6211\u4eec\u4e0d\u5f97\u800c\u77e5&#xff0c;\u56e0\u4e3a\u90a3\u5c5e\u4e8e\u5185\u5b58\u5c42&#xff0c;\u662f\u6211\u4eec\u770b\u4e0d\u5230\u7684&#xff0c;\u6211\u4eec\u80fd\u770b\u5230\u7684\u53ea\u662f\u8ba1\u7b97\u673a\u7ed9\u6211\u4eec\u5c55\u73b0\u7684\u865a\u62df\u5c42&#xff0c;\u6bd4\u5982\u8bf4\u6211\u4eec\u7684\u76d1\u89c6\u7a97\u53e3\u548c\u5185\u5b58\u7a97\u53e3&#xff0c;\u6bcf\u4e2abit\u4f4d\u90fd\u662f\u5de6\u9ad8\u53f3\u4f4e\u7684\u6392\u5e03&#xff0c;\u7b26\u5408\u6211\u4eec\u4eba\u7684\u4e00\u4e2a\u60ef\u6027\u3002\u00a0 <\/span><span style=\"color:#4da8ee\">\u800c\u6211\u4eec\u7684\u5de6\u79fb\u8fd0\u7b97\u7b26 \u5176\u5b9e\u5c31\u662f\u4ece\u4f4e\u4f4d-&gt;\u9ad8\u4f4d\u00a0 \u800c\u53f3\u79fb\u8fd0\u7b97\u7b26 \u5176\u5b9e\u662f\u4ece\u9ad8\u4f4d-&gt;\u4f4e\u4f4d\u3002<\/span><\/p>\n<h3>\u00a01.2 \u4f4d\u56fe\u7684\u5b9e\u73b0<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u9996\u5148&#xff0c;\u6211\u4eec\u7684STL\u5bb9\u5668\u4e2d\u662f\u6709\u4f4d\u56fe\u8fd9\u4e2a\u5bb9\u5668\u7684&#xff0c;\u540d\u5b57\u53eb\u505abitset\u3002<\/p>\n<h4>1.2.1 \u57fa\u672c\u7ed3\u6784<\/h4>\n<p>template&lt;size_t N&gt; \/\/\u975e\u7c7b\u578b\u6a21\u677f\u53c2\u6570   N\u8868\u793a\u9700\u8981\u5f00\u7684\u4f4d\u56fe\u7684\u5927\u5c0f<br \/>\nclass bitset<br \/>\n{<br \/>\npublic:<\/p>\n<p>private:<br \/>\nvector&lt;char&gt; _bits;<br \/>\n}; <\/p>\n<p>\u00a0 \u00a0 \u00a0 \u6211\u4eec\u9700\u8981\u53bb\u63a7\u5236\u6bd4\u7279\u4f4d&#xff0c;\u6240\u4ee5\u9009\u62e9char\u4f5c\u4e3a\u6211\u4eec\u7684\u7c7b\u578b\u662f\u6700\u5408\u9002\u7684&#xff0c;\u5176\u4e2dN\u662f\u975e\u7c7b\u578b\u6a21\u677f\u53c2\u6570&#xff0c;\u8868\u660e\u4f4d\u56fe\u5177\u4f53\u5f00\u591a\u5927\u3002<\/p>\n<h4>1.2.2 \u6784\u9020\u51fd\u6570<\/h4>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u6211\u4eec\u5177\u4f53\u5e94\u8be5\u5f00\u591a\u5927&#xff0c;\u81ea\u7136\u662f\u53d6\u51b3\u4e8e\u6211\u4eec\u7684\u5143\u7d20\u6570\u91cf\u7684&#xff0c;\u65e2\u7136\u6211\u4eec\u4e00\u4e2achar\u67098\u4e2abit\u4f4d&#xff0c;\u81ea\u7136\u5c31\u53ef\u4ee5\u8868\u793a8\u4e2a\u6574\u6570&#xff0c;\u4f46\u662f\u9700\u8981\u6ce8\u610f\u7684\u4e00\u4e2a\u539f\u5219\u662f&#xff1a;<span style=\"color:#fe2c24\">\u5b81\u53ef\u5f00\u591a\u4e0d\u53ef\u5f00\u5c11\u3002<\/span><span style=\"color:#0d0016\">\u56e0\u4e3a\u5047\u8bbe\u662f10&#xff0c;\u9664\u4ee58\u4e4b\u540e\u4f59\u6570\u4f1a\u88ab\u5e72\u6389&#xff0c;\u56e0\u6b64\u6211\u4eec<\/span><span style=\"color:#fe2c24\">\u6700\u540e\u4e00\u5b9a\u8fd8\u8981\u52a0\u4e0a\u4e00\u4e2a1<\/span><\/p>\n<p>bitset()<br \/>\n{<br \/>\n_bits.resize(N \/ 8 &#043; 1, 0); \/\/\u53ea\u80fd\u5f00\u591a\u4e0d\u80fd\u5f00\u5c11<br \/>\n} <\/p>\n<h4>1.2.3 set<\/h4>\n<p>\u00a0 \u00a0 \u00a0 \u00a0set\u7684\u4f5c\u7528&#xff0c;\u5c31\u662f\u5c06\u67d0\u4e00\u4f4d\u8bbe\u7f6e\u62101<\/p>\n<p>void set(size_t x) \/\/\u8bbe\u7f6e\u62101<br \/>\n{<br \/>\nsize_t i &#061; x \/ 8;\/\/\u8ba1\u7b97x\u6620\u5c04\u7684\u4f4dchar\u5728\u7b2ci\u4e2a\u6570\u7ec4\u7684\u4f4d\u7f6e<br \/>\nsize_t j &#061; x % 8;\/\/\u8ba1\u7b97x\u6620\u5c04\u7684\u4f4d\u5728\u8fd9\u4e2achar\u7684\u7b2cj\u4e2a\u6bd4\u7279\u4f4d<br \/>\n\/\/\u6309\u4f4d\u6216   &lt;&lt;\u5de6\u79fb\u662f\u4f4e-&gt;\u9ad8<br \/>\n_bits[i] |&#061; (1 &lt;&lt; j);<br \/>\n} <\/p>\n<p><span style=\"color:#fe2c24\">size_t i &#061; x \/ 8;\/\/\u8ba1\u7b97x\u6620\u5c04\u7684\u4f4dchar\u5728\u7b2ci\u4e2a\u6570\u7ec4\u7684\u4f4d\u7f6e size_t j &#061; x % 8;\/\/\u8ba1\u7b97x\u6620\u5c04\u7684\u4f4d\u5728\u8fd9\u4e2achar\u7684\u7b2cj\u4e2a\u6bd4\u7279\u4f4d<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u00a0 \u00a0 \u00a0 \u00a0\u63a5\u4e0b\u6765\u6211\u4eec\u8981\u5224\u65ad\u7684\u95ee\u9898\u5c31\u662f&#xff0c;\u5982\u4f55\u5c06\u8be5\u4f4d\u8bbe\u7f6e\u4e3a1-&gt;\u5229\u7528\u4f4d\u8fd0\u7b97\u7684\u6027\u8d28 \u53ea\u8981j\u5bf9\u5e94\u7684\u4f4d\u7f6e\u6309\u4f4d\u6216\u4e0a0\u2026\u20261\u2026\u20260 &#xff08;1\u5de6\u79fbj\u4f4d\u5f97\u5230&#xff09;\u5373\u53ef<\/span><\/p>\n<h4><span style=\"color:#0d0016\">1.2.4 reset<\/span><\/h4>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0reset\u7684\u4f5c\u7528&#xff0c;\u5c31\u662f\u5c06\u67d0\u4e00\u4f4d\u8bbe\u7f6e\u62100<\/p>\n<p>void reset(size_t x)\/\/\u8bbe\u7f6e\u62100<br \/>\n{<br \/>\nsize_t i &#061; x \/ 8;\/\/\u8ba1\u7b97x\u6620\u5c04\u7684\u4f4dchar\u5728\u7b2ci\u4e2a\u6570\u7ec4\u7684\u4f4d\u7f6e<br \/>\nsize_t j &#061; x % 8;\/\/\u8ba1\u7b97x\u6620\u5c04\u7684\u4f4d\u5728\u8fd9\u4e2achar\u7684\u7b2cj\u4e2a\u6bd4\u7279\u4f4d<br \/>\n\/\/\u6309\u4f4d\u4e0e<br \/>\n_bits[i] &amp;&#061; ~(1 &lt;&lt; j);<br \/>\n} <\/p>\n<p><span style=\"color:#0d0016\">\u00a0 \u00a0 \u00a0 \u00a0 \u63a5\u4e0b\u6765\u6211\u4eec\u8981\u5224\u65ad\u7684\u95ee\u9898\u5c31\u662f&#xff0c;\u5982\u4f55\u5c06\u8be5\u4f4d\u8bbe\u7f6e\u4e3a0-&gt;\u5229\u7528\u4f4d\u8fd0\u7b97\u7684\u6027\u8d28 \u53ea\u8981j\u5bf9\u5e94\u7684\u4f4d\u7f6e\u6309\u4f4d\u6216\u4e0a1\u2026\u20260\u2026\u20261\u00a0&#xff08;1\u5de6\u79fbj\u4f4d\u518d\u53d6\u53cd\u5f97\u5230&#xff09;\u5373\u53ef<\/span><\/p>\n<h4><span style=\"color:#0d0016\">1.2.5 test<\/span><\/h4>\n<p><span style=\"color:#0d0016\">\u00a0 \u00a0\u00a0<\/span><span style=\"color:#0d0016\">test\u7684\u4f5c\u7528&#xff0c;\u5c31\u662f\u5224\u65ad\u67d0\u4e00\u4f4d\u662f\u5426\u4e3a1&#xff08;\u5373\u8be5\u6574\u6570\u5728\u4e0d\u5728&#xff09;<\/span><\/p>\n<p>bool test(size_t x) \/\/x\u5728\u4e0d\u5728  \u5224\u65ad\u8fd9\u4e00\u4f4d\u662f0\u8fd8\u662f1<br \/>\n{<br \/>\nsize_t i &#061; x \/ 8;\/\/\u8ba1\u7b97x\u6620\u5c04\u7684\u4f4dchar\u5728\u7b2ci\u4e2a\u6570\u7ec4\u7684\u4f4d\u7f6e<br \/>\nsize_t j &#061; x % 8;\/\/\u8ba1\u7b97x\u6620\u5c04\u7684\u4f4d\u5728\u8fd9\u4e2achar\u7684\u7b2cj\u4e2a\u6bd4\u7279\u4f4d<br \/>\nreturn _bits[i] &amp; (1 &lt;&lt; j);<br \/>\n} <\/p>\n<p>\u00a0 \u00a0 \u00a0 \u8fd8\u8981\u6309\u4f4d\u4e0e\u4e0a0\u2026\u20261\u2026\u20260&#xff0c;\u90a3\u4e48\u9664\u4e86\u7b2cj\u4f4d \u5176\u4ed6\u4f4d\u90fd\u4f1a\u662f0 \u90a3\u4e48\u7b2cj\u4f4d\u5982\u679c\u4e5f\u662f0 \u7ed3\u679c\u5c31\u4f1a\u662f0&#xff0c;\u5982\u679c\u662f1 \u90a3\u4e48\u7ed3\u679c\u5c31\u662f\u975e0.<\/p>\n<h4>1.2.6 \u4f4d\u56fe\u5f00\u6ee1\u7a7a\u95f4\u7684\u65b9\u6cd5<\/h4>\n<p>bitset&lt;-1&gt; bs;\/\/\u5f00\u6ee1\u7684\u65b9\u6cd5<br \/>\nbitset&lt;0xFFFFFFFF&gt; bs; <\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0-1\u5f3a\u8f6c\u6210size_t \u7c7b\u578b\u7684\u65f6\u5019\u5c31\u662f\u65e0\u7b26\u53f7\u6574\u578b\u7684\u6700\u5927\u503c&#xff0c;\u800c0xFFFFFFFF\u5219\u662f16\u8fdb\u5236\u4e0b\u7684\u65e0\u7b26\u53f7\u6574\u578b\u6700\u5927\u503c\u3002<\/p>\n<h3>1.3 \u4f4d\u56fe\u7684\u5e94\u7528<\/h3>\n<p>1. \u5feb\u901f\u67e5\u627e\u67d0\u4e2a\u6570\u636e\u662f\u5426\u5728\u4e00\u4e2a\u96c6\u5408\u4e2d<\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 \u00a0 \u00a0 \u4e00\u822c\u9002\u7528\u4e8e\u6574\u578b<\/span> 2. \u6392\u5e8f &#043; \u53bb\u91cd<\/p>\n<p>\u00a0 \u00a0 \u00a0 <span style=\"color:#fe2c24\">\u00a0\u53ef\u4ee5\u5c06\u4e00\u5806\u5143\u7d20\u90fd\u4e22\u8fdb\u4f4d\u56fe\u4e2d&#xff0c;\u5982\u679c\u5bf9\u5e94\u4f4d\u7f6e\u539f\u6765\u4e3a0\u7684\u8bdd&#xff0c;\u5c31\u53d8\u62101&#xff0c;\u5982\u679c\u539f\u6765\u4f4d\u7f6e\u539f\u6765\u4e3a1\u7684\u8bdd&#xff0c;\u5c31\u4e0d\u5904\u7406&#xff0c;\u7136\u540e\u6211\u4eec\u518d\u901a\u8fc7\u6620\u5c04\u5173\u7cfb\u5c06\u5143\u7d20\u8fd8\u539f\u56de\u6765&#xff0c;\u5c31\u5b8c\u6210\u4e86\u6392\u5e8f&#043;\u53bb\u91cd<\/span> 3. \u6c42\u4e24\u4e2a\u96c6\u5408\u7684\u4ea4\u96c6\u3001\u5e76\u96c6\u7b49<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0<span style=\"color:#fe2c24\">\u8fd9\u8fb9\u6709\u4e24\u79cd\u601d\u8def&#xff1a;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">1\u3001\u5c06\u4e24\u4e2a\u96c6\u5408\u5206\u522b\u653e\u5728\u4e24\u4e2a\u4f4d\u56fe\u4e2d&#xff0c;\u5206\u522b\u5b8c\u6210\u6392\u5e8f\u548c\u53bb\u91cd&#xff0c;\u7136\u540e\u518d\u4e00\u4e2a\u4e2a\u53bb\u6bd4\u5bf9\u3002<\/span><\/p>\n<p><span style=\"color:#fe2c24\">2\u3001\u5148\u5c06\u5176\u4e2d\u4e00\u4e2a\u96c6\u5408\u653e\u8fdb\u4f4d\u56fe\u4e2d&#xff0c;\u7136\u540e\u518d\u901a\u8fc7\u53e6\u4e00\u4e2a\u96c6\u5408\u53bb\u5224\u65ad&#xff0c;\u5982\u679c\u4f4d\u56fe\u4e2d\u4e3a1&#xff0c;\u8bf4\u660e\u8be5\u6570\u5c31\u662f\u4ea4\u96c6&#xff0c;<\/span><span style=\"color:#ff9900\">\u4f46\u662f\u4e3a\u4e86\u9632\u6b62\u96c6\u5408\u51fa\u73b0\u91cd\u590d\u6570\u5b57&#xff0c;\u6211\u4eec\u6b64\u65f6\u5c06\u8be5\u4f4d\u7f6e\u53d8\u62100&#xff08;\u6539\u8fdb\u65b9\u6cd5&#xff09;<\/span><span style=\"color:#fe2c24\">.<\/span><\/p>\n<p>\u00a0 \u00a0\u00a0 \u00a0 <span style=\"color:#4da8ee\">\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5&#xff0c;\u4f46\u662f<\/span><span style=\"color:#ff9900\">\u7b2c\u4e00\u79cd\u65b9\u6cd5<\/span><span style=\"color:#4da8ee\">\u6709\u4e24\u4e2a\u95ee\u9898&#xff0c;\u4e00\u4e2a\u662f<\/span><span style=\"color:#fe2c24\">\u7a7a\u95f4\u7684\u6d88\u8017\u592a\u5927<\/span><span style=\"color:#4da8ee\">&#xff0c;\u53e6\u4e00\u4e2a\u5c31\u662f\u65e0<\/span><span style=\"color:#fe2c24\">\u8bba\u8fd9\u4e2a\u96c6\u5408\u591a\u5927&#xff0c;\u6211\u4eec\u90fd\u9700\u8981\u5c06\u6240\u6709\u7684\u4f4d\u7f6e\u90fd\u904d\u5386\u5b8c\u4e86\u624d\u53ef\u4ee5\u786e\u5b9a<\/span><span style=\"color:#4da8ee\">&#xff0c;\u56e0\u4e3a\u6211\u4eec\u5e76\u4e0d\u6e05\u695a\u96c6\u5408\u91cc\u5143\u7d20\u7684\u8303\u56f4\u3002 \u800c<\/span><span style=\"color:#ff9900\">\u7b2c\u4e8c\u79cd\u65b9\u6cd5<\/span><span style=\"color:#4da8ee\">\u53ef\u4ee5\u6709\u6548\u6539\u8fdb\u4e0a\u9762\u4e24\u4e2a\u95ee\u9898&#xff0c;\u4e0d\u4ec5<\/span><span style=\"color:#fe2c24\">\u7a7a\u95f4\u6d88\u8017\u51cf\u5c11<\/span><span style=\"color:#4da8ee\">&#xff0c;\u800c\u4e14\u6211\u4eec<\/span><span style=\"color:#fe2c24\">\u53ea\u9700\u8981\u5224\u65ad\u96c6\u54082\u7684\u5143\u7d20\u662f\u5426\u5728\u4f4d\u56fe\u4e2d\u51fa\u73b0\u8fc7\u5373\u53ef<\/span><span style=\"color:#4da8ee\">&#xff0c;\u80af\u5b9a\u6bd4\u904d\u5386\u5168\u90e8\u4f4d\u7f6e\u6548\u7387\u9ad8\u3002\u00a0 \u53e6\u4e00\u65b9\u9762\u7531\u4e8e\u96c6\u54082\u6ca1\u6709\u8fdb\u884c\u53bb\u91cd&#xff0c;\u6240\u4ee5\u53ef\u80fd\u4f1a\u51fa\u73b0\u91cd\u590d\u5143\u7d20&#xff0c;\u4f46\u662f\u901a\u8fc7\u6211\u4eec\u7684<\/span><span style=\"color:#fe2c24\">\u6539\u8fdb\u65b9\u6cd5\u2014\u2014\u5373\u53d1\u73b0\u4ea4\u96c6\u7684\u65f6\u5019&#xff0c;\u5c06\u539f\u5148\u4f4d\u56fe\u7684\u4f4d\u7f6e\u53d8\u62100\u5c31\u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u00a0\u00a0<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 \u00a0 \u00a0\u00a0<\/span><span style=\"color:#fe2c24\">\u603b\u7ed3&#xff1a;\u5982\u679c\u6570\u636e\u91cf\u8fbe\u5230\u4ebf\u7ea7\u522b&#xff0c;\u53ef\u80fd\u7528\u7b2c\u4e00\u79cd\u6bd4\u8f83\u5408\u9002&#xff0c;\u4f46\u662f\u5927\u591a\u6570\u60c5\u51b5\u4e0b&#xff0c;\u7b2c\u4e8c\u79cd\u663e\u7136\u662f\u66f4\u5408\u9002\u7684&#xff01;&#xff01;<\/span><\/p>\n<p><span style=\"color:#0d0016\">4.\u6570\u636e\u76f8\u5bf9\u96c6\u4e2d\u65f6\u7684\u7edf\u8ba1\u6b21\u6570<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u00a0 \u00a0 \u00a0<\/span><span style=\"color:#fe2c24\">\u5047\u8bbe\u8bf4\u6211\u4eec\u5df2\u77e5\u6570\u636e\u53ea\u6709\u53ef\u80fd\u51fa\u73b0\u2018a\u2019-&gt;\u2018z\u2019 \u6b64\u65f6\u6211\u4eec\u53d1\u73b0\u4e5f\u5c3126\u79cd\u53ef\u80fd\u6027&#xff0c;\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u4e5f\u4e0d\u9700\u8981\u5355\u72ec\u53bb\u5c01\u88c5\u4e00\u4e2a\u4f4d\u56fe&#xff0c;\u76f4\u63a5\u7528\u4e00\u4e2a\u6574\u578b\u5c31\u53ef\u4ee5\u89e3\u51b3\u95ee\u9898&#xff01;&#xff01;<\/span><\/p>\n<p>\u00a0 \u00a0 \u00a0 \u9644\u4e0a\u4e00\u9053\u4f4d\u56fe\u6709\u5173\u7684OJ\u9898<\/p>\n<p>\u9762\u8bd5\u9898 01.01. \u5224\u5b9a\u5b57\u7b26\u662f\u5426\u552f\u4e00 &#8211; \u529b\u6263&#xff08;LeetCode&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"667\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042702-68393396df879.png\" width=\"838\" \/><\/p>\n<p>class Solution {<br \/>\npublic:<br \/>\n    bool isUnique(string astr)<br \/>\n    {<br \/>\n       if(astr.size()&gt;26)  return false;\/\/\u9e3d\u5de2\u539f\u7406\u505a\u4f18\u5316<br \/>\n       \/\/\u5229\u7528\u4f4d\u56fe\u7684\u601d\u60f3<br \/>\n       int bitmap&#061;0;<br \/>\n       for(auto ch:astr)<br \/>\n       {<br \/>\n        int i&#061;ch-&#039;a&#039;;\/\/\u627e\u5230\u6620\u5c04\u5173\u7cfb<br \/>\n        if((bitmap&gt;&gt;i)&amp;1&#061;&#061;1)  return false;\/\/\u5148\u5224\u65ad\u8be5\u5b57\u7b26\u662f\u5426\u51fa\u73b0\u8fc7 \u5224\u65ad\u7b2ci\u4f4d\u662f\u5426\u662f1<br \/>\n        \/\/\u5982\u679c\u6ca1\u51fa\u73b0\u8fc7&#xff0c;\u5c06\u7b2ci\u4f4d\u76840\u4fee\u6539\u4e3a1<br \/>\n        bitmap|&#061;(1&lt;&lt;i);<br \/>\n       }<br \/>\n       return true;<br \/>\n    }<br \/>\n}; <\/p>\n<p>5. \u64cd\u4f5c\u7cfb\u7edf\u4e2d\u78c1\u76d8\u5757\u6807\u8bb0<\/p>\n<\/p>\n<h3>1.4 \u4f4d\u56fe\u7684\u6d77\u91cf\u6570\u636e\u5904\u7406<\/h3>\n<p>1. 1\u4e2a\u6587\u4ef6\u6709100\u4ebf\u4e2aint&#xff0c;1G\u5185\u5b58&#xff0c;\u8bbe\u8ba1\u7b97\u6cd5\u627e\u5230\u51fa\u73b0\u6b21\u6570\u4e0d\u8d85\u8fc72\u6b21\u7684\u6240\u6709\u6574\u6570 \u00a0 \u00a0 \u00a0 \u8be5\u95ee\u9898\u7684\u5173\u952e\u5c31\u662f&#xff1a;<span style=\"color:#fe2c24\">\u6211\u4eec\u4f4d\u56fe\u6a21\u578b\u53ea\u80fd\u5224\u65ad\u6709\u6216\u8005\u65e0&#xff0c;\u4f46\u662f\u65e0\u6cd5\u533a\u5206\u51fa\u73b0\u591a\u5c11\u6b21\u3002\u00a0<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 \u00a0 \u00a0 \u00a0\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u5c31\u8981\u4ece\u672c\u8d28\u53bb\u5206\u6790&#xff0c;\u4e3a\u4ec0\u4e48\u4f4d\u56fe\u53ea\u80fd\u5224\u65ad\u6709\u6216\u8005\u65e0\u5462&#xff1f;&#xff1f;\u539f\u56e0\u5c31\u662f\u6211\u4eec\u53ea\u6709\u4e00\u4e2a\u6bd4\u7279\u4f4d\u6765\u8868\u793a\u72b6\u6001\u7684\u6709\u65e0&#xff0c;\u6240\u4ee5\u6211\u4eec\u8fd9\u4e2a\u65f6\u5019\u53ef\u4ee5\u7528\u4e24\u4e2a\u6bd4\u7279\u4f4d\u6765\u8868\u793a\u5f53\u524d\u7684\u72b6\u6001\u3002\u4f46\u662f\u6211\u4eec\u5982\u679c\u76f4\u63a5\u7528\u4e00\u4e2a\u4e3a\u4f4d\u56fe\u6765\u89e3\u51b3&#xff0c;\u90a3\u4e48\u8ba1\u7b97\u903b\u8f91\u4e5f\u4f1a\u968f\u4e4b\u6539\u53d8\u3002\u6240\u4ee5\u6211\u4eec\u8fd8\u662f\u7528\u4e4b\u524d\u7684\u4f4d\u56fe&#xff0c;\u4f46\u662f\u4e3a\u4e86\u8868\u793a\u591a\u79cd\u72b6\u6001&#xff0c;\u6211\u4eec\u4f7f\u7528\u4e24\u4e2a\u4f4d\u56fe\u3002 00\u8868\u793a\u65e0&#xff0c;01\u8868\u793a1\u6b21&#xff0c;11\u8868\u793a2\u6b21&#xff0c;10\u8868\u793a2\u6b21\u4ee5\u4e0a\u5373\u53ef\u3002<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 \u00a0 \u00a0<\/span><span style=\"color:#0d0016\">\u6839\u636e\u4e0a\u8ff0\u7684\u5206\u6790&#xff0c;\u6211\u4eec\u6784\u5efa\u51fa\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u7684\u7c7b<\/span><\/p>\n<p>template&lt;size_t N&gt; \/\/\u975e\u7c7b\u578b\u6a21\u677f\u53c2\u6570   N\u8868\u793a\u9700\u8981\u5f00\u7684\u4f4d\u56fe\u7684\u5927\u5c0f<br \/>\nclass twobitset \/\/\u89e3\u51b3100\u4ebf\u6570\u636e\u5224\u65ad\u6709\u65e0  \u627e\u5230\u6570\u636e\u4e2d\u4e0d\u8d85\u8fc72\u6b21\u7684\u6574\u6570  00-\u65e0  01\u4e00\u4e2a  11\u4e24\u4e2a  10\u4e24\u4e2a\u4ee5\u4e0a<br \/>\n{<br \/>\npublic:<br \/>\nvoid set(size_t x) \/\/\u8bbe\u7f6e\u62101<br \/>\n{<br \/>\nif (_bit1.test(x) &#061;&#061; false &amp;&amp; _bit2.test(x) &#061;&#061; false)  _bit2.set(x);\/\/00-&gt;01<br \/>\nelse if (_bit1.test(x) &#061;&#061; false &amp;&amp; _bit2.test(x) &#061;&#061; true) _bit1.set(x);\/\/01-&gt;11<br \/>\nelse if (_bit1.test(x) &#061;&#061; true &amp;&amp; _bit2.test(x) &#061;&#061; true) _bit2.reset(x);\/\/11-&gt;10<br \/>\n\/\/\u5982\u679c\u662f11 \u4e0d\u5904\u7406<br \/>\n}<\/p>\n<p>void Print() \/\/\u6253\u5370\u53ea\u51fa\u73b0\u4e00\u6b21\u6216\u8005\u4e24\u6b21\u7684\u6574\u6570<br \/>\n{<br \/>\nfor (size_t i &#061; 0; i &lt; N; &#043;&#043;i)<br \/>\nif (_bit2.test(i) &#061;&#061; true)<br \/>\ncout &lt;&lt; i &lt;&lt; endl;<br \/>\ncout &lt;&lt; endl;<br \/>\n}<br \/>\nprivate:<br \/>\nbitset&lt;N&gt; _bit1;<br \/>\nbitset&lt;N&gt; _bit2;<\/p>\n<p>}; <\/p>\n<p>2\u3001\u7ed9\u4e24\u4e2a\u6587\u4ef6&#xff0c;\u5206\u522b\u6709100\u4ebf\u4e2a\u6574\u6570&#xff0c;\u6211\u4eec\u53ea\u67091G\u5185\u5b58&#xff0c;\u5982\u4f55\u627e\u5230\u4e24\u4e2a\u6587\u4ef6\u4ea4\u96c6&#xff1f;<\/p>\n<p>\u00a0 \u00a0 \u89e3\u51b3\u65b9\u6848\u6211\u57281.3\u4e2d\u5df2\u7ecf\u8bb2\u8fc7\u4e86&#xff01;&#xff01;<\/p>\n<h3>1.5 \u4f4d\u56fe\u7684\u4f18\u7f3a\u70b9<\/h3>\n<p>\u4f18\u70b9&#xff1a;\u901f\u5ea6\u5feb\u3001\u8282\u7701\u5185\u5b58<\/p>\n<p>\u7f3a\u70b9&#xff1a;<span style=\"color:#fe2c24\">\u53ea\u80fd\u6620\u5c04\u6574\u578b&#xff0c;\u5982\u6d6e\u70b9\u6570\u3001string\u7b49\u7b49\u4e0d\u80fd\u5b58\u50a8\u6620\u5c04\u00a0\u00a0<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 \u00a0 \u00a0 \u00a0\u9996\u5148\u6211\u4eec\u8981\u601d\u8003&#xff0c;\u4e3a\u4ec0\u4e48\u4f4d\u56fe\u65e0\u6cd5\u5b58\u50a8\u8fd9\u4e24\u79cd\u7c7b\u578b\u7684\u6620\u5c04&#xff0c;\u539f\u56e0\u5c31\u5728\u4e8e\u5176\u53ef\u4ee5\u8868\u73b0\u7684\u5f62\u5f0f\u592a\u591a\u79cd\u4e86&#xff0c;\u6bd4\u5982\u8bf4\u5bf9\u4e8e\u65e0\u7b26\u53f7\u6574\u578b\u6765\u8bf4&#xff0c;\u6700\u591a\u4e5f\u5c312^32-1\u79cd\u53ef\u80fd&#xff0c; \u4f46\u662f\u5bf9\u4e8e\u6d6e\u70b9\u6570\u548cstring\u6765\u8bf4&#xff0c;\u5176\u7ec4\u5408\u4e4b\u591a\u5bfc\u81f4\u65e0\u6cd5\u50cf\u6574\u578b\u4e00\u6837\u5728\u4f4d\u56fe\u4e2d\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u76f4\u63a5\u5b9a\u5740\u6cd5\u3002<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 \u00a0 \u00a0 \u00a0\u6d6e\u70b9\u6570\u8fd8\u597d&#xff0c;\u4f46\u662fstring\u5e73\u65f6\u975e\u5e38\u5e38\u7528&#xff0c;\u6bd4\u5982\u7528\u6237\u540d&#xff0c;\u6240\u4ee5\u8fd9\u4e2a\u65f6\u5019\u5f53\u6570\u636e\u91cf\u6781\u5927\u7684\u65f6\u5019&#xff0c;\u4e5f\u662f\u4e00\u4e2a\u95ee\u9898&#xff0c;\u6240\u4ee5\u540e\u6765\u51fa\u73b0\u4e86\u4e00\u79cd\u7ed3\u6784\u89e3\u51b3\u4e86\u8fd9\u79cd\u95ee\u9898\u2014\u2014&gt;\u5e03\u9686\u8fc7\u6ee4\u5668<\/span><\/p>\n<h2>\u4e8c\u3001\u5e03\u9686\u8fc7\u6ee4\u5668<\/h2>\n<h3>2.1 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u63d0\u51fa<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u6211\u4eec\u5728\u4f7f\u7528\u65b0\u95fb\u5ba2\u6237\u7aef\u770b\u65b0\u95fb\u65f6&#xff0c;\u5b83\u4f1a\u7ed9\u6211\u4eec\u4e0d\u505c\u5730\u63a8\u8350\u65b0\u7684\u5185\u5bb9&#xff0c;\u5b83\u6bcf\u6b21\u63a8\u8350\u65f6\u8981\u53bb\u91cd&#xff0c;\u53bb\u6389\u90a3\u4e9b\u5df2\u7ecf\u770b\u8fc7\u7684\u5185\u5bb9\u3002\u95ee\u9898\u6765\u4e86&#xff0c;\u65b0\u95fb\u5ba2\u6237\u7aef\u63a8\u8350\u7cfb\u7edf\u5982\u4f55\u5b9e\u73b0\u63a8\u9001\u53bb\u91cd\u7684&#xff1f; \u7528\u670d\u52a1\u5668\u8bb0\u5f55\u4e86\u7528\u6237\u770b\u8fc7\u7684\u6240\u6709\u5386\u53f2\u8bb0\u5f55&#xff0c;<span style=\"color:#fe2c24\">\u5f53\u63a8\u8350\u7cfb\u7edf\u63a8\u8350\u65b0\u95fb\u65f6\u4f1a\u4ece\u6bcf\u4e2a\u7528\u6237\u7684\u5386\u53f2\u8bb0\u5f55\u91cc\u8fdb\u884c\u7b5b\u9009&#xff0c;\u8fc7\u6ee4\u6389\u90a3 \u4e9b\u5df2\u7ecf\u5b58\u5728\u7684\u8bb0\u5f55<\/span>\u3002 \u5982\u4f55\u5feb\u901f\u67e5\u627e\u5462&#xff1f; \u00a0<\/p>\n<p>1. \u7528\u54c8\u5e0c\u8868\u5b58\u50a8\u7528\u6237\u8bb0\u5f55&#xff0c;\u7f3a\u70b9&#xff1a;<span style=\"color:#fe2c24\">\u6d6a\u8d39\u7a7a\u95f4<\/span> 2. \u7528\u4f4d\u56fe\u5b58\u50a8\u7528\u6237\u8bb0\u5f55&#xff0c;\u7f3a\u70b9&#xff1a;<span style=\"color:#fe2c24\">\u4f4d\u56fe\u4e00\u822c\u53ea\u80fd\u5904\u7406\u6574\u5f62&#xff0c;\u5982\u679c\u5185\u5bb9\u7f16\u53f7\u662f\u5b57\u7b26\u4e32&#xff0c;\u5c31\u65e0\u6cd5\u5904\u7406 \u4e86\u3002<\/span> 3. \u5c06\u54c8\u5e0c\u4e0e\u4f4d\u56fe\u7ed3\u5408&#xff0c;\u5373<span style=\"color:#fe2c24\">\u5e03\u9686\u8fc7\u6ee4\u5668<\/span> \u00a0<\/p>\n<h3>2.2 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u6982\u5ff5<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u5e03\u9686\u8fc7\u6ee4\u5668\u662f\u7531\u5e03\u9686&#xff08;Burton Howard Bloom&#xff09;\u57281970\u5e74\u63d0\u51fa\u7684 \u4e00\u79cd\u7d27\u51d1\u578b\u7684\u3001\u6bd4\u8f83\u5de7\u5999\u7684<span style=\"color:#fe2c24\">\u6982\u7387\u578b\u6570\u636e\u7ed3\u6784<\/span>&#xff0c;\u7279\u70b9\u662f\u9ad8\u6548\u5730\u63d2\u5165\u548c\u67e5\u8be2&#xff0c;\u53ef\u4ee5\u7528\u6765\u544a\u8bc9\u4f60 \u201c\u67d0\u6837\u4e1c\u897f\u4e00\u5b9a\u4e0d\u5b58\u5728\u6216\u8005\u53ef\u80fd\u5b58 \u5728\u201d&#xff0c;\u5b83\u662f\u7528\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570&#xff0c;\u5c06\u4e00\u4e2a\u6570\u636e\u6620\u5c04\u5230\u4f4d\u56fe\u7ed3\u6784\u4e2d\u3002\u6b64\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u53ef\u4ee5\u63d0\u5347\u67e5\u8be2\u6548\u7387&#xff0c;\u4e5f \u53ef\u4ee5\u8282\u7701\u5927\u91cf\u7684\u5185\u5b58\u7a7a\u95f4\u3002<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"180\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042703-68393397328aa.png\" width=\"500\" \/><\/p>\n<p>\u00a0 \u00a0<span style=\"color:#fe2c24\">\u00a0\u600e\u4e48\u53bb\u7406\u89e3\u6982\u7387\u578b\u6570\u636e\u7ed3\u6784\u5462&#xff1f;&#xff1f;<\/span><\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u00a0<span style=\"color:#0d0016\">\u9996\u5148\u53ef\u4ee5\u786e\u5b9a\u7684\u662f&#xff0c;\u7531\u4e8e\u5b57\u7b26\u4e32\u7684\u6392\u5217\u7ec4\u5408\u79cd\u7c7b\u975e\u5e38\u591a&#xff0c;\u6240\u4ee5\u6211\u4eec\u65e0\u8bba\u5982\u4f55\u90fd\u65e0\u6cd5\u505a\u5230\u901a\u8fc7\u76f4\u63a5\u5b9a\u5740\u6cd5\u8ba9\u6bcf\u4e2a\u5b57\u7b26\u4e32\u6b63\u597d\u90fd\u5bf9\u5e94\u4e00\u4e2a\u4f4d\u7f6e\u2026\u2026\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u6211\u4eec<\/span><span style=\"color:#fe2c24\">\u5229\u7528\u5b57\u7b26\u4e32\u54c8\u5e0c\u51fd\u6570\u5728\u4f4d\u56fe\u4e2d\u5b58\u50a8\u5927\u91cf\u5b57\u7b26\u4e32\u4fe1\u606f\u662f\u5fc5\u7136\u4f1a\u9020\u6210\u54c8\u5e0c\u51b2\u7a81\u7684<\/span><span style=\"color:#0d0016\">&#xff0c;\u800c\u5e03\u9686\u5927\u4f6c\u7684\u60f3\u6cd5\u5e76\u4e0d\u662f\u5b8c\u5168\u89e3\u51b3\u54c8\u5e0c\u51b2\u7a81&#xff0c;\u800c\u662f\u60f3\u964d\u4f4e\u54c8\u5e0c\u51b2\u7a81\u7684\u6982\u7387\u3002\u00a0 \u7b56\u7565\u5c31\u662f&#xff1a;<\/span><span style=\"color:#fe2c24\">\u65e2\u7136\u4e00\u4e2a\u5b57\u7b26\u4e32\u6620\u5c04\u4e00\u4e2a\u4f4d\u7f6e\u5bb9\u6613\u51fa\u73b0\u54c8\u5e0c\u51b2\u7a81&#xff0c;\u90a3\u4e48\u4e00\u4e2a\u5b57\u7b26\u4e32\u6620\u5c04\u591a\u4e2a\u4f4d\u7f6e\u51fa\u73b0\u54c8\u5e0c\u51b2\u7a81\u7684\u6982\u7387\u5c31\u4f1a\u964d\u4f4e<\/span><span style=\"color:#0d0016\">&#xff01;&#xff01;&#xff01;\u8fd9\u662f\u4e00\u79cd\u9000\u800c\u6c42\u5176\u6b21\u7684\u7b56\u7565\u3002<\/span><\/p>\n<\/p>\n<p><span style=\"color:#ff9900\">\u6240\u4ee5\u6211\u4eec\u8981\u4f7f\u7528\u591a\u4e2a\u7c7b\u578b\u7684\u5b57\u7b26\u4e32\u54c8\u5e0c\u51fd\u6570\u6765\u5e2e\u52a9\u6211\u4eec\u8ba9\u4e00\u4e2a\u5b57\u7b26\u4e32\u6620\u5c04\u591a\u4e2a\u4f4d\u7f6e\u3002<\/span>\u5177\u4f53\u6709\u54ea\u4e9b\u5e38\u7528\u7684\u54c8\u5e0c\u51fd\u6570\u53ef\u4ee5\u53c2\u7167\u4e0b\u9762\u7684\u6587\u7ae0&#xff1a;\u5b57\u7b26\u4e32\u54c8\u5e0c\u51fd\u6570\u7b97\u6cd5<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"370\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042703-683933974837e.png\" width=\"913\" \/><\/p>\n<p>\u901a\u8fc7\u4e0a\u56fe&#xff0c;\u6211\u4eec\u53ef\u4ee5\u786e\u5b9a\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u4e24\u4e2a\u7279\u70b9&#xff1a;<\/p>\n<p>1\u3001<span style=\"color:#fe2c24\">\u4e0d\u5728\u662f\u51c6\u786e\u7684<\/span>&#xff0c;\u56e0\u4e3a\u53ea\u8981\u6709\u4e00\u4e2a\u4f4d\u7f6e\u6ca1\u6620\u5c04\u4e0a&#xff0c;\u5c31\u662f\u4e0d\u5728\u3002<\/p>\n<p>2\u3001<span style=\"color:#fe2c24\">\u5728\u662f\u4e0d\u51c6\u5907\u7684&#xff0c;\u5b58\u5728\u8bef\u5224<\/span>&#xff0c;\u56e0\u4e3a\u53ef\u80fd\u8be5\u5b57\u7b26\u4e32\u6620\u5c04\u7684\u4f4d\u7f6e\u6070\u597d\u88ab\u524d\u9762\u7684\u5b57\u7b26\u4e32\u7ed9\u6620\u5c04\u4e86<\/p>\n<h3>2.3 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u5e94\u7528\u573a\u666f<\/h3>\n<p>\u00a0\u65e2\u7136\u5e03\u9686\u8fc7\u6ee4\u5668\u53ea\u662f\u964d\u4f4e\u54c8\u5e0c\u51b2\u7a81\u800c\u4e0d\u662f\u907f\u514d\u54c8\u5e0c\u51b2\u7a81&#xff0c;\u90a3\u4e48\u4ed6\u9002\u5408\u7684\u573a\u666f\u5982\u4e0b&#xff1a;<\/p>\n<p><span style=\"color:#fe2c24\">1\u3001\u80fd\u5bb9\u5fcd\u8bef\u5224\u7684\u573a\u666f&#xff08;\u5ba2\u6237\u7aef\u611f\u77e5\u4e0d\u5230&#xff09;<\/span><\/p>\n<p>\u6bd4\u5982\u6ce8\u518c\u65f6&#xff0c;\u5feb\u901f\u5224\u65ad\u6635\u79f0\u662f\u5426\u88ab\u4f7f\u7528\u8fc7\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"398\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042703-683933977245b.png\" width=\"1038\" \/><\/p>\n<p><span style=\"color:#fe2c24\">2\u3001\u867d\u7136\u4e0d\u80fd\u5bb9\u5fcd\u8bef\u5224&#xff0c;\u4f46\u662f\u53ef\u4ee5\u786e\u5b9a\u4e0d\u5728\u662f\u51c6\u786e\u7684&#xff0c;\u53ea\u9700\u8981\u5bf9\u5728\u7684\u573a\u666f\u8fdb\u884c\u7279\u6b8a\u5904\u7406<\/span><\/p>\n<p>\u6bd4\u5982\u8bf4\u6ce8\u518c\u65f6&#xff0c;\u5feb\u901f\u5224\u65ad\u8be5\u7535\u8bdd\u53f7\u7801\u662f\u5426\u88ab\u6ce8\u518c\u8fc7\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"643\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042703-68393397a9db4.png\" width=\"1200\" \/><\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u901a\u8fc7\u4e0a\u56fe\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0&#xff0c;\u5e03\u9686\u8fc7\u6ee4\u5668\u81f3\u5c11\u5bf9\u4e0d\u5728\u7684\u573a\u666f\u662f\u5224\u65ad\u51c6\u786e\u7684&#xff0c;\u6240\u4ee5\u6211\u4eec<span style=\"color:#fe2c24\">\u53ef\u4ee5\u4e0d\u9700\u8981\u53bb\u6570\u636e\u5e93\u67e5\u8be2&#xff0c;\u53ea\u9700\u8981\u5bf9\u5728\u7684\u7ed3\u679c\u8fdb\u884c\u67e5\u8be2\u548c\u6bd4\u5bf9\u5373\u53ef<\/span>\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u540c\u65f6\u5927\u5bb6\u4f1a\u53d1\u73b0&#xff0c;\u4e0a\u56fe\u5c31\u5145\u5206\u5c55\u73b0\u4e86\u4e3a\u4ec0\u4e48\u8be5\u89e3\u51b3\u5c31\u53eb\u505a\u5e03\u9686\u8fc7\u6ee4\u5668&#xff0c;\u5176\u5b9e\u5c31\u662f<span style=\"color:#fe2c24\">\u5c06\u5927\u91cf\u7684\u4fe1\u606f\u8fdb\u884c\u8fc7\u6ee4&#xff0c;\u5904\u7406\u5176\u4e2d\u53ef\u4ee5\u89e3\u51b3\u7684\u95ee\u9898&#xff0c;\u5bf9\u4e8e\u5c11\u90e8\u5206\u4e0d\u80fd\u89e3\u51b3\u7684\u95ee\u9898&#xff0c;\u518d\u5230\u6570\u636e\u5e93\u4e2d\u53bb\u89e3\u51b3\u3002<\/span><\/p>\n<h3><span style=\"color:#0d0016\">2.4 \u5e03\u9686\u8fc7\u6ee4\u5668\u5b9e\u73b0\u7684\u57fa\u672c\u7ed3\u6784<\/span><\/h3>\n<p>  \/\/\u60f3\u628a\u7c7b\u5f53\u51fd\u6570\u4f7f\u7528 \u5c31\u8981\u60f3\u5230\u4eff\u51fd\u6570<br \/>\n  \/\/\u63d0\u4f9b\u4e09\u4e2a\u5b57\u7b26\u4e32\u54c8\u5e0c\u51fd\u6570<br \/>\nstruct BKDRHash<br \/>\n{<br \/>\nsize_t operator() (const string&amp; s) \/\/\u5b57\u7b26\u4e32\u8f6c\u6574\u578b<br \/>\n{<br \/>\nsize_t hash &#061; 0;<br \/>\nfor (auto e : s)<br \/>\n{<br \/>\nhash &#043;&#061; e;<br \/>\nhash *&#061; 31;<br \/>\n}<br \/>\nreturn hash;<br \/>\n}<br \/>\n};<br \/>\nstruct APHash<br \/>\n{<br \/>\nsize_t operator()(const string&amp; s)<br \/>\n{<br \/>\nsize_t hash &#061; 0;<br \/>\nfor (long i &#061; 0; i &lt; s.size(); i&#043;&#043;)<br \/>\n{<br \/>\nsize_t ch &#061; s[i];<br \/>\nif ((i &amp; 1) &#061;&#061; 0)  hash ^&#061; ((hash &lt;&lt; 7) ^ ch ^ (hash &gt;&gt; 3));<br \/>\nelse               hash ^&#061; (~((hash &lt;&lt; 11) ^ ch ^ (hash &gt;&gt; 5)));<br \/>\n}<br \/>\nreturn hash;<br \/>\n}<br \/>\n};<br \/>\nstruct DJBHash<br \/>\n{<br \/>\nsize_t operator()(const string&amp; s)<br \/>\n{<br \/>\nsize_t hash &#061; 5381;<br \/>\nfor (auto ch : s)  hash &#043;&#061; (hash &lt;&lt; 5) &#043; ch;<br \/>\nreturn hash;<br \/>\n}<br \/>\n};<br \/>\n\/\/\u5e03\u9686\u8fc7\u6ee4\u5668  \u57fa\u672c\u4e0a\u89e3\u51b3\u7684\u662f\u5b57\u7b26\u4e32\u7684\u95ee\u9898 \u5982\u679c\u662f\u6574\u578b\u7684\u8bdd \u8fd8\u662f\u4f4d\u56fe\u66f4\u597d\u7528   \u81f3\u4e8e\u7528\u591a\u5c11\u4e2a\u54c8\u5e0c\u51fd\u6570 \u53d6\u51b3\u4e8e\u5b9e\u9645\u7684\u9700\u6c42<br \/>\n\/\/N\u8868\u793a\u6700\u591a\u4f1a\u63d2\u5165key\u7684\u4e2a\u6570<br \/>\ntemplate&lt;size_t N,<br \/>\nsize_t X&#061;6,<br \/>\nclass K&#061;string,<br \/>\nclass Hash1&#061; BKDRHash,<br \/>\nclass Hash2&#061; APHash,<br \/>\nclass Hash3&#061; DJBHash&gt; \/\/K\u5e76\u4e0d\u786e\u5b9a\u662f\u4ec0\u4e48   \u901a\u8fc7\u591a\u79cdHash\u51fd\u6570\u53bb\u5e2e\u52a9\u6211\u4eec\u6620\u5c04\u4e0d\u540c\u7684\u4f4d\u7f6e<br \/>\nclass BloomFilter<br \/>\n{<br \/>\npublic:<\/p>\n<p>private:<br \/>\nbitset&lt;N*X&gt; _bits;<br \/>\n};<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u6211\u4eec\u4e00\u5171\u7528\u4e866\u4e2a\u6a21\u7248\u53c2\u6570&#xff0c;\u9996\u5148\u5e03\u9686\u8fc7\u6ee4\u5668\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u662f\u7528\u6765\u89e3\u51b3\u5b57\u7b26\u4e32\u7684\u95ee\u9898&#xff0c;\u6240\u4ee5\u6211\u4eec\u7684K\u9ed8\u7136\u7ed9\u7684\u662fstring&#xff0c;\u800c\u540e\u9762Hash1\u2014\u2014Hash3\u90fd\u662f\u5b57\u7b26\u4e32\u54c8\u5e0c\u51fd\u6570&#xff0c;\u8fd9\u6837\u4e00\u4e2a\u5b57\u7b26\u4e32\u53ef\u4ee5\u6620\u5c04\u4e09\u4e2a\u4f4d\u7f6e\u3002\u800cN\u8868\u793a\u7684\u662f\u8981\u63d2\u5165\u591a\u5c11\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u800c\u5173\u4e8eX\u662f\u4ec0\u4e48&#xff0c;\u6211\u4eec\u6765\u770b\u770b\u4e0b\u9762\u8fd9\u4e2a\u6587\u7ae0\u3002<\/p>\n<p>\u8be6\u89e3\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u539f\u7406&#xff0c;\u4f7f\u7528\u573a\u666f\u548c\u6ce8\u610f\u4e8b\u9879 &#8211; \u77e5\u4e4e<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"652\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042704-6839339829e8d.png\" width=\"1200\" \/><\/p>\n<p>\u00a0\u6240\u4ee5X\u5728\u8fd9\u8fb9\u53ef\u4ee5\u7406\u89e3\u4e3a\u6211\u4eec\u9700\u8981\u591a\u5f00X\u500d\u7684\u7a7a\u95f4&#xff0c;\u6765\u5c3d\u53ef\u80fd\u8fbe\u5230\u8bef\u5224\u7387\u548c\u6548\u7387\u5c3d\u53ef\u80fd\u5408\u7406\u3002<\/p>\n<p>\u7ecf\u8fc7\u8ba1\u7b97\u540e\u5982\u679c\u6211\u4eec\u7684\u54c8\u5e0c\u51fd\u6570\u662f3\u4e2a\u7684\u8bdd&#xff0c;\u5927\u6982\u9700\u8981\u591a\u5f004.3\u500d\u7684\u7a7a\u95f4\u6bd4\u8f83\u5408\u7406\u3002<\/p>\n<h3>2.5 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u63d2\u5165<\/h3>\n<p>void set(const K&amp; key)<br \/>\n{<br \/>\nsize_t len &#061; N * X;<br \/>\nsize_t hash1 &#061; Hash1()(key) % len;<br \/>\n_bits.set(hash1);<br \/>\nsize_t hash2 &#061; Hash2()(key) % len;<br \/>\n_bits.set(hash2);<br \/>\nsize_t hash3 &#061; Hash3()(key) % len;<br \/>\n_bits.set(hash3);<br \/>\n\/\/cout &lt;&lt; hash1 &lt;&lt; &#034; &#034; &lt;&lt; hash2 &lt;&lt; &#034; &#034; &lt;&lt; hash3 &lt;&lt; endl &lt;&lt; endl; \/\/\u770b\u770b\u6620\u5c04\u7684\u4f4d\u7f6e<br \/>\n} <\/p>\n<h3>\u00a02.6 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u67e5\u627e<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u601d\u60f3\u662f\u5c06\u4e00\u4e2a\u5143\u7d20\u7528\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u6620\u5c04\u5230\u4e00\u4e2a\u4f4d\u56fe\u4e2d&#xff0c;\u56e0\u6b64\u88ab\u6620\u5c04\u5230\u7684\u4f4d\u7f6e\u7684\u6bd4\u7279\u4f4d\u4e00\u5b9a\u4e3a1\u3002\u6240\u4ee5\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u65b9\u5f0f\u8fdb\u884c\u67e5\u627e&#xff1a;<span style=\"color:#fe2c24\">\u5206\u522b\u8ba1\u7b97\u6bcf\u4e2a\u54c8\u5e0c\u503c\u5bf9\u5e94\u7684\u6bd4\u7279\u4f4d\u7f6e\u5b58\u50a8\u7684\u662f\u5426\u4e3a\u96f6&#xff0c;\u53ea\u8981\u6709\u4e00\u4e2a\u4e3a\u96f6&#xff0c;\u4ee3\u8868\u8be5\u5143\u7d20\u4e00\u5b9a\u4e0d\u5728\u54c8\u5e0c\u8868\u4e2d&#xff0c;\u5426\u5219\u53ef\u80fd\u5728\u54c8\u5e0c\u8868\u4e2d\u3002<\/span><\/p>\n<p>bool test(const K&amp; key)<br \/>\n{<br \/>\nsize_t len &#061; N * X;<br \/>\nsize_t hash1 &#061; Hash1()(key) % len;<br \/>\nif (_bits.test(hash1) &#061;&#061; false) return false;<br \/>\nsize_t hash2 &#061; Hash2()(key) % len;<br \/>\nif (_bits.test(hash2) &#061;&#061; false) return false;<br \/>\nsize_t hash3 &#061; Hash3()(key) % len;<br \/>\nif (_bits.test(hash3) &#061;&#061; false) return false;<\/p>\n<p>return true;\/\/\u5728\u53ef\u80fd\u4f1a\u6709\u8bef\u5224<br \/>\n} <\/p>\n<p>\u6ce8\u610f&#xff1a;<span style=\"color:#fe2c24\">\u5e03\u9686\u8fc7\u6ee4\u5668\u5982\u679c\u8bf4\u67d0\u4e2a\u5143\u7d20\u4e0d\u5b58\u5728\u65f6&#xff0c;\u8be5\u5143\u7d20\u4e00\u5b9a\u4e0d\u5b58\u5728&#xff0c;\u5982\u679c\u8be5\u5143\u7d20\u5b58\u5728\u65f6&#xff0c;\u8be5\u5143\u7d20\u53ef \u80fd\u5b58\u5728&#xff0c;\u56e0\u4e3a\u6709\u4e9b\u54c8\u5e0c\u51fd\u6570\u5b58\u5728\u4e00\u5b9a\u7684\u8bef\u5224\u3002<\/span><\/p>\n<h3><span style=\"color:#0d0016\">2.7 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u5220\u9664<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u00a0 \u00a0 \u00a0 \u9996\u5148\u6211\u4eec\u53ef\u4ee5\u786e\u5b9a\u7684\u662f&#xff0c;\u5e03\u9686\u8fc7\u6ee4\u5668\u662f\u4e0d\u592a\u652f\u6301\u5220\u9664\u7684&#xff0c;\u56e0\u4e3a\u6211\u4eec\u5220\u4e86\u4e00\u4e2a\u4f4d\u7f6e&#xff0c;\u53ef\u80fd\u4f1a\u5f71\u54cd\u5176\u4ed6\u4f4d\u7f6e\u3002<\/span><\/p>\n<p>\u00a0 \u00a0 \u00a0 \u4e00\u79cd\u652f\u6301\u5220\u9664\u7684\u65b9\u6cd5&#xff1a;<span style=\"color:#fe2c24\">\u5c06\u5e03\u9686\u8fc7\u6ee4\u5668\u4e2d\u7684\u6bcf\u4e2a\u6bd4\u7279\u4f4d\u6269\u5c55\u6210\u4e00\u4e2a\u5c0f\u7684\u8ba1\u6570\u5668&#xff0c;\u63d2\u5165\u5143\u7d20\u65f6\u7ed9k\u4e2a\u8ba1\u6570\u5668(k\u4e2a\u54c8\u5e0c\u51fd\u6570\u8ba1\u7b97\u51fa\u7684\u54c8\u5e0c\u5730\u5740)\u52a0\u4e00&#xff0c;\u5220\u9664\u5143\u7d20\u65f6&#xff0c;\u7ed9k\u4e2a\u8ba1\u6570\u5668\u51cf\u4e00&#xff0c;\u901a\u8fc7\u591a\u5360\u7528\u51e0\u500d\u5b58\u50a8\u7a7a\u95f4\u7684\u4ee3\u4ef7\u6765\u589e\u52a0\u5220\u9664\u64cd\u4f5c\u3002<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 \u00a0 \u00a0<\/span> \u00a0 \u00a0 \u00a0 \u4f46\u662f\u8fd9\u6837\u4f1a\u5b58\u5728\u4e09\u79cd\u7f3a\u9677&#xff1a;<\/p>\n<p>1\u3001\u65e0\u6cd5\u786e\u8ba4\u5143\u7d20\u662f\u5426\u771f\u6b63\u5728\u5e03\u9686\u8fc7\u6ee4\u5668\u4e2d<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u56e0\u4e3a\u65e0\u8bba\u662f\u4f4d\u56fe\u8fd8\u662f\u5e03\u9686\u8fc7\u6ee4\u5668\u5e76\u4e0d\u662f\u4f20\u7edf\u610f\u4e49\u4e0a\u7684\u771f\u7684\u5b58\u4e86\u76f8\u5bf9\u5e94\u7684\u5143\u7d20\u5728\u91cc\u9762&#xff0c;\u800c\u53ea\u80fd\u53cd \u5e94\u5177\u4f53\u5728\u4e0d\u5728\u3002\u6240\u4ee5\u6211\u4eec\u5f88\u96be\u4fdd\u8bc1\u8bf4\u6211\u4eec\u5f53\u524d\u8981\u5220\u9664\u7684\u5143\u7d20\u662f\u5426\u5b58\u5728\u5e03\u9686\u8fc7\u6ee4\u5668\u4e2d&#xff0c;\u5982\u679c\u8981\u5220\u9664\u7684\u5143\u7d20\u4e0d\u5b58\u5728\u5e03\u9686\u8fc7\u6ee4\u5668\u4e2d&#xff0c;\u5e03\u9686\u8fc7\u6ee4\u5668\u662f\u68c0\u6d4b\u4e0d\u51fa\u6765\u7684&#xff0c;\u8fd9\u6837\u5c31\u6574\u4e2a\u4e71\u5957\u4e86\u3002<\/p>\n<p>2\u3001\u5bb9\u6613\u5b58\u5728\u8ba1\u6570\u56de\u7ed5<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u65e2\u7136\u662f\u8ba1\u6570&#xff0c;\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u6839\u636e\u60c5\u51b5\u53bb\u63a7\u5236\u4e00\u4e2a\u4f4d\u7f6e\u5927\u7ea6\u7528\u51e0\u4e2a\u6bd4\u7279\u4f4d\u6765\u8ba1\u6570&#xff0c;\u6bd4\u5982\u6211\u4eec\u75284\u4e2a\u6bd4\u7279\u4f4d\u6765\u8ba1\u6570&#xff0c;\u90a3\u4e48\u5c31\u67092^4 \u4e5f\u5c31\u662f16\u4e2a\u5b57\u7b26\u4e32\u53ef\u4ee5\u6620\u5c04\u8be5\u4f4d\u7f6e&#xff0c;\u5982\u679c\u75288\u4e2a\u6bd4\u7279\u4f4d\u5c31\u662f2^8 \u4e5f\u5c31\u662f256\u4e2a\u5b57\u7b26\u4e32\u53ef\u4ee5\u6620\u5c04\u8be5\u4f4d\u7f6e\u3002\u4f46\u662f\u5982\u679c\u6211\u4eec\u8d85\u51fa\u4e86\u8fd9\u4e2a\u8303\u56f4&#xff08;\u6bd4\u5982\u6709257\u4e2a\u5b57\u7b26\u4e32\u6620\u5c04\u4e86\u8be5\u4f4d\u7f6e&#xff09;&#xff0c;\u53ef\u80fd\u5c31\u4f1a\u51fa\u73b0\u8ba1\u6570\u6ea2\u51fa\u5bfc\u81f4\u8ba1\u6570\u56de\u7ed5\u3002<\/p>\n<p>3\u3001\u65e0\u6cd5\u53bb\u91cd<\/p>\n<p>\u00a0 \u00a0 \u00a0\u4f7f\u7528\u5f15\u7528\u8ba1\u6570\u540e&#xff0c;\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e0d\u5c0f\u5fc3\u540c\u65f6\u63d2\u5165\u4e86\u4e24\u6b21&#xff0c;\u90a3\u4e48\u5bf9\u5e94\u4f4d\u7f6e\u7684\u8ba1\u6570\u90fd\u4f1a\u589e\u52a0&#xff0c;\u8fd9\u4e2a\u65f6\u5019\u5f53\u6211\u4eec\u4e0b\u6b21\u8981\u5220\u9664\u7684\u65f6\u5019&#xff0c;\u4e5f\u5fc5\u987b\u8981\u5220\u9664\u4e24\u6b21&#xff0c;\u5982\u679c\u53ea\u5220\u9664\u4e00\u6b21&#xff0c;\u90a3\u4e48\u8fd8\u662f\u53ef\u4ee5\u627e\u5f97\u5230\u3002<\/p>\n<p>\u00a0 \u00a0<span style=\"color:#fe2c24\"> \u00a0\u7efc\u5408\u4e0a\u9762\u7684\u4e09\u79cd\u7f3a\u9677&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u7ed3\u8bba\u5c31\u662f\u2014\u2014\u5e03\u9686\u8fc7\u6ee4\u5668\u5e76\u4e0d\u9002\u5e94\u5220\u9664\u7684\u573a\u666f&#xff0c;\u5c24\u5176\u662f\u7b2c\u4e00\u4e2a\u7f3a\u9677\u6700\u4e3a\u4e25\u91cd&#xff0c;\u4e25\u91cd\u65f6\u4f1a\u5bfc\u81f4\u6570\u636e\u4e22\u5931&#xff01;&#xff01;&#xff01;<\/span><\/p>\n<h3><span style=\"color:#0d0016\">2.8 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u4f18\u70b9<\/span><\/h3>\n<p>1. <span style=\"color:#fe2c24\">\u589e\u52a0\u548c\u67e5\u8be2\u5143\u7d20\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a:O(K),<\/span> (K\u4e3a\u54c8\u5e0c\u51fd\u6570\u7684\u4e2a\u6570&#xff0c;\u4e00\u822c\u6bd4\u8f83\u5c0f)&#xff0c;\u4e0e\u6570\u636e\u91cf\u5927\u5c0f\u65e0\u5173<\/p>\n<p>2. <span style=\"color:#fe2c24\">\u54c8\u5e0c\u51fd\u6570\u76f8\u4e92\u4e4b\u95f4\u6ca1\u6709\u5173\u7cfb&#xff08;\u53ef\u591a\u6b21\u8fdb\u884c\u54c8\u5e0c\u5207\u5272&#xff09;<\/span>&#xff0c;\u65b9\u4fbf\u786c\u4ef6\u5e76\u884c\u8fd0\u7b97<\/p>\n<p>3. \u5e03\u9686\u8fc7\u6ee4\u5668<span style=\"color:#fe2c24\">\u4e0d\u9700\u8981\u5b58\u50a8\u5143\u7d20\u672c\u8eab<\/span>&#xff0c;\u5728\u67d0\u4e9b<span style=\"color:#fe2c24\">\u5bf9\u4fdd\u5bc6\u8981\u6c42\u6bd4\u8f83\u4e25\u683c\u7684\u573a\u5408\u6709\u5f88\u5927\u4f18\u52bf<\/span><\/p>\n<p>4. \u5728<span style=\"color:#fe2c24\">\u80fd\u591f\u627f\u53d7\u4e00\u5b9a\u7684\u8bef\u5224<\/span>\u65f6&#xff0c;\u5e03\u9686\u8fc7\u6ee4\u5668\u6bd4\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u6709\u8fd9\u5f88\u5927\u7684\u7a7a\u95f4\u4f18\u52bf<\/p>\n<p>5. \u6570\u636e\u91cf\u5f88\u5927\u65f6&#xff0c;\u5e03\u9686\u8fc7\u6ee4\u5668\u53ef\u4ee5\u8868\u793a\u5168\u96c6&#xff0c;\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u4e0d\u80fd<\/p>\n<p>6. \u4f7f\u7528<span style=\"color:#fe2c24\">\u540c\u4e00\u7ec4\u6563\u5217\u51fd\u6570\u7684\u5e03\u9686\u8fc7\u6ee4\u5668\u53ef\u4ee5\u8fdb\u884c\u4ea4\u3001\u5e76\u3001\u5dee\u8fd0\u7b97(\u54c8\u5e0c\u5207\u5272)<\/span><\/p>\n<h3><span style=\"color:#0d0016\">2.9 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u7f3a\u70b9<\/span><\/h3>\n<p>1. \u6709\u8bef\u5224\u7387&#xff0c;\u5373\u5b58\u5728\u5047\u9633\u6027(False Position)&#xff0c;\u5373\u4e0d\u80fd\u51c6\u786e\u5224\u65ad\u5143\u7d20\u662f\u5426\u5728\u96c6\u5408\u4e2d(<span style=\"color:#fe2c24\">\u8865\u6551\u65b9\u6cd5&#xff1a;1&#xff0c;\u518d \u5efa\u7acb\u4e00\u4e2a\u767d\u540d\u5355&#xff0c;\u5b58\u50a8\u53ef\u80fd\u4f1a\u8bef\u5224\u7684\u6570\u636e\u30022&#xff0c;\u5bf9\u5728\u7684\u573a\u666f\u8fdb\u884c\u7279\u6b8a\u5904\u7406<\/span>)<\/p>\n<p>2. <span style=\"color:#fe2c24\">\u4e0d\u80fd\u83b7\u53d6\u5143\u7d20\u672c\u8eab<\/span><\/p>\n<p>3. <span style=\"color:#fe2c24\">\u4e00\u822c\u60c5\u51b5\u4e0b\u4e0d\u80fd\u4ece\u5e03\u9686\u8fc7\u6ee4\u5668\u4e2d\u5220\u9664\u5143\u7d20<\/span><\/p>\n<p>4. \u5982\u679c\u91c7\u7528\u8ba1\u6570\u65b9\u5f0f\u5220\u9664&#xff0c;\u53ef\u80fd\u4f1a\u5b58\u5728\u8ba1\u6570\u56de\u7ed5\u3001\u5220\u9664\u4e0d\u5728\u7684\u5143\u7d20\u3001\u65e0\u6cd5\u53bb\u91cd\u7b49\u95ee\u9898\u3002<\/p>\n<h3> 2.10 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u6d77\u91cf\u6570\u636e\u5904\u7406<\/h3>\n<p>1\u3001\u7ed9\u4e24\u4e2a\u6587\u4ef6&#xff0c;\u5206\u522b\u6709100\u4ebf\u4e2aquery&#xff08;<span style=\"color:#fe2c24\">\u672c\u8d28\u5c31\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u5982sql\u8bed\u53e5<\/span>&#xff09;&#xff0c;\u6211\u4eec\u53ea\u67091G\u5185\u5b58&#xff0c;\u5982\u4f55\u627e\u5230\u4e24\u4e2a\u6587\u4ef6\u4ea4\u96c6&#xff1f;\u5206\u522b\u7ed9\u51fa\u7cbe\u786e\u7b97\u6cd5\u548c\u8fd1\u4f3c\u7b97\u6cd5<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1200\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042704-6839339883679.png\" width=\"1200\" \/><\/p>\n<p>\u603b\u7ed3&#xff1a;<\/p>\n<p>1,\u5229\u7528\u4e00\u4e2a\u54c8\u5e0c\u51fd\u6570\u8fdb\u884c\u54c8\u5e0c\u5207\u5206&#xff0c;\u6839\u636e\u5177\u4f53\u60c5\u51b5\u5c06A\u548cB\u5206\u522b\u5207\u5272\u6210\u591a\u4e2a\u5c0f\u6587\u4ef6\u3002<\/p>\n<p>2,\u7528\u4e00\u4e2aset\u6765\u8bfb\u53d6\u5c0f\u6587\u4ef6<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u5982\u679c\u90fd\u53ef\u4ee5\u63d2\u5165&#xff0c;\u90a3\u4e48\u5c31\u662f\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5&#xff1a;&#xff08;1&#xff09;\u5355\u4e2a\u6587\u4ef6\u6bd4\u8f83\u5c0f&#xff0c;\u6240\u4ee5\u53ef\u4ee5\u63d2\u5165\u8fdb\u53bb\u3002&#xff08;2&#xff09;\u5355\u4e2a\u6587\u4ef6\u6bd4\u8f83\u5927&#xff0c;\u4f46\u662f\u5176\u4e2d\u5b58\u5728\u67d0\u4e2a\u5927\u91cf\u91cd\u590d\u7684query&#xff08;<span style=\"color:#fe2c24\">\u6b64\u65f6\u6362\u4e2a\u54c8\u5e0c\u51fd\u6570\u5207\u5272\u4e5f\u662f\u6ca1\u7528\u7684&#xff0c;\u5207\u4e0d\u52a8<\/span>&#xff09;\u3002\u4f46\u662f\u7531\u4e8eset\u4e0d\u652f\u6301\u952e\u503c\u5197\u4f59&#xff0c;\u6240\u4ee5\u90fd\u4e0d\u4f1a\u6b63\u786e\u63d2\u5165\u8fdb\u53bb\u3002 <span style=\"color:#fe2c24\">\u6b64\u65f6\u76f4\u63a5\u628a\u53e6\u4e00\u4e2a\u6587\u4ef6\u62ff\u8fc7\u6765\u6bd4\u5bf9\u5373\u53ef\u3002<\/span><\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u5982\u679c\u63d2\u5165\u7684\u8fc7\u7a0b\u4e2d<span style=\"color:#fe2c24\">\u51fa\u73b0\u629b\u5f02\u5e38&#xff08;\u5185\u5b58\u4e0d\u591f\u624d\u4f1a\u629b\u5f02\u5e38&#xff09;<\/span>&#xff0c;\u90a3\u4e48\u5c31\u662f\u4ee5\u4e0b\u60c5\u51b5&#xff1a;\u5355\u4e2a\u6587\u4ef6\u6bd4\u8f83\u5927&#xff0c;\u5e76\u4e14\u5b58\u5728\u5927\u91cf\u4e0d\u540c\u7684query&#xff0c;\u6b64\u65f6\u6211\u4eec\u5c31\u518d<span style=\"color:#fe2c24\">\u6362\u4e00\u4e2a\u54c8\u5e0c\u51fd\u6570\u8fdb\u884c\u5207\u5272&#xff0c;\u5c06\u8be5\u6587\u4ef6\u5207\u5f97\u66f4\u5c0f\u4e00\u70b9\u3002<\/span><\/p>\n<h3><span style=\"color:#0d0016\">2.11 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u8bef\u5224\u7387\u6d4b\u8bd5\u4ee3\u7801<\/span><\/h3>\n<p>void test_bloomfilter2()<br \/>\n{<br \/>\nsrand((unsigned int)time(0));<br \/>\nconst size_t N &#061; 10000;<br \/>\nBloomFilter&lt;N&gt; bf;<\/p>\n<p>vector&lt;string&gt; v1;<br \/>\nstring url &#061; &#034;https:\/\/www.cnblogs.com\/-clq\/archive\/2012\/05\/31\/2528153.html&#034;;<\/p>\n<p>for (size_t i &#061; 0; i &lt; N; &#043;&#043;i)<br \/>\n{<br \/>\nv1.push_back(url &#043; to_string(i));<br \/>\n}<\/p>\n<p>for (auto&amp; str : v1)<br \/>\n{<br \/>\nbf.set(str);<br \/>\n}<\/p>\n<p>\/\/ v2\u8ddfv1\u662f\u76f8\u4f3c\u5b57\u7b26\u4e32\u96c6&#xff0c;\u4f46\u662f\u4e0d\u4e00\u6837<br \/>\nvector&lt;string&gt; v2;<br \/>\nfor (size_t i &#061; 0; i &lt; N; &#043;&#043;i)<br \/>\n{<br \/>\nstring url &#061; &#034;https:\/\/www.cnblogs.com\/-clq\/archive\/2012\/05\/31\/2528153.html&#034;;<br \/>\nurl &#043;&#061; to_string(999999 &#043; i);<br \/>\nv2.push_back(url);<br \/>\n}<\/p>\n<p>size_t n2 &#061; 0;<br \/>\nfor (auto&amp; str : v2)<br \/>\n{<br \/>\nif (bf.test(str))<br \/>\n{<br \/>\n&#043;&#043;n2;<br \/>\n}<br \/>\n}<br \/>\ncout &lt;&lt; &#034;\u76f8\u4f3c\u5b57\u7b26\u4e32\u8bef\u5224\u7387:&#034; &lt;&lt; (double)n2 \/ (double)N &lt;&lt; endl;<\/p>\n<p>\/\/ \u4e0d\u76f8\u4f3c\u5b57\u7b26\u4e32\u96c6<br \/>\nvector&lt;string&gt; v3;<br \/>\nfor (size_t i &#061; 0; i &lt; N; &#043;&#043;i)<br \/>\n{<br \/>\nstring url &#061; &#034;zhihu.com&#034;;<br \/>\n\/\/string url &#061; &#034;https:\/\/www.cctalk.com\/m\/statistics\/live\/16845432622875&#034;;<br \/>\nurl &#043;&#061; to_string(i &#043; rand());<br \/>\nv3.push_back(url);<br \/>\n}<\/p>\n<p>size_t n3 &#061; 0;<br \/>\nfor (auto&amp; str : v3)<br \/>\n{<br \/>\nif (bf.test(str))<br \/>\n{<br \/>\n&#043;&#043;n3;<br \/>\n}<br \/>\n}<br \/>\ncout &lt;&lt; &#034;\u4e0d\u76f8\u4f3c\u5b57\u7b26\u4e32\u8bef\u5224\u7387:&#034; &lt;&lt; (double)n3 \/ (double)N &lt;&lt; endl; <\/p>\n<p>\u5f53X\u4e3a4\u7684\u65f6\u5019<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"137\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042705-6839339951b23.png\" width=\"1041\" \/>\u00a0\u5f53X\u4e3a5\u7684\u65f6\u5019<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"161\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042705-6839339971e1c.png\" width=\"1120\" \/><\/p>\n<p>\u5f53X\u4e3a6\u7684\u65f6\u5019<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"181\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042705-683933999068c.png\" width=\"1200\" \/>\u00a0\u5f53X\u662f7\u7684\u65f6\u5019<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"157\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042705-68393399b0ad3.png\" width=\"1181\" \/><\/p>\n<p>\u00a0\u6211\u4eec\u53d1\u73b06\u7684\u65f6\u5019\u8fdb\u6b65\u662f\u6bd4\u8f83\u660e\u663e\u7684&#xff0c;\u6240\u4ee5\u6700\u540e\u6211\u9009\u62e9\u4e866<\/p>\n<h3>2.12\u00a0\u54c8\u5e0c\u5207\u5272<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u7ed9\u4e00\u4e2a\u8d85\u8fc7100G\u5927\u5c0f\u7684log file, log\u4e2d\u5b58\u7740IP\u5730\u5740, \u8bbe\u8ba1\u7b97\u6cd5\u627e\u5230\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684IP\u5730\u5740&#xff1f; \u4e0e\u4e0a\u9898\u6761\u4ef6\u76f8\u540c&#xff0c;\u5982\u4f55\u627e\u5230top K\u7684IP&#xff1f;\u5982\u4f55\u76f4\u63a5\u7528Linux\u7cfb\u7edf\u547d\u4ee4\u5b9e\u73b0&#xff1f; \u00a0 \u00a0\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"819\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042705-68393399d0993.png\" width=\"1200\" \/><\/p>\n<p>\u5982\u679c\u662ftop-K\u7684\u8bdd&#xff0c;\u5efa\u4e2a\u5c0f\u5806\u53bb\u4e0d\u65ad\u6bd4\u5bf9\u5373\u53ef&#xff0c;\u6700\u540e\u5269\u4e0b\u7684\u5c31\u662ftop-K\u3002<\/p>\n<h3>2.13 \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u6574\u4f53\u4ee3\u7801\u5b9e\u73b0<\/h3>\n<p>  \/\/\u60f3\u628a\u7c7b\u5f53\u51fd\u6570\u4f7f\u7528 \u5c31\u8981\u60f3\u5230\u4eff\u51fd\u6570<br \/>\n  \/\/\u63d0\u4f9b\u4e09\u4e2a\u5b57\u7b26\u4e32\u54c8\u5e0c\u51fd\u6570<br \/>\nstruct BKDRHash<br \/>\n{<br \/>\nsize_t operator() (const string&amp; s) \/\/\u5b57\u7b26\u4e32\u8f6c\u6574\u578b<br \/>\n{<br \/>\nsize_t hash &#061; 0;<br \/>\nfor (auto e : s)<br \/>\n{<br \/>\nhash &#043;&#061; e;<br \/>\nhash *&#061; 31;<br \/>\n}<br \/>\nreturn hash;<br \/>\n}<br \/>\n};<br \/>\nstruct APHash<br \/>\n{<br \/>\nsize_t operator()(const string&amp; s)<br \/>\n{<br \/>\nsize_t hash &#061; 0;<br \/>\nfor (long i &#061; 0; i &lt; s.size(); i&#043;&#043;)<br \/>\n{<br \/>\nsize_t ch &#061; s[i];<br \/>\nif ((i &amp; 1) &#061;&#061; 0)  hash ^&#061; ((hash &lt;&lt; 7) ^ ch ^ (hash &gt;&gt; 3));<br \/>\nelse               hash ^&#061; (~((hash &lt;&lt; 11) ^ ch ^ (hash &gt;&gt; 5)));<br \/>\n}<br \/>\nreturn hash;<br \/>\n}<br \/>\n};<br \/>\nstruct DJBHash<br \/>\n{<br \/>\nsize_t operator()(const string&amp; s)<br \/>\n{<br \/>\nsize_t hash &#061; 5381;<br \/>\nfor (auto ch : s)  hash &#043;&#061; (hash &lt;&lt; 5) &#043; ch;<br \/>\nreturn hash;<br \/>\n}<br \/>\n};<\/p>\n<p>\/\/\u5e03\u9686\u8fc7\u6ee4\u5668  \u57fa\u672c\u4e0a\u89e3\u51b3\u7684\u662f\u5b57\u7b26\u4e32\u7684\u95ee\u9898 \u5982\u679c\u662f\u6574\u578b\u7684\u8bdd \u8fd8\u662f\u4f4d\u56fe\u66f4\u597d\u7528   \u81f3\u4e8e\u7528\u591a\u5c11\u4e2a\u54c8\u5e0c\u51fd\u6570 \u53d6\u51b3\u4e8e\u5b9e\u9645\u7684\u9700\u6c42<br \/>\n\/\/N\u8868\u793a\u6700\u591a\u4f1a\u63d2\u5165key\u7684\u4e2a\u6570<br \/>\ntemplate&lt;size_t N,<br \/>\nsize_t X&#061;6,<br \/>\nclass K&#061;string,<br \/>\nclass Hash1&#061; BKDRHash,<br \/>\nclass Hash2&#061; APHash,<br \/>\nclass Hash3&#061; DJBHash&gt; \/\/K\u5e76\u4e0d\u786e\u5b9a\u662f\u4ec0\u4e48   \u901a\u8fc7\u591a\u79cdHash\u51fd\u6570\u53bb\u5e2e\u52a9\u6211\u4eec\u6620\u5c04\u4e0d\u540c\u7684\u4f4d\u7f6e<br \/>\n\/\/6\u662f\u6d4b\u8bd5\u7528\u6d4b\u8bd5\u4ee3\u7801\u6d4b\u8bd5\u51fa\u6765\u7684<br \/>\nclass BloomFilter<br \/>\n{<br \/>\npublic:<br \/>\nvoid set(const K&amp; key)<br \/>\n{<br \/>\nsize_t len &#061; N * X;<br \/>\nsize_t hash1 &#061; Hash1()(key) % len;<br \/>\n_bits.set(hash1);<br \/>\nsize_t hash2 &#061; Hash2()(key) % len;<br \/>\n_bits.set(hash2);<br \/>\nsize_t hash3 &#061; Hash3()(key) % len;<br \/>\n_bits.set(hash3);<br \/>\n\/\/cout &lt;&lt; hash1 &lt;&lt; &#034; &#034; &lt;&lt; hash2 &lt;&lt; &#034; &#034; &lt;&lt; hash3 &lt;&lt; endl &lt;&lt; endl; \/\/\u770b\u770b\u6620\u5c04\u7684\u4f4d\u7f6e<br \/>\n}<\/p>\n<p>bool test(const K&amp; key)<br \/>\n{<br \/>\nsize_t len &#061; N * X;<br \/>\nsize_t hash1 &#061; Hash1()(key) % len;<br \/>\nif (_bits.test(hash1) &#061;&#061; false) return false;<br \/>\nsize_t hash2 &#061; Hash2()(key) % len;<br \/>\nif (_bits.test(hash2) &#061;&#061; false) return false;<br \/>\nsize_t hash3 &#061; Hash3()(key) % len;<br \/>\nif (_bits.test(hash3) &#061;&#061; false) return false;<\/p>\n<p>return true;\/\/\u5728\u53ef\u80fd\u4f1a\u6709\u8bef\u5224<br \/>\n}<\/p>\n<p>private:<br \/>\nbitset&lt;N*X&gt; _bits;<br \/>\n};<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042706-6839339a38e27.jpg\" \/> \u00a0 \u00a0 \u00a0\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.9k\u6b21\uff0c\u70b9\u8d5e297\u6b21\uff0c\u6536\u85cf232\u6b21\u3002\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u89e3\u51b3\u4e00\u4e9b\u6d77\u91cf\u6570\u636e\u5904\u7406\u95ee\u9898\uff01\uff01_reset\u7684\u4f5c\u7528\u662f\u8f83\u76ee\u6807\u4f4d\u7f6e\u8bbe\u7f6e\u6210<\/p>\n","protected":false},"author":2,"featured_media":40963,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,190,427],"topic":[],"class_list":["post-40978","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-190","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>STL\uff1a\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668 - \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\/40978.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"STL\uff1a\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.9k\u6b21\uff0c\u70b9\u8d5e297\u6b21\uff0c\u6536\u85cf232\u6b21\u3002\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u89e3\u51b3\u4e00\u4e9b\u6d77\u91cf\u6570\u636e\u5904\u7406\u95ee\u9898\uff01\uff01_reset\u7684\u4f5c\u7528\u662f\u8f83\u76ee\u6807\u4f4d\u7f6e\u8bbe\u7f6e\u6210\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/40978.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-30T04:27:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042702-68393396aa816.gif\" \/>\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=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40978.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/40978.html\",\"name\":\"STL\uff1a\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-30T04:27:07+00:00\",\"dateModified\":\"2025-05-30T04:27:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/40978.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/40978.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40978.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STL\uff1a\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668\"}]},{\"@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":"STL\uff1a\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668 - \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\/40978.html","og_locale":"zh_CN","og_type":"article","og_title":"STL\uff1a\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.9k\u6b21\uff0c\u70b9\u8d5e297\u6b21\uff0c\u6536\u85cf232\u6b21\u3002\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u89e3\u51b3\u4e00\u4e9b\u6d77\u91cf\u6570\u636e\u5904\u7406\u95ee\u9898\uff01\uff01_reset\u7684\u4f5c\u7528\u662f\u8f83\u76ee\u6807\u4f4d\u7f6e\u8bbe\u7f6e\u6210","og_url":"https:\/\/www.wsisp.com\/helps\/40978.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-30T04:27:07+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042702-68393396aa816.gif"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/40978.html","url":"https:\/\/www.wsisp.com\/helps\/40978.html","name":"STL\uff1a\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-30T04:27:07+00:00","dateModified":"2025-05-30T04:27:07+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/40978.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/40978.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/40978.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"STL\uff1a\u4f4d\u56fe\u548c\u5e03\u9686\u8fc7\u6ee4\u5668"}]},{"@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\/40978","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=40978"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40978\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/40963"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=40978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=40978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=40978"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=40978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}