{"id":915,"date":"2019-12-09T16:39:48","date_gmt":"2019-12-09T08:39:48","guid":{"rendered":"http:\/\/47.101.202.111\/?p=915"},"modified":"2022-11-04T09:36:10","modified_gmt":"2022-11-04T01:36:10","slug":"%e7%ae%97%e6%b3%95%e5%93%88%e5%b8%8c%e6%95%a3%e5%88%97","status":"publish","type":"post","link":"http:\/\/139.196.114.170\/?p=915","title":{"rendered":"\u5e38\u6570\u7ea7\u67e5\u627e\u7b97\u6cd5 &#8211; \u54c8\u5e0c\u6563\u5217"},"content":{"rendered":"<p>\u54c8\u5e0c\u51fd\u6570\u7528\u67e5\u8be2\u952e\u503cK\u76f4\u63a5\u8ba1\u7b97\u4e3a\u4e00\u4e2a\u6570\u7ec4\u4e0b\u6807\u7d22\u5f15\uff0c\u5373index = hash(Key)\u5f62\u6210\u4e86\u4e00\u5bf9\u4e00\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u5c06\u67e5\u627e\u7b97\u6cd5\u7b80\u5316\u4e3aO(1)\u590d\u6742\u5ea6<br \/>\n<!--more--><\/p>\n<div class=\"mind no-emojify\" style=\"width:100%;overflow:auto\"><canvas><\/canvas><\/p>\n<div class=\"mindTxt\" style=\"display:none\"><script type=\"text\/javascript\">document.write(\"    - Hash\u6563\u5217\\n        - \u6563\u5217\u51fd\u6570\\n            - \u6574\u6570\\n                - \u9664\u7559\u4f59\u6570\u6cd5\\n            - \u6d6e\u70b9\u6570\\n                - \u4e58\u57fa\u53d6\u6574\u6cd5\\n            - \u5b57\u7b26\u4e32\\n                - \u8fdb\u5236\u9664\u7559\u6cd5\\n            - \u7ec4\u5408\u952e\\n                - \u8fdb\u5236\u9664\u7559\u6cd5\\n        - \u51b2\u7a81\u89e3\u51b3\\n            - \u62c9\u94fe\u6cd5\\n            - \u5f00\u653e\u5b9a\u5740\u6cd5\\n                - \u7ebf\u6027\u63a2\u6d4b\u6cd5\\n                - \u5e73\u65b9\u63a2\u6d4b\u6cd5\\n                - \u4f2a\u968f\u673a\u6570\u6cd5\\n                - \u518d\u6563\u5217\u6cd5\\n\");<\/script><\/div>\n<\/div>\n<h2>\u6563\u5217\u51fd\u6570<\/h2>\n<p>\u5c06N\u4e2a\u952e\u503c\u5747\u5300\u6620\u5c04\u5230M\u4e2a\u4f4d\u7f6e\u4e0a<br \/>\n\u5c3d\u53ef\u80fd\u5229\u7528\u952e\u503c\u4fe1\u606f\u8ba1\u7b97<br \/>\n\u5c3d\u53ef\u80fd\u968f\u673a\u5206\u6563\u51cf\u5c11\u51b2\u7a81<\/p>\n<h3>\u9664\u7559\u4f59\u6570\u6cd5<\/h3>\n<pre lang='java'>hash = K % M<\/pre>\n<p>M\u4e00\u822c\u53d6\u7d20\u6570\uff0c\u589e\u52a0\u952e\u503c\u7684\u4fe1\u606f\u5229\u7528<\/p>\n<h3>\u4e58\u57fa\u53d6\u6574\u6cd5<\/h3>\n<pre lang='java'>hash = Math.round(M * K)<\/pre>\n<p>\u4e5f\u53ef\u7528\u4e8c\u8fdb\u5236\u9664\u7559\u4f59\u6570\u589e\u52a0\u4fe1\u606f\u5229\u7528<\/p>\n<h3>\u5b57\u7b26\u4e32<\/h3>\n<pre lang='java'>\nint hash = 0;\nfor(int i = 0; i < s.length(); i++)\n    hash = (R * hash + s.charAt(i)) % M;\n<\/pre>\n<pre><code>[BKDR HASH\u7b97\u6cd5]\n\u6839\u636e \u4e0d\u540c\u5b57\u7b26 \u53ca \u5b57\u7b26\u6240\u5728\u4e0d\u540c\u4f4d \u533a\u5206\u5b57\u7b26\u4e32\n\u4f7f\u7528\u7c7b\u4f3c\u8fdb\u5236\u65b9\u5f0f\u53ef\u4ee5\u5f88\u597d\u5730\u5c06\u4e0d\u540c\u5b57\u7b26\u4e32\u5206\u6563\n\u53d6\u7cfb\u6570R\u4f5c\u4e3a\u8fdb\u5236\uff0c\u5b57\u7b26\u503c\u4f5c\u4e3a\u6240\u5728\u4f4d\u53d6\u503c\n\u6240\u5f97\u7ed3\u679c\u53d6\u4f59\u5206\u6563\u5230[0, M - 1]\u533a\u95f4\n\n[\u8fdb\u5236\u8ba1\u7b97\u8f6c\u6362]\n\u8fdb\u5236\u7684\u76f4\u89c2\u8ba1\u7b97\nhash = \u03a3 R ^ i * s.charAt(i)\n\u9012\u5f52\u7b97\u6cd5\uff08\u9664k\u53d6\u4f59\u6cd5\u9006\u7528\uff09\nhash = R * hash + s.charAt(i)\n\n[\u4f59\u6570\u7684\u52a0\u6cd5\u5b9a\u7406]\n(a + b) % c = (a % c + b % c) % c\n<\/code><\/pre>\n<h3>\u7ec4\u5408\u952e<\/h3>\n<pre lang='java'>hash =  (R * ((R * K0 + K1) % M) + K2) % M<\/pre>\n<p>BKDR HASH\u7b97\u6cd5\uff0c\u5c06\u6240\u6709\u952e\u503c\u4f5c\u4e3a\u4f4d\u53d6\u503c\u7f16\u7801\u8fdb\u6765<\/p>\n<h2>\u51b2\u7a81\u89e3\u51b3<\/h2>\n<p>\u65b0\u63d2\u5165\u7684\u5143\u7d20\u53d1\u73b0\u6563\u5217\u4f4d\u7f6e\u5df2\u6709\u5143\u7d20\u65f6\uff0c\u5e94\u5b89\u7f6e\u4e00\u4e2a\u65b0\u7684\u5b58\u50a8\u4f4d\u7f6e<\/p>\n<h3>\u62c9\u94fe\u6cd5<\/h3>\n<p>\u6563\u5217\u4f4d\u7f6e\u7684\u9996\u4e2a\u5143\u7d20\u4f5c\u4e3a\u94fe\u8868\u5934\uff0c\u518d\u63d2\u5165\u7684\u5143\u7d20\u52a0\u5165\u94fe\u8868<\/p>\n<h3>\u5f00\u653e\u5b9a\u5740\u6cd5<\/h3>\n<p>\u4ece\u6563\u5217\u4f4d\u7f6e\u5f00\u59cb\uff0c\u7ee7\u7eed\u5411\u524d\u540e\u5bfb\u627e\u65b0\u7684\u4f4d\u7f6e<br \/>\n$\\scriptsize newIndex = (hash(Key) + \\Delta) \\mod M$<\/p>\n<h4>\u7ebf\u6027\u63a2\u6d4b\u6cd5<\/h4>\n<p>\u4ece\u6563\u5217\u4f4d\u7f6e\u5f00\u59cb\uff0c\u6309\u7ebf\u6027\u589e\u91cf\u5411\u540e\u67e5\u627e\uff0c\u76f4\u81f3\u627e\u5230\u4e0b\u4e2a\u7a7a\u4f59\u4f4d\u7f6e<\/p>\n<pre lang=\"java\">\nint i = 0, Delta = 0, oldIndex = hash(Key) % M;\nwhile(Entry[(oldIndex + Delta) % M] != null)\n    Delta = i++;\nint newIndex = (oldIndex + Delta) % M;\n<\/pre>\n<h4>\u5e73\u65b9\u63a2\u6d4b\u6cd5<\/h4>\n<p>\u4ece\u6563\u5217\u4f4d\u7f6e\u5f00\u59cb\uff0c\u6309\u5e73\u65b9\u589e\u91cf\u5411\u540e\u67e5\u627e\uff0c\u76f4\u81f3\u627e\u5230\u4e0b\u4e2a\u7a7a\u4f59\u4f4d\u7f6e<\/p>\n<pre lang=\"java\">\nint i = 0, Delta = 0, int oldIndex = hash(Key) % M;\nwhile(Entry[(oldIndex + Delta) % M] != null)\n    Delta = i * (i++);\nint newIndex = (oldIndex + Delta) % M;\n<\/pre>\n<h4>\u518d\u6563\u5217\u6cd5<\/h4>\n<p>\u5f15\u5165\u7b2c\u4e8c\u4e2ahash\u51fd\u6570\uff0c\u91cd\u65b0\u786e\u5b9a\u5730\u5740<\/p>\n<pre lang=\"java\">\nint Delta = 0, oldIndex = hash(Key) % M;\nwhile(Entry[(oldIndex + Delta) % M] != null)\n    Delta = newHash(Key);\nnewIndex = (oldIndex + Delta) % M;\n<\/pre>\n<h4>\u4f2a\u968f\u673a\u6570\u6cd5<\/h4>\n<p>\u5f15\u5165\u4e00\u4e2a\u968f\u673a\u751f\u6210\u6570\uff0c\u91cd\u65b0\u786e\u5b9a\u5730\u5740<\/p>\n<pre lang=\"java\">\nint Delta = 0, oldIndex = hash(Key) % M;\nwhile(Entry[(oldIndex + Delta) % M] != null)\n    Delta = rand();\nnewIndex = (oldIndex + Delta) % M;\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u54c8\u5e0c\u51fd\u6570\u7528\u67e5\u8be2\u952e\u503cK\u76f4\u63a5\u8ba1\u7b97\u4e3a\u4e00\u4e2a\u6570\u7ec4\u4e0b\u6807\u7d22\u5f15\uff0c\u5373index = hash(Key)\u5f62\u6210\u4e86\u4e00\u5bf9\u4e00\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u5c06 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/139.196.114.170\/?p=915\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u5e38\u6570\u7ea7\u67e5\u627e\u7b97\u6cd5 &#8211; \u54c8\u5e0c\u6563\u5217\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/915"}],"collection":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=915"}],"version-history":[{"count":26,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/915\/revisions"}],"predecessor-version":[{"id":2515,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/915\/revisions\/2515"}],"wp:attachment":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=915"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}