{"id":7418,"date":"2024-04-04T10:01:01","date_gmt":"2024-04-04T02:01:01","guid":{"rendered":""},"modified":"2024-04-04T10:01:01","modified_gmt":"2024-04-04T02:01:01","slug":"Hash\u7b97\u6cd5\u603b\u7ed3","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7418.html","title":{"rendered":"Hash\u7b97\u6cd5\u603b\u7ed3"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

1. Hash\u662f\u4ec0\u4e48\uff0c\u5b83\u7684\u4f5c\u7528<\/h3>\n

\u5148\u4e3e\u4e2a\u4f8b\u5b50\u3002\u6211\u4eec\u6bcf\u4e2a\u6d3b\u5728\u4e16\u4e0a\u7684\u4eba\uff0c\u4e3a\u4e86\u80fd\u591f\u53c2\u4e0e\u5404\u79cd\u793e\u4f1a\u6d3b\u52a8\uff0c\u90fd\u9700\u8981\u4e00\u4e2a\u7528\u4e8e\u8bc6\u522b\u81ea\u5df1\u7684\u6807\u5fd7\u3002\u4e5f\u8bb8\u4f60\u89c9\u5f97\u540d\u5b57\u6216\u662f\u8eab\u4efd\u8bc1\u5c31\u8db3\u4ee5\u4ee3\u8868\u4f60\u8fd9\u4e2a\u4eba\uff0c\u4f46\u662f\u8fd9\u79cd\u4ee3\u8868\u6027\u975e\u5e38\u8106\u5f31\uff0c\u56e0\u4e3a\u91cd\u540d\u7684\u4eba\u5f88\u591a\uff0c\u8eab\u4efd\u8bc1\u4e5f\u53ef\u4ee5\u4f2a\u9020\u3002\u6700\u53ef\u9760\u7684\u529e\u6cd5\u662f\u628a\u4e00\u4e2a\u4eba\u7684\u6240\u6709\u57fa\u56e0\u5e8f\u5217\u8bb0\u5f55\u4e0b\u6765\u7528\u6765\u4ee3\u8868\u8fd9\u4e2a\u4eba\uff0c\u4f46\u663e\u7136\uff0c\u8fd9\u6837\u505a\u5e76\u4e0d\u5b9e\u9645\u3002\u800c\u6307\u7eb9\u770b\u4e0a\u53bb\u662f\u4e00\u79cd\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u867d\u7136\u4e00\u4e9b\u4e13\u4e1a\u7ec4\u7ec7\u4ecd\u7136\u53ef\u4ee5\u6a21\u62df\u67d0\u4e2a\u4eba\u7684\u6307\u7eb9\uff0c\u4f46\u8fd9\u79cd\u4ee3\u4ef7\u5b9e\u5728\u592a\u9ad8\u4e86\u3002<\/p>\n

\u800c\u5bf9\u4e8e\u5728\u4e92\u8054\u7f51\u4e16\u754c\u91cc\u4f20\u9001\u7684\u6587\u4ef6\u6765\u8bf4\uff0c\u5982\u4f55\u6807\u5fd7\u4e00\u4e2a\u6587\u4ef6\u7684\u8eab\u4efd\u540c\u6837\u91cd\u8981\u3002\u6bd4\u5982\u8bf4\u6211\u4eec\u4e0b\u8f7d\u4e00\u4e2a\u6587\u4ef6\uff0c\u6587\u4ef6\u7684\u4e0b\u8f7d\u8fc7\u7a0b\u4e2d\u4f1a\u7ecf\u8fc7\u5f88\u591a\u7f51\u7edc\u670d\u52a1\u5668\u3001\u8def\u7531\u5668\u7684\u4e2d\u8f6c\uff0c\u5982\u4f55\u4fdd\u8bc1\u8fd9\u4e2a\u6587\u4ef6\u5c31\u662f\u6211\u4eec\u6240\u9700\u8981\u7684\u5462\uff1f\u6211\u4eec\u4e0d\u53ef\u80fd\u53bb\u4e00\u4e00\u68c0\u6d4b\u8fd9\u4e2a\u6587\u4ef6\u7684\u6bcf\u4e2a\u5b57\u8282\uff0c\u4e5f\u4e0d\u80fd\u7b80\u5355\u5730\u5229\u7528\u6587\u4ef6\u540d\u3001\u6587\u4ef6\u5927\u5c0f\u8fd9\u4e9b\u6781\u5bb9\u6613\u4f2a\u88c5\u7684\u4fe1\u606f\uff0c\u8fd9\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u9700\u8981\u4e00\u79cd\u6307\u7eb9\u4e00\u6837\u7684\u6807\u5fd7\u6765\u68c0\u67e5\u6587\u4ef6\u7684\u53ef\u9760\u6027\uff0c\u8fd9\u79cd\u6307\u7eb9\u5c31\u662f\u6211\u4eec\u73b0\u5728\u6240\u7528\u7684Hash\u7b97\u6cd5(\u4e5f\u53eb\u6563\u5217\u7b97\u6cd5)\u3002<\/p>\n

\u6563\u5217\u7b97\u6cd5\uff08Hash Algorithm\uff09<\/strong>\uff0c\u53c8\u79f0\u54c8\u5e0c\u7b97\u6cd5\uff0c\u6742\u51d1\u7b97\u6cd5\uff0c\u662f\u4e00\u79cd\u4ece\u4efb\u610f\u6587\u4ef6\u4e2d\u521b\u9020\u5c0f\u7684\u6570\u5b57\u300c\u6307\u7eb9\u300d\u7684\u65b9\u6cd5\u3002\u4e0e\u6307\u7eb9\u4e00\u6837\uff0c\u6563\u5217\u7b97\u6cd5\u5c31\u662f\u4e00\u79cd\u4ee5\u8f83\u77ed\u7684\u4fe1\u606f\u6765\u4fdd\u8bc1\u6587\u4ef6\u552f\u4e00\u6027\u7684\u6807\u5fd7\uff0c\u8fd9\u79cd\u6807\u5fd7\u4e0e\u6587\u4ef6\u7684\u6bcf\u4e00\u4e2a\u5b57\u8282\u90fd\u76f8\u5173\uff0c\u800c\u4e14\u96be\u4ee5\u627e\u5230\u9006\u5411\u89c4\u5f8b\u3002\u56e0\u6b64\uff0c\u5f53\u539f\u6709\u6587\u4ef6\u53d1\u751f\u6539\u53d8\u65f6\uff0c\u5176\u6807\u5fd7\u503c\u4e5f\u4f1a\u53d1\u751f\u6539\u53d8\uff0c\u4ece\u800c\u544a\u8bc9\u6587\u4ef6\u4f7f\u7528\u8005\u5f53\u524d\u7684\u6587\u4ef6\u5df2\u7ecf\u4e0d\u662f\u4f60\u6240\u9700\u6c42\u7684\u6587\u4ef6\u3002<\/p>\n

\u8fd9\u79cd\u6807\u5fd7\u6709\u4f55\u610f\u4e49\u5462\uff1f\u4e4b\u524d\u6587\u4ef6\u4e0b\u8f7d\u8fc7\u7a0b\u5c31\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u4f8b\u5b50\uff0c\u4e8b\u5b9e\u4e0a\uff0c\u73b0\u5728\u5927\u90e8\u5206\u7684\u7f51\u7edc\u90e8\u7f72\u548c\u7248\u672c\u63a7\u5236\u5de5\u5177\u90fd\u5728\u4f7f\u7528\u6563\u5217\u7b97\u6cd5\u6765\u4fdd\u8bc1\u6587\u4ef6\u53ef\u9760\u6027\u3002\u800c\u53e6\u4e00\u65b9\u9762\uff0c\u6211\u4eec\u5728\u8fdb\u884c\u6587\u4ef6\u7cfb\u7edf\u540c\u6b65\u3001\u5907\u4efd\u7b49\u5de5\u5177\u65f6\uff0c\u4f7f\u7528\u6563\u5217\u7b97\u6cd5\u6765\u6807\u5fd7\u6587\u4ef6\u552f\u4e00\u6027\u80fd\u5e2e\u52a9\u6211\u4eec\u51cf\u5c11\u7cfb\u7edf\u5f00\u9500\uff0c\u8fd9\u4e00\u70b9\u5728\u5f88\u591a\u4e91\u5b58\u50a8\u670d\u52a1\u5668\u4e2d\u90fd\u6709\u5e94\u7528\u3002<\/p>\n

\"Hash\u7b97\u6cd5\u603b\u7ed3<\/p>\n

\u5f53\u7136\uff0c\u4f5c\u4e3a\u4e00\u79cd\u6307\u7eb9\uff0c\u6563\u5217\u7b97\u6cd5\u6700\u91cd\u8981\u7684\u7528\u9014\u5728\u4e8e\u7ed9\u8bc1\u4e66\u3001\u6587\u6863\u3001\u5bc6\u7801\u7b49\u9ad8\u5b89\u5168\u7cfb\u6570\u7684\u5185\u5bb9\u6dfb\u52a0\u52a0\u5bc6\u4fdd\u62a4\u3002\u8fd9\u4e00\u65b9\u9762\u7684\u7528\u9014\u4e3b\u8981\u662f\u5f97\u76ca\u4e8e\u6563\u5217\u7b97\u6cd5\u7684\u4e0d\u53ef\u9006\u6027<\/strong>\uff0c\u8fd9\u79cd\u4e0d\u53ef\u9006\u6027\u4f53\u73b0\u5728\uff0c\u4f60\u4e0d\u4ec5\u4e0d\u53ef\u80fd\u6839\u636e\u4e00\u6bb5\u901a\u8fc7\u6563\u5217\u7b97\u6cd5\u5f97\u5230\u7684\u6307\u7eb9\u6765\u83b7\u5f97\u539f\u6709\u7684\u6587\u4ef6\uff0c\u4e5f\u4e0d\u53ef\u80fd\u7b80\u5355\u5730\u521b\u9020\u4e00\u4e2a\u6587\u4ef6\u5e76\u8ba9\u5b83\u7684\u6307\u7eb9\u4e0e\u4e00\u6bb5\u76ee\u6807\u6307\u7eb9\u76f8\u4e00\u81f4\u3002\u6563\u5217\u7b97\u6cd5\u7684\u8fd9\u79cd\u4e0d\u53ef\u9006\u6027\u7ef4\u6301\u7740\u5f88\u591a\u5b89\u5168\u6846\u67b6\u7684\u8fd0\u8425\uff0c\u800c\u8fd9\u4e5f\u5c06\u662f\u672c\u6587\u8ba8\u8bba\u7684\u91cd\u70b9\u3002<\/p>\n

2. Hash\u7b97\u6cd5\u6709\u4ec0\u4e48\u7279\u70b9<\/h3>\n

\u4e00\u4e2a\u4f18\u79c0\u7684 hash \u7b97\u6cd5\uff0c\u5c06\u80fd\u5b9e\u73b0\uff1a<\/p>\n

    \n
  • \u6b63\u5411\u5feb\u901f\uff1a\u7ed9\u5b9a\u660e\u6587\u548c hash \u7b97\u6cd5\uff0c\u5728\u6709\u9650\u65f6\u95f4\u548c\u6709\u9650\u8d44\u6e90\u5185\u80fd\u8ba1\u7b97\u51fa hash \u503c\u3002<\/li>\n
  • \u9006\u5411\u56f0\u96be\uff1a\u7ed9\u5b9a\uff08\u82e5\u5e72\uff09 hash \u503c\uff0c\u5728\u6709\u9650\u65f6\u95f4\u5185\u5f88\u96be\uff08\u57fa\u672c\u4e0d\u53ef\u80fd\uff09\u9006\u63a8\u51fa\u660e\u6587\u3002<\/li>\n
  • \u8f93\u5165\u654f\u611f\uff1a\u539f\u59cb\u8f93\u5165\u4fe1\u606f\u4fee\u6539\u4e00\u70b9\u4fe1\u606f\uff0c\u4ea7\u751f\u7684 hash \u503c\u770b\u8d77\u6765\u5e94\u8be5\u90fd\u6709\u5f88\u5927\u4e0d\u540c\u3002<\/li>\n
  • \u51b2\u7a81\u907f\u514d\uff1a\u5f88\u96be\u627e\u5230\u4e24\u6bb5\u5185\u5bb9\u4e0d\u540c\u7684\u660e\u6587\uff0c\u4f7f\u5f97\u5b83\u4eec\u7684 hash \u503c\u4e00\u81f4\uff08\u53d1\u751f\u51b2\u7a81\uff09\u3002\u5373\u5bf9\u4e8e\u4efb\u610f\u4e24\u4e2a\u4e0d\u540c\u7684\u6570\u636e\u5757\uff0c\u5176hash\u503c\u76f8\u540c\u7684\u53ef\u80fd\u6027\u6781\u5c0f\uff1b\u5bf9\u4e8e\u4e00\u4e2a\u7ed9\u5b9a\u7684\u6570\u636e\u5757\uff0c\u627e\u5230\u548c\u5b83hash\u503c\u76f8\u540c\u7684\u6570\u636e\u5757\u6781\u4e3a\u56f0\u96be\u3002<\/li>\n<\/ul>\n

    \u4f46\u5728\u4e0d\u540c\u7684\u4f7f\u7528\u573a\u666f\u4e2d\uff0c\u5982\u6570\u636e\u7ed3\u6784\u548c\u5b89\u5168\u9886\u57df\u91cc\uff0c\u5176\u4e2d\u5bf9\u67d0\u4e00\u4e9b\u7279\u70b9\u4f1a\u6709\u6240\u4fa7\u91cd\u3002<\/p>\n

    2.1 Hash\u5728\u7ba1\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528<\/h4>\n

    \u5728\u7528\u5230hash\u8fdb\u884c\u7ba1\u7406\u7684\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u5c31\u5bf9\u901f\u5ea6\u6bd4\u8f83\u91cd\u89c6\uff0c\u5bf9\u6297\u78b0\u649e\u4e0d\u592a\u770b\u4e2d\uff0c\u53ea\u8981\u4fdd\u8bc1hash\u5747\u5300\u5206\u5e03\u5c31\u53ef\u4ee5\u3002\u6bd4\u5982hashmap\uff0chash\u503c\uff08key\uff09\u5b58\u5728\u7684\u76ee\u7684\u662f\u52a0\u901f\u952e\u503c\u5bf9\u7684\u67e5\u627e\uff0ckey\u7684\u4f5c\u7528\u662f\u4e3a\u4e86\u5c06\u5143\u7d20\u9002\u5f53\u5730\u653e\u5728\u5404\u4e2a\u6876\u91cc\uff0c\u5bf9\u4e8e\u6297\u78b0\u649e\u7684\u8981\u6c42\u6ca1\u6709\u90a3\u4e48\u9ad8\u3002\u6362\u53e5\u8bdd\u8bf4\uff0chash\u51fa\u6765\u7684key\uff0c\u53ea\u8981\u4fdd\u8bc1value\u5927\u81f4\u5747\u5300\u7684\u653e\u5728\u4e0d\u540c\u7684\u6876\u91cc\u5c31\u53ef\u4ee5\u4e86\u3002\u4f46\u6574\u4e2a\u7b97\u6cd5\u7684set\u6027\u80fd\uff0c\u76f4\u63a5\u4e0ehash\u503c\u4ea7\u751f\u7684\u901f\u5ea6\u6709\u5173\uff0c\u6240\u4ee5\u8fd9\u65f6\u5019\u7684hash\u503c\u7684\u4ea7\u751f\u901f\u5ea6\u5c31\u5c24\u4e3a\u91cd\u8981\uff0c\u4ee5JDK\u4e2d\u7684String.hashCode()\u65b9\u6cd5\u4e3a\u4f8b\uff1a <\/p>\n

    public<\/span> int<\/span> hashCode<\/span>() {\n    int<\/span> h = hash;\n    \/\/hash default value : 0 <\/span>\n    if<\/span> (h == 0<\/span> && value<\/span>.length > 0<\/span>) {\n        \/\/value : char storage<\/span>\n        char<\/span> val[] = value<\/span>;\n        for<\/span> (int<\/span> i = 0<\/span>; i < value<\/span>.length; i++) {\n            h = 31<\/span> * h + val[i];\n        }\n        hash = h;\n    }\n    return<\/span> h;\n}\n<\/code><\/pre>\n

    \u5f88\u7b80\u6d01\u7684\u4e00\u4e2a\u4e58\u52a0\u8fed\u4ee3\u8fd0\u7b97\uff0c\u5728\u4e0d\u5c11\u7684hash\u7b97\u6cd5\u4e2d\uff0c\u4f7f\u7528\u7684\u662f\u5f02\u6216+\u52a0\u6cd5\u8fdb\u884c\u8fed\u4ee3\uff0c\u901f\u5ea6\u548c\u524d\u8005\u5dee\u4e0d\u591a\u3002<\/p>\n

    2.1 Hash\u5728\u5728\u5bc6\u7801\u5b66\u4e2d\u7684\u5e94\u7528<\/h4>\n

    \u5728\u5bc6\u7801\u5b66\u4e2d\uff0chash\u7b97\u6cd5\u7684\u4f5c\u7528\u4e3b\u8981\u662f\u7528\u4e8e\u6d88\u606f\u6458\u8981\u548c\u7b7e\u540d\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b83\u4e3b\u8981\u7528\u4e8e\u5bf9\u6574\u4e2a\u6d88\u606f\u7684\u5b8c\u6574\u6027\u8fdb\u884c\u6821\u9a8c\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u767b\u9646\u77e5\u4e4e\u7684\u65f6\u5019\u90fd\u9700\u8981\u8f93\u5165\u5bc6\u7801\uff0c\u90a3\u4e48\u77e5\u4e4e\u5982\u679c\u660e\u6587\u4fdd\u5b58\u8fd9\u4e2a\u5bc6\u7801\uff0c\u90a3\u4e48\u9ed1\u5ba2\u5c31\u5f88\u5bb9\u6613\u7a83\u53d6\u5927\u5bb6\u7684\u5bc6\u7801\u6765\u767b\u9646\uff0c\u7279\u522b\u4e0d\u5b89\u5168\u3002\u90a3\u4e48\u77e5\u4e4e\u5c31\u60f3\u5230\u4e86\u4e00\u4e2a\u65b9\u6cd5\uff0c\u4f7f\u7528hash\u7b97\u6cd5\u751f\u6210\u4e00\u4e2a\u5bc6\u7801\u7684\u7b7e\u540d\uff0c\u77e5\u4e4e\u540e\u53f0\u53ea\u4fdd\u5b58\u8fd9\u4e2a\u7b7e\u540d\u503c\u3002\u7531\u4e8ehash\u7b97\u6cd5\u662f\u4e0d\u53ef\u9006\u7684\uff0c\u90a3\u4e48\u9ed1\u5ba2\u5373\u4fbf\u5f97\u5230\u8fd9\u4e2a\u7b7e\u540d\uff0c\u4e5f\u4e1d\u6beb\u6ca1\u6709\u7528\u5904\uff1b\u800c\u5982\u679c\u4f60\u5728\u7f51\u7ad9\u767b\u9646\u754c\u9762\u4e0a\u8f93\u5165\u4f60\u7684\u5bc6\u7801\uff0c\u90a3\u4e48\u77e5\u4e4e\u540e\u53f0\u5c31\u4f1a\u91cd\u65b0\u8ba1\u7b97\u4e00\u4e0b\u8fd9\u4e2ahash\u503c\uff0c\u4e0e\u7f51\u7ad9\u4e2d\u50a8\u5b58\u7684\u539fhash\u503c\u8fdb\u884c\u6bd4\u5bf9\uff0c\u5982\u679c\u76f8\u540c\uff0c\u8bc1\u660e\u4f60\u62e5\u6709\u8fd9\u4e2a\u8d26\u6237\u7684\u5bc6\u7801\uff0c\u90a3\u4e48\u5c31\u4f1a\u5141\u8bb8\u4f60\u767b\u9646\u3002\u94f6\u884c\u4e5f\u662f\u5982\u6b64\uff0c\u94f6\u884c\u662f\u4e07\u4e07\u4e0d\u6562\u4fdd\u5b58\u7528\u6237\u5bc6\u7801\u7684\u539f\u6587\u7684\uff0c\u53ea\u4f1a\u4fdd\u5b58\u5bc6\u7801\u7684hash\u503c\u800c\u800c\u5df2\u3002\u5728\u8fd9\u4e9b\u5e94\u7528\u573a\u666f\u91cc\uff0c\u5bf9\u4e8e\u6297\u78b0\u649e\u548c\u6297\u7be1\u6539\u80fd\u529b\u8981\u6c42\u6781\u9ad8\uff0c\u5bf9\u901f\u5ea6\u7684\u8981\u6c42\u5728\u5176\u6b21\u3002\u4e00\u4e2a\u8bbe\u8ba1\u826f\u597d\u7684hash\u7b97\u6cd5\uff0c\u5176\u6297\u78b0\u649e\u80fd\u529b\u662f\u5f88\u9ad8\u7684\u3002\u4ee5MD5\u4e3a\u4f8b\uff0c\u5176\u8f93\u51fa\u957f\u5ea6\u4e3a128\u4f4d\uff0c\u8bbe\u8ba1\u9884\u671f\u78b0\u649e\u6982\u7387\u4e3a\uff0c\u8fd9\u662f\u4e00\u4e2a\u6781\u5c0f\u6781\u5c0f\u7684\u6570\u5b57\u2014\u2014\u800c\u5373\u4fbf\u662f\u5728MD5\u88ab\u738b\u5c0f\u4e91\u6559\u6388\u6fc0\u6d3b\u6210\u529f\u6559\u7a0b\u4e4b\u540e\uff0c\u5176\u78b0\u649e\u6982\u7387\u4e0a\u9650\u4e5f\u9ad8\u8fbe\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u81f3\u5c11\u9700\u8981\u627e\u6b21\u624d\u80fd\u67091\/2\u7684\u6982\u7387\u6765\u627e\u5230\u4e00\u4e2a\u4e0e\u76ee\u6807\u6587\u4ef6\u76f8\u540c\u7684hash\u503c\u3002\u800c\u5bf9\u4e8e\u4e24\u4e2a\u76f8\u4f3c\u7684\u5b57\u7b26\u4e32\uff0cMD5\u52a0\u5bc6\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n

    MD5(\"version1\"<\/span>) = \"966634ebf2fc135707d6753692bf4b1e\"<\/span>;\nMD5(\"version2\"<\/span>) = \"2e0e95285f08a07dea17e7ee111b21c8\"<\/span>;<\/code><\/pre>\n

    \u53ef\u4ee5\u770b\u5230\u4ec5\u4ec5\u4e00\u4e2a\u6bd4\u7279\u4f4d\u7684\u6539\u53d8\uff0c\u4e8c\u8005\u7684MD5\u503c\u5c31\u5929\u5dee\u5730\u522b\u4e86<\/p>\n

    \n

    ps : \u5176\u5b9e\u628ahash\u7b97\u6cd5\u5f53\u6210\u662f\u4e00\u79cd\u52a0\u5bc6\u7b97\u6cd5\uff0c\u8fd9\u662f\u4e0d\u51c6\u786e\u7684\uff0c\u6211\u4eec\u77e5\u9053\u52a0\u5bc6\u603b\u662f\u76f8\u5bf9\u4e8e\u89e3\u5bc6\u800c\u8a00\u7684\uff0c\u6ca1\u6709\u89e3\u5bc6\u4f55\u8c08\u52a0\u5bc6\u5462\uff0cHASH\u7684\u8bbe\u8ba1\u4ee5\u65e0\u6cd5\u89e3\u4e3a\u76ee\u7684\u7684\u3002\u5e76\u4e14\u5982\u679c\u6211\u4eec\u4e0d\u9644\u52a0\u4e00\u4e2a\u968f\u673a\u7684salt\u503c\uff0cHASH\u53e3\u4ee4\u662f\u5f88\u5bb9\u6613\u88ab\u5b57\u5178\u653b\u51fb\u5165\u4fb5\u7684\u3002 <\/p>\n<\/blockquote>\n

    3. Hash\u7b97\u6cd5\u662f\u5982\u4f55\u5b9e\u73b0\u7684\uff1f<\/h3>\n

    \u5bc6\u7801\u5b66\u548c\u4fe1\u606f\u5b89\u5168\u53d1\u5c55\u5230\u73b0\u5728\uff0c\u5404\u79cd\u52a0\u5bc6\u7b97\u6cd5\u548c\u6563\u5217\u7b97\u6cd5\u5df2\u7ecf\u4e0d\u662f\u53ea\u8a00\u7247\u8bed\u6240\u80fd\u89e3\u91ca\u5f97\u4e86\u7684\u3002\u5728\u8fd9\u91cc\u6211\u4eec\u4ec5\u63d0\u4f9b\u51e0\u4e2a\u7b80\u5355\u7684\u6982\u5ff5\u4f9b\u5927\u5bb6\u53c2\u8003\u3002<\/p>\n

    \u4f5c\u4e3a\u6563\u5217\u7b97\u6cd5\uff0c\u9996\u8981\u7684\u529f\u80fd\u5c31\u662f\u8981\u4f7f\u7528\u4e00\u79cd\u7b97\u6cd5\u628a\u539f\u6709\u7684\u4f53\u79ef\u5f88\u5927\u7684\u6587\u4ef6\u4fe1\u606f\u7528\u82e5\u5e72\u4e2a\u5b57\u7b26\u6765\u8bb0\u5f55\uff0c\u8fd8\u8981\u4fdd\u8bc1\u6bcf\u4e00\u4e2a\u5b57\u8282\u90fd\u4f1a\u5bf9\u6700\u7ec8\u7ed3\u679c\u4ea7\u751f\u5f71\u54cd\u3002\u90a3\u4e48\u5927\u5bb6\u4e5f\u8bb8\u5df2\u7ecf\u60f3\u5230\u4e86\uff0c\u6c42\u6a21\u8fd9\u79cd\u7b97\u6cd5\u5c31\u80fd\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u8981\u3002<\/p>\n

    \u4e8b\u5b9e\u4e0a\uff0c\u6c42\u6a21\u7b97\u6cd5\u4f5c\u4e3a\u4e00\u79cd\u4e0d\u53ef\u9006\u7684\u8ba1\u7b97\u65b9\u6cd5\uff0c\u5df2\u7ecf\u6210\u4e3a\u4e86\u6574\u4e2a\u73b0\u4ee3\u5bc6\u7801\u5b66\u7684\u6839\u57fa\u3002\u53ea\u8981\u662f\u6d89\u53ca\u5230\u8ba1\u7b97\u673a\u5b89\u5168\u548c\u52a0\u5bc6\u7684\u9886\u57df\uff0c\u90fd\u4f1a\u6709\u6a21\u8ba1\u7b97\u7684\u8eab\u5f71\u3002\u6563\u5217\u7b97\u6cd5\u4e5f\u5e76\u4e0d\u4f8b\u5916\uff0c\u4e00\u79cd\u6700\u539f\u59cb\u7684\u6563\u5217\u7b97\u6cd5\u5c31\u662f\u5355\u7eaf\u5730\u9009\u62e9\u4e00\u4e2a\u6570\u8fdb\u884c\u6a21\u8fd0\u7b97\uff0c\u6bd4\u5982\u4ee5\u4e0b\u7a0b\u5e8f\u3002<\/p>\n

    # \u6784\u9020\u6563\u5217\u51fd\u6570<\/span>\ndef<\/span> hash<\/span>(a)<\/span>:<\/span>\n    return<\/span> a % 8<\/span>\n\n# \u6d4b\u8bd5\u6563\u5217\u51fd\u6570\u529f\u80fd<\/span>\nprint(hash(233<\/span>))\nprint(hash(234<\/span>))\nprint(hash(235<\/span>))\n\n# \u8f93\u51fa\u7ed3\u679c<\/span>\n- 1<\/span>\n- 2<\/span>\n- 3<\/span><\/code><\/pre>\n

    \u5f88\u663e\u7136\uff0c\u4e0a\u8ff0\u7684\u7a0b\u5e8f\u5b8c\u6210\u4e86\u4e00\u4e2a\u6563\u5217\u7b97\u6cd5\u6240\u5e94\u5f53\u5b9e\u73b0\u7684\u521d\u7ea7\u76ee\u6807\uff1a\u7528\u8f83\u5c11\u7684\u6587\u672c\u91cf\u4ee3\u8868\u5f88\u957f\u7684\u5185\u5bb9\uff08\u6c42\u6a21\u4e4b\u540e\u7684\u6570\u5b57\u80af\u5b9a\u5c0f\u4e8e8\uff09\u3002\u4f46\u4e5f\u8bb8\u4f60\u5df2\u7ecf\u6ce8\u610f\u5230\u4e86\uff0c\u5355\u7eaf\u4f7f\u7528\u6c42\u6a21\u7b97\u6cd5\u8ba1\u7b97\u4e4b\u540e\u7684\u7ed3\u679c\u5e26\u6709\u660e\u663e\u7684\u89c4\u5f8b\u6027\uff0c\u8fd9\u79cd\u89c4\u5f8b\u5c06\u5bfc\u81f4\u7b97\u6cd5\u5c06\u80fd\u96be\u4fdd\u8bc1\u4e0d\u53ef\u9006\u6027\u3002\u6240\u4ee5\u6211\u4eec\u5c06\u4f7f\u7528\u53e6\u5916\u4e00\u79cd\u624b\u6bb5\uff0c\u90a3\u5c31\u662f\u5f02\u6216\u3002<\/p>\n

    \u518d\u6765\u770b\u4e0b\u9762\u4e00\u6bb5\u7a0b\u5e8f\uff0c\u6211\u4eec\u5728\u6563\u5217\u51fd\u6570\u4e2d\u52a0\u5165\u4e00\u4e2a\u5f02\u6216\u8fc7\u7a0b\u3002<\/p>\n

    # \u6784\u9020\u6563\u5217\u51fd\u6570<\/span>\ndef<\/span> hash<\/span>(a)<\/span>:<\/span>\n    return<\/span> (a % 8<\/span>) ^ 5<\/span>\n\n# \u6d4b\u8bd5\u6563\u5217\u51fd\u6570\u529f\u80fd<\/span>\nprint(hash(233<\/span>))\nprint(hash(234<\/span>))\nprint(hash(235<\/span>))\n\n# \u8f93\u51fa\u7ed3\u679c<\/span>\n- 4<\/span>\n- 7<\/span>\n- 6<\/span><\/code><\/pre>\n

    \u5f88\u660e\u663e\u7684\uff0c\u52a0\u5165\u4e00\u5c42\u5f02\u6216\u8fc7\u7a0b\u4e4b\u540e\uff0c\u8ba1\u7b97\u4e4b\u540e\u7684\u7ed3\u679c\u89c4\u5f8b\u6027\u5c31\u4e0d\u662f\u90a3\u4e48\u660e\u663e\u4e86\u3002<\/p>\n

    \u5f53\u7136\uff0c\u5927\u5bb6\u4e5f\u8bb8\u4f1a\u89c9\u5f97\u8fd9\u6837\u7684\u7b97\u6cd5\u4f9d\u65e7\u5f88\u4e0d\u5b89\u5168\uff0c\u5982\u679c\u7528\u6237\u4f7f\u7528\u8fde\u7eed\u53d8\u5316\u7684\u4e00\u7cfb\u5217\u6587\u672c\u4e0e\u8ba1\u7b97\u7ed3\u679c\u76f8\u6bd4\u5bf9\uff0c\u5c31\u5f88\u6709\u53ef\u80fd\u627e\u5230\u7b97\u6cd5\u6240\u5305\u542b\u7684\u89c4\u5f8b\u3002\u4f46\u662f\u6211\u4eec\u8fd8\u6709\u5176\u4ed6\u7684\u529e\u6cd5\u3002\u6bd4\u5982\u5728\u8fdb\u884c\u8ba1\u7b97\u4e4b\u524d\u5bf9\u539f\u59cb\u6587\u672c\u8fdb\u884c\u4fee\u6539\uff0c\u6216\u662f\u52a0\u5165\u989d\u5916\u7684\u8fd0\u7b97\u8fc7\u7a0b\uff08\u5982\u79fb\u4f4d\uff09\uff0c\u6bd4\u5982\u4ee5\u4e0b\u7a0b\u5e8f\u3002<\/p>\n

    # \u6784\u9020\u6563\u5217\u51fd\u6570<\/span>\ndef<\/span> hash<\/span>(a)<\/span>:<\/span>\n    return<\/span> (a + 2<\/span> + (a << 1<\/span>)) % 8<\/span> ^ 5<\/span>\n\n# \u6d4b\u8bd5\u6563\u5217\u51fd\u6570\u529f\u80fd<\/span>\nprint(hash(233<\/span>))\nprint(hash(234<\/span>))\nprint(hash(235<\/span>))\n\n# \u8f93\u51fa\u7ed3\u679c<\/span>\n- 0<\/span>\n- 5<\/span>\n- 6<\/span><\/code><\/pre>\n

    \u8fd9\u6837\u5904\u7406\u5f97\u5230\u7684\u6563\u5217\u7b97\u6cd5\u5c31\u5f88\u96be\u53d1\u73b0\u5176\u5185\u90e8\u89c4\u5f8b\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u5e76\u4e0d\u80fd\u5f88\u8f7b\u6613\u5730\u7ed9\u51fa\u4e00\u4e2a\u6570\uff0c\u8ba9\u5b83\u7ecf\u8fc7\u4e0a\u8ff0\u6563\u5217\u51fd\u6570\u8fd0\u7b97\u4e4b\u540e\u7684\u7ed3\u679c\u7b49\u4e8e4\u2014\u2014\u9664\u975e\u6211\u4eec\u53bb\u7a77\u4e3e\u6d4b\u8bd5\u3002<\/p>\n

    \u4e0a\u9762\u7684\u7b97\u6cd5\u662f\u4e0d\u662f\u5f88\u7b80\u5355\uff1f\u4e8b\u5b9e\u4e0a\uff0c\u4e0b\u9762\u6211\u4eec\u5373\u5c06\u4ecb\u7ecd\u7684\u5e38\u7528\u7b97\u6cd5MD5\u548cSHA1\uff0c\u5176\u672c\u8d28\u7b97\u6cd5\u5c31\u662f\u8fd9\u4e48\u7b80\u5355\uff0c\u53ea\u4e0d\u8fc7\u4f1a\u52a0\u5165\u66f4\u591a\u7684\u5faa\u73af\u548c\u8ba1\u7b97\uff0c\u6765\u52a0\u5f3a\u6563\u5217\u51fd\u6570\u7684\u53ef\u9760\u6027\u3002<\/p>\n

    4. Hash\u6709\u54ea\u4e9b\u6d41\u884c\u7684\u7b97\u6cd5<\/h3>\n

    \u76ee\u524d\u6d41\u884c\u7684 Hash \u7b97\u6cd5\u5305\u62ec MD5\u3001SHA-1 \u548c SHA-2\u3002<\/p>\n

      \n
    • \n

      MD4\uff08RFC 1320\uff09\u662f MIT \u7684 Ronald L. Rivest \u5728 1990 \u5e74\u8bbe\u8ba1\u7684\uff0cMD \u662f Message Digest \u7684\u7f29\u5199\u3002\u5176\u8f93\u51fa\u4e3a 128 \u4f4d\u3002MD4 \u5df2\u8bc1\u660e\u4e0d\u591f\u5b89\u5168\u3002<\/p>\n<\/li>\n

    • \n

      MD5\uff08RFC 1321\uff09\u662f Rivest \u4e8e1991\u5e74\u5bf9 MD4 \u7684\u6539\u8fdb\u7248\u672c\u3002\u5b83\u5bf9\u8f93\u5165\u4ecd\u4ee5 512 \u4f4d\u5206\u7ec4\uff0c\u5176\u8f93\u51fa\u662f 128 \u4f4d\u3002MD5 \u6bd4 MD4 \u590d\u6742\uff0c\u5e76\u4e14\u8ba1\u7b97\u901f\u5ea6\u8981\u6162\u4e00\u70b9\uff0c\u66f4\u5b89\u5168\u4e00\u4e9b\u3002MD5 \u5df2\u88ab\u8bc1\u660e\u4e0d\u5177\u5907\u201d\u5f3a\u6297\u78b0\u649e\u6027\u201d\u3002<\/p>\n<\/li>\n

    • \n

      SHA \uff08Secure Hash Algorithm\uff09\u662f\u4e00\u4e2a Hash \u51fd\u6570\u65cf\uff0c\u7531 NIST\uff08National Institute of Standards and Technology\uff09\u4e8e 1993 \u5e74\u53d1\u5e03\u7b2c\u4e00\u4e2a\u7b97\u6cd5\u3002\u76ee\u524d\u77e5\u540d\u7684 SHA-1 \u5728 1995 \u5e74\u9762\u4e16\uff0c\u5b83\u7684\u8f93\u51fa\u4e3a\u957f\u5ea6 160 \u4f4d\u7684 hash \u503c\uff0c\u56e0\u6b64\u6297\u7a77\u4e3e\u6027\u66f4\u597d\u3002SHA-1 \u8bbe\u8ba1\u65f6\u57fa\u4e8e\u548c MD4 \u76f8\u540c\u539f\u7406\uff0c\u5e76\u4e14\u6a21\u4eff\u4e86\u8be5\u7b97\u6cd5\u3002SHA-1 \u5df2\u88ab\u8bc1\u660e\u4e0d\u5177\u201d\u5f3a\u6297\u78b0\u649e\u6027\u201d\u3002<\/p>\n<\/li>\n

    • \n

      \u4e3a\u4e86\u63d0\u9ad8\u5b89\u5168\u6027\uff0cNIST \u8fd8\u8bbe\u8ba1\u51fa\u4e86 SHA-224\u3001SHA-256\u3001SHA-384\uff0c\u548c SHA-512 \u7b97\u6cd5\uff08\u7edf\u79f0\u4e3a SHA-2\uff09\uff0c\u8ddf SHA-1 \u7b97\u6cd5\u539f\u7406\u7c7b\u4f3c\u3002SHA-3 \u76f8\u5173\u7b97\u6cd5\u4e5f\u5df2\u88ab\u63d0\u51fa\u3002<\/p>\n<\/li>\n<\/ul>\n

      \u53ef\u4ee5\u770b\u51fa\uff0c\u4e0a\u9762\u8fd9\u51e0\u79cd\u6d41\u884c\u7684\u7b97\u6cd5\uff0c\u5b83\u4eec\u6700\u91cd\u8981\u7684\u4e00\u70b9\u533a\u522b\u5c31\u662f\u201d\u5f3a\u6297\u78b0\u649e\u6027\u201d\u3002<\/p>\n

      5. \u90a3\u4e48\uff0c\u4f55\u8c13Hash\u7b97\u6cd5\u7684\u300c\u78b0\u649e\u300d\uff1f<\/h3>\n

      \u4f60\u53ef\u80fd\u5df2\u7ecf\u53d1\u73b0\u4e86\uff0c\u5728\u5b9e\u73b0\u7b97\u6cd5\u7ae0\u8282\u7684\u7b2c\u4e00\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u5c1d\u8bd5\u7684\u6563\u5217\u7b97\u6cd5\u5f97\u5230\u7684\u503c\u4e00\u5b9a\u662f\u4e00\u4e2a\u4e0d\u5927\u4e8e8\u7684\u81ea\u7136\u6570\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u6211\u4eec\u968f\u4fbf\u62ff9\u4e2a\u6570\u53bb\u8ba1\u7b97\uff0c\u80af\u5b9a\u81f3\u5c11\u4f1a\u5f97\u5230\u4e24\u4e2a\u76f8\u540c\u7684\u503c\uff0c\u6211\u4eec\u628a\u8fd9\u79cd\u60c5\u51b5\u5c31\u53eb\u505a\u6563\u5217\u7b97\u6cd5\u7684\u300c\u78b0\u649e\u300d\uff08Collision\uff09\u3002<\/p>\n

      \u8fd9\u5f88\u5bb9\u6613\u7406\u89e3\uff0c\u56e0\u4e3a\u4f5c\u4e3a\u4e00\u79cd\u53ef\u7528\u7684\u6563\u5217\u7b97\u6cd5\uff0c\u5176\u4f4d\u6570\u4e00\u5b9a\u662f\u6709\u9650\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b83\u80fd\u8bb0\u5f55\u7684\u6587\u4ef6\u662f\u6709\u9650\u7684\u2014\u2014\u800c\u6587\u4ef6\u6570\u91cf\u662f\u65e0\u9650\u7684\uff0c\u4e24\u4e2a\u6587\u4ef6\u6307\u7eb9\u53d1\u751f\u78b0\u649e\u7684\u6982\u7387\u6c38\u8fdc\u4e0d\u4f1a\u662f\u96f6\u3002<\/p>\n

      \u4f46\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u6563\u5217\u7b97\u6cd5\u5c31\u4e0d\u80fd\u7528\u4e86\uff0c\u56e0\u4e3a\u51e1\u4e8b\u90fd\u8981\u8003\u8651\u4ee3\u4ef7\uff0c\u4e70\u5149\u6240\u6709\u5f69\u7968\u53bb\u4e2d\u4e00\u6b21\u5934\u5956\u662f\u6beb\u65e0\u610f\u4e49\u7684\u3002\u73b0\u4ee3\u6563\u5217\u7b97\u6cd5\u6240\u5b58\u5728\u7684\u7406\u7531\u5c31\u662f\uff0c\u5b83\u7684\u4e0d\u53ef\u9006\u6027\u80fd\u5728\u8f83\u5927\u6982\u7387\u4e0a\u5f97\u5230\u5b9e\u73b0\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u53d1\u73b0\u78b0\u649e\u7684\u6982\u7387\u5f88\u5c0f\uff0c\u8fd9\u79cd\u78b0\u649e\u80fd\u88ab\u5229\u7528\u7684\u6982\u7387\u66f4\u5c0f\u3002<\/p>\n

      \u968f\u610f\u627e\u5230\u4e00\u7ec4\u78b0\u649e\u662f\u6709\u53ef\u80fd\u7684\uff0c\u53ea\u8981\u7a77\u4e3e\u5c31\u53ef\u4ee5\u3002\u6563\u5217\u7b97\u6cd5\u5f97\u5230\u7684\u6307\u7eb9\u4f4d\u6570\u662f\u6709\u9650\u7684\uff0c\u6bd4\u5982MD5\u7b97\u6cd5\u6307\u7eb9\u5b57\u957f\u4e3a128\u4f4d\uff0c\u610f\u5473\u7740\u53ea\u8981\u6211\u4eec\u7a77\u4e3e21282128\u6b21\uff0c\u5c31\u80af\u5b9a\u80fd\u5f97\u5230\u4e00\u7ec4\u78b0\u649e\u2014\u2014\u5f53\u7136\uff0c\u8fd9\u4e2a\u65f6\u95f4\u4ee3\u4ef7\u662f\u96be\u4ee5\u60f3\u8c61\u7684\uff0c\u800c\u66f4\u91cd\u8981\u7684\u662f\uff0c\u4ec5\u4ec5\u627e\u5230\u4e00\u7ec4\u78b0\u649e\u5e76\u6ca1\u6709\u4ec0\u4e48\u5b9e\u9645\u610f\u4e49\u3002\u66f4\u6709\u610f\u4e49\u7684\u662f\uff0c\u5982\u679c\u6211\u4eec\u5df2\u7ecf\u6709\u4e86\u4e00\u7ec4\u6307\u7eb9\uff0c\u80fd\u5426\u627e\u5230\u4e00\u4e2a\u539f\u59cb\u6587\u4ef6\uff0c\u8ba9\u5b83\u7684\u6563\u5217\u8ba1\u7b97\u7ed3\u679c\u7b49\u4e8e\u8fd9\u7ec4\u6307\u7eb9\u3002\u5982\u679c\u8fd9\u4e00\u70b9\u88ab\u5b9e\u73b0\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u7be1\u6539\u548c\u4f2a\u9020\u7f51\u7edc\u8bc1\u4e66\u3001\u5bc6\u7801\u7b49\u5173\u952e\u4fe1\u606f\u3002<\/p>\n

      \u4f60\u4e5f\u8bb8\u5df2\u7ecf\u542c\u8fc7MD5\u5df2\u7ecf\u88ab\u6fc0\u6d3b\u6210\u529f\u6559\u7a0b\u7684\u65b0\u95fb\u2014\u2014\u4f46\u4e8b\u5b9e\u4e0a\uff0c\u5373\u4fbf\u662fMD5\u8fd9\u79cd\u5df2\u7ecf\u8fc7\u65f6\u7684\u6563\u5217\u7b97\u6cd5\uff0c\u4e5f\u5f88\u96be\u5b9e\u73b0\u9006\u5411\u8fd0\u7b97\u3002\u6211\u4eec\u73b0\u5728\u66f4\u591a\u7684\u8fd8\u662f\u4f9d\u8d56\u4e8e\u6d77\u91cf\u5b57\u5178\u6765\u8fdb\u884c\u5c1d\u8bd5\uff0c\u4e5f\u5c31\u662f\u901a\u8fc7\u5df2\u7ecf\u77e5\u9053\u7684\u5927\u91cf\u7684\u6587\u4ef6\u2014\u2014\u6307\u7eb9\u5bf9\u5e94\u5173\u7cfb\uff0c\u641c\u7d22\u67d0\u4e2a\u6307\u7eb9\u6240\u5bf9\u5e94\u7684\u6587\u4ef6\u662f\u5426\u5728\u6570\u636e\u5e93\u91cc\u5b58\u5728\u3002<\/p>\n

      5.1 MD5\u7684\u5b9e\u9645\u78b0\u649e\u6848\u4f8b<\/h4>\n

      \u4e0b\u9762\u8ba9\u6211\u4eec\u6765\u770b\u770b\u4e00\u4e2a\u771f\u5b9e\u7684\u78b0\u649e\u6848\u4f8b\u3002\u6211\u4eec\u4e4b\u6240\u4ee5\u8bf4MD5\u8fc7\u65f6\uff0c\u662f\u56e0\u4e3a\u5b83\u5728\u67d0\u4e9b\u65f6\u5019\u5df2\u7ecf\u5f88\u96be\u8868\u73b0\u51fa\u6563\u5217\u7b97\u6cd5\u7684\u67d0\u4e9b\u4f18\u52bf\u2014\u2014\u6bd4\u5982\u5728\u5e94\u5bf9\u6587\u4ef6\u7684\u5fae\u5c0f\u4fee\u6539\u65f6\uff0c\u6563\u5217\u7b97\u6cd5\u5f97\u5230\u7684\u6307\u7eb9\u7ed3\u679c\u5e94\u5f53\u6709\u663e\u8457\u7684\u4e0d\u540c\uff0c\u800c\u4e0b\u9762\u7684\u7a0b\u5e8f\u8bf4\u660e\u4e86MD5\u5e76\u4e0d\u80fd\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n

      import hashlib\n\n# \u4e24\u6bb5HEX\u5b57\u8282\u4e32\uff0c\u6ce8\u610f\u5b83\u4eec\u6709\u7ec6\u5fae\u5dee\u522b<\/span>\na = bytearray.fromhex<\/span>(\"0e306561559aa787d00bc6f70bbdfe3404cf03659e704f8534c00ffb659c4c8740cc942feb2da115a3f4155cbb8607497386656d7d1f34a42059d78f5a8dd1ef\"<\/span>)\n\nb = bytearray.fromhex<\/span>(\"0e306561559aa787d00bc6f70bbdfe3404cf03659e744f8534c00ffb659c4c8740cc942feb2da115a3f415dcbb8607497386656d7d1f34a42059d78f5a8dd1ef\"<\/span>)\n\n# \u8f93\u51faMD5\uff0c\u5b83\u4eec\u7684\u7ed3\u679c\u4e00\u81f4<\/span>\nprint(hashlib.md<\/span>5(a).hexdigest<\/span>())\nprint(hashlib.md<\/span>5(b).hexdigest<\/span>())\n\n### a\u548cb\u8f93\u51fa\u7ed3\u679c\u90fd\u4e3a\uff1a<\/span>\ncee9a457e790cf20d4bdaa6d69f01e41\ncee9a457e790cf20d4bdaa6d69f01e41\n<\/code><\/pre>\n

      \u800c\u8bf8\u5982\u6b64\u7c7b\u7684\u78b0\u649e\u6848\u4f8b\u8fd8\u6709\u5f88\u591a\uff0c\u4e0a\u9762\u53ea\u662f\u539f\u59cb\u6587\u4ef6\u76f8\u5bf9\u8f83\u5c0f\u7684\u4e00\u4e2a\u4f8b\u5b50\u3002\u4e8b\u5b9e\u4e0a\u73b0\u5728\u6211\u4eec\u7528\u667a\u80fd\u624b\u673a\u53ea\u8981\u6570\u79d2\u5c31\u80fd\u627e\u5230MD5\u7684\u4e00\u4e2a\u78b0\u649e\u6848\u4f8b\uff0c\u56e0\u6b64\uff0cMD5\u5728\u6570\u5e74\u524d\u5c31\u5df2\u7ecf\u4e0d\u88ab\u63a8\u8350\u4f5c\u4e3a\u5e94\u7528\u4e2d\u7684\u6563\u5217\u7b97\u6cd5\u65b9\u6848\uff0c\u53d6\u4ee3\u5b83\u7684\u662fSHA\u5bb6\u65cf\u7b97\u6cd5\uff0c\u4e5f\u5c31\u662f\u5b89\u5168\u6563\u5217\u7b97\u6cd5\uff08Secure Hash Algorithm\uff0c\u7f29\u5199\u4e3aSHA\uff09\u3002<\/p>\n

      5.2 SHA\u5bb6\u65cf\u7b97\u6cd5\u4ee5\u53caSHA1\u78b0\u649e<\/h4>\n

      \u5b89\u5168\u6563\u5217\u7b97\u6cd5\u4e0eMD5\u7b97\u6cd5\u672c\u8d28\u4e0a\u7684\u7b97\u6cd5\u662f\u7c7b\u4f3c\u7684\uff0c\u4f46\u5b89\u5168\u6027\u8981\u9886\u5148\u5f88\u591a\u2014\u2014\u8fd9\u79cd\u9886\u5148\u578b\u66f4\u591a\u7684\u8868\u73b0\u5728\u78b0\u649e\u653b\u51fb\u7684\u65f6\u95f4\u5f00\u9500\u66f4\u5927\uff0c\u5f53\u7136\u76f8\u5bf9\u5e94\u7684\u8ba1\u7b97\u65f6\u95f4\u4e5f\u4f1a\u6162\u4e00\u70b9\u3002<\/p>\n

      SHA\u5bb6\u65cf\u7b97\u6cd5\u7684\u79cd\u7c7b\u5f88\u591a\uff0c\u6709SHA0\u3001SHA1\u3001SHA256\u3001SHA384\u7b49\u7b49\uff0c\u5b83\u4eec\u7684\u8ba1\u7b97\u65b9\u5f0f\u548c\u8ba1\u7b97\u901f\u5ea6\u90fd\u6709\u5dee\u522b\u3002\u5176\u4e2dSHA1\u662f\u73b0\u5728\u7528\u9014\u6700\u5e7f\u6cdb\u7684\u4e00\u79cd\u7b97\u6cd5\u3002\u5305\u62ecGitHub\u5728\u5185\u7684\u4f17\u591a\u7248\u672c\u63a7\u5236\u5de5\u5177\u4ee5\u53ca\u5404\u79cd\u4e91\u540c\u6b65\u670d\u52a1\u90fd\u662f\u7528SHA1\u6765\u533a\u522b\u6587\u4ef6\uff0c\u5f88\u591a\u5b89\u5168\u8bc1\u4e66\u6216\u662f\u7b7e\u540d\u4e5f\u4f7f\u7528SHA1\u6765\u4fdd\u8bc1\u552f\u4e00\u6027\u3002\u957f\u671f\u4ee5\u6765\uff0c\u4eba\u4eec\u90fd\u8ba4\u4e3aSHA1\u662f\u5341\u5206\u5b89\u5168\u7684\uff0c\u81f3\u5c11\u5927\u5bb6\u8fd8\u6ca1\u6709\u627e\u5230\u4e00\u6b21\u78b0\u649e\u6848\u4f8b\u3002<\/p>\n

      \u4f46\u8fd9\u4e00\u4e8b\u5b9e\u57282017\u5e742\u6708\u7834\u706d\u4e86\u3002CWI\u548cGoogle\u7684\u7814\u7a76\u4eba\u5458\u4eec\u6210\u529f\u627e\u5230\u4e86\u4e00\u4f8bSHA1\u78b0\u649e\uff0c\u800c\u4e14\u5f88\u5389\u5bb3\u7684\u662f\uff0c\u53d1\u751f\u78b0\u649e\u7684\u662f\u4e24\u4e2a\u771f\u5b9e\u7684\u3001\u53ef\u9605\u8bfb\u7684PDF\u6587\u4ef6\u3002\u8fd9\u4e24\u4e2aPDF\u6587\u4ef6\u5185\u5bb9\u4e0d\u76f8\u540c\uff0c\u4f46SHA1\u503c\u5b8c\u5168\u4e00\u6837\u3002(\u5bf9\u4e8e\u8fd9\u4ef6\u4e8b\u7684\u5f71\u54cd\u8303\u56f4\u53ca\u8ba8\u8bba\uff0c\u53ef\u53c2\u8003\u77e5\u4e4e\u4e0a\u7684\u8ba8\u8bba:\u5982\u4f55\u8bc4\u4ef7 2 \u6708 23 \u65e5\u8c37\u6b4c\u5ba3\u5e03\u5b9e\u73b0\u4e86 SHA-1 \u78b0\u649e\uff1f)<\/p>\n

      \u6240\u4ee5\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u5927\u7684\u5546\u4e1a\u673a\u6784\u6765\u8bf4\uff0c MD5 \u548c SHA1 \u5df2\u7ecf\u4e0d\u591f\u5b89\u5168\uff0c\u63a8\u8350\u81f3\u5c11\u4f7f\u7528 SHA2-256 \u7b97\u6cd5\u3002<\/p>\n

      6. Hash\u5728Java\u4e2d\u7684\u5e94\u7528<\/h3>\n

      6.1 HashMap\u7684\u590d\u6742\u5ea6<\/h4>\n

      \u5728\u4ecb\u7ecdHashMap\u7684\u5b9e\u73b0\u4e4b\u524d\uff0c\u5148\u8003\u8651\u4e00\u4e0b\uff0cHashMap\u4e0eArrayList\u548cLinkedList\u5728\u6570\u636e\u590d\u6742\u5ea6\u4e0a\u6709\u4ec0\u4e48\u533a\u522b\u3002\u4e0b\u56fe\u662f\u4ed6\u4eec\u7684\u6027\u80fd\u5bf9\u6bd4\u56fe\uff1a<\/p>\n\n\n\n\n\n\n
      <\/td>\n\u83b7\u53d6<\/td>\n\u67e5\u627e<\/td>\n\u6dfb\u52a0\/\u5220\u9664<\/td>\n \u7a7a\u95f4<\/td>\n<\/tr>\n
      ArrayList<\/td>\nO(1)<\/td>\nO(1)<\/td>\nO(N\uff09<\/td>\nO(N)<\/td>\n<\/tr>\n
      LinkedList<\/td>\nO(N)<\/td>\nO(N)<\/td>\nO(1)<\/td>\nO(N)<\/td>\n<\/tr>\n
      HashMap<\/td>\nO(N\/Bucket_size)<\/td>\nO(N\/Bucket_size)<\/td>\nO(N\/Bucket_size)<\/td>\nO(N)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

      \u53ef\u4ee5\u770b\u51faHashMap\u6574\u4f53\u4e0a\u6027\u80fd\u90fd\u975e\u5e38\u4e0d\u9519\uff0c\u4f46\u662f\u4e0d\u7a33\u5b9a\uff0c\u4e3aO(N\/Buckets)\uff0cN\u5c31\u662f\u4ee5\u6570\u7ec4\u4e2d\u6ca1\u6709\u53d1\u751f\u78b0\u649e\u7684\u5143\u7d20\uff0cBuckets\u662f\u56e0\u78b0\u649e\u4ea7\u751f\u7684\u94fe\u8868\u3002<\/p>\n

      \n

      \u6ce8\uff1a\u53d1\u751f\u78b0\u649e\u5b9e\u9645\u4e0a\u662f\u975e\u5e38\u7a00\u5c11\u7684\uff0c\u6240\u4ee5N\/Bucket_size\u7ea6\u7b49\u4e8e1<\/p>\n<\/blockquote>\n

      HashMap\u662f\u5bf9Array\u4e0eLink\u7684\u6298\u8877\u5904\u7406\uff0cArray\u4e0eLink\u53ef\u4ee5\u8bf4\u662f\u4e24\u4e2a\u901f\u5ea6\u65b9\u5411\u7684\u6781\u7aef\uff0cArray\u6ce8\u91cd\u4e8e\u6570\u636e\u7684\u83b7\u53d6\uff0c\u800c\u5904\u7406\u4fee\u6539\uff08\u6dfb\u52a0\/\u5220\u9664\uff09\u7684\u6548\u7387\u975e\u5e38\u4f4e\uff1bLink\u7531\u4e8e\u662f\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u4fdd\u6301\u7740\u4e0b\u4e00\u4e2a\u5bf9\u8c61\u7684\u6307\u9488\uff0c\u67e5\u627e\u67d0\u4e2a\u6570\u636e\u9700\u8981\u904d\u5386\u4e4b\u524d\u6240\u6709\u7684\u6570\u636e\uff0c\u6240\u4ee5\u6548\u7387\u6bd4\u8f83\u4f4e\uff0c\u800c\u5728\u4fee\u6539\u64cd\u4f5c\u4e2d\u6bd4\u8f83\u5feb\u3002<\/p>\n

      6.2 HashMap\u7684\u5b9e\u73b0<\/h4>\n

      \u672c\u6587\u4ee5JDK8\u7684API\u5b9e\u73b0\u8fdb\u884c\u5206\u6790<\/p>\n

      6.2.1 \u5bf9key\u8fdb\u884cHash\u8ba1\u7b97<\/h5>\n

      \u5728JDK8\u4e2d\uff0c\u7531\u4e8e\u4f7f\u7528\u4e86\u7ea2\u9ed1\u6811\u6765\u5904\u7406\u5927\u7684\u94fe\u8868\u5f00\u9500\uff0c\u6240\u4ee5hash\u8fd9\u8fb9\u53ef\u4ee5\u66f4\u52a0\u7701\u529b\u4e86\uff0c\u53ea\u7528\u8ba1\u7b97hashCode\u5e76\u79fb\u52a8\u5230\u4f4e\u4f4d\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n

      static<\/span> final<\/span> int<\/span> hash(Object key) {\n    int<\/span> h;\n    \/\/\u8ba1\u7b97hashCode\uff0c\u5e76\u65e0\u7b26\u53f7\u79fb\u52a8\u5230\u4f4e\u4f4d<\/span>\n    return<\/span> (key == null<\/span>) ? 0<\/span> : (h = key.hashCode()) ^ (h >>> 16<\/span>);\n}<\/code><\/pre>\n

      \u4e3e\u4e2a\u4f8b\u5b50: 363771819^(363771819 >>> 16)<\/p>\n

      0001 0101 1010 1110 1011 0111 1010 1011(363771819)\n0000 0000 0000 0000 0001 0101 1010 1110(5550) XOR\n--------------------------------------- = <\/span>0001 0101 1010 1110 1010 0010 0000 0101(363766277)<\/code><\/pre>\n

      \u8fd9\u6837\u505a\u53ef\u4ee5\u5b9e\u73b0\u4e86\u9ad8\u5730\u4f4d\u66f4\u52a0\u5747\u5300\u5730\u6df7\u5230\u4e00\u8d77\u3002<\/p>\n

      \u4e0b\u9762\u7ed9\u51fa\u5728Java\u4e2d\u51e0\u4e2a\u5e38\u7528\u7684\u54c8\u5e0c\u7801(hashCode)\u7684\u7b97\u6cd5\u3002<\/p>\n

        \n
      1. \n

        Object\u7c7b\u7684hashCode. \u8fd4\u56de\u5bf9\u8c61\u7684\u7ecf\u8fc7\u5904\u7406\u540e\u7684\u5185\u5b58\u5730\u5740\uff0c\u7531\u4e8e\u6bcf\u4e2a\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u90fd\u4e0d\u4e00\u6837\uff0c\u6240\u4ee5\u54c8\u5e0c\u7801\u4e5f\u4e0d\u4e00\u6837\u3002\u8fd9\u4e2a\u662fnative\u65b9\u6cd5\uff0c\u53d6\u51b3\u4e8eJVM\u7684\u5185\u90e8\u8bbe\u8ba1\uff0c\u4e00\u822c\u662f\u67d0\u79cdC\u5730\u5740\u7684\u504f\u79fb\u3002<\/p>\n<\/li>\n

      2. \n

        String\u7c7b\u7684hashCode. \u6839\u636eString\u7c7b\u5305\u542b\u7684\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\uff0c\u6839\u636e\u4e00\u79cd\u7279\u6b8a\u7b97\u6cd5\u8fd4\u56de\u54c8\u5e0c\u7801\uff0c\u53ea\u8981\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u76f8\u540c\uff0c\u8fd4\u56de\u7684\u54c8\u5e0c\u7801\u4e5f\u76f8\u540c\u3002<\/p>\n<\/li>\n

      3. \n

        Integer\u7b49\u5305\u88c5\u7c7b\uff0c\u8fd4\u56de\u7684\u54c8\u5e0c\u7801\u5c31\u662fInteger\u5bf9\u8c61\u91cc\u6240\u5305\u542b\u7684\u90a3\u4e2a\u6574\u6570\u7684\u6570\u503c\uff0c\u4f8b\u5982Integer i1=new Integer(100), i1.hashCode\u7684\u503c\u5c31\u662f100 \u3002\u7531\u6b64\u53ef\u89c1\uff0c2\u4e2a\u4e00\u6837\u5927\u5c0f\u7684Integer\u5bf9\u8c61\uff0c\u8fd4\u56de\u7684\u54c8\u5e0c\u7801\u4e5f\u4e00\u6837\u3002<\/p>\n<\/li>\n

      4. \n

        int\uff0cchar\u8fd9\u6837\u7684\u57fa\u7840\u7c7b\uff0c\u5b83\u4eec\u4e0d\u9700\u8981hashCode\uff0c\u5982\u679c\u9700\u8981\u5b58\u50a8\u65f6\uff0c\u5c06\u8fdb\u884c\u81ea\u52a8\u88c5\u7bb1\u64cd\u4f5c\uff0c\u8ba1\u7b97\u65b9\u6cd5\u540c\u4e0a\u3002<\/p>\n<\/li>\n<\/ol>\n

        6.2.2 \u83b7\u53d6\u5230\u6570\u7ec4\u7684index\u7684\u4f4d\u7f6e<\/h5>\n

        \u8ba1\u7b97\u4e86Hash\uff0c\u6211\u4eec\u73b0\u5728\u8981\u628a\u5b83\u63d2\u5165\u6570\u7ec4\u4e2d\u4e86<\/p>\n

        i = (tab<\/span>.length<\/span> - 1<\/span>) & hash\uff1b<\/code><\/pre>\n

        \u901a\u8fc7\u4f4d\u8fd0\u7b97\uff0c\u786e\u5b9a\u4e86\u5f53\u524d\u7684\u4f4d\u7f6e\uff0c\u56e0\u4e3aHashMap\u6570\u7ec4\u7684\u5927\u5c0f\u603b\u662f2^n\uff0c\u6240\u4ee5\u5b9e\u9645\u7684\u8fd0\u7b97\u5c31\u662f (0xfff\u2026ff) & hash \uff0c\u8fd9\u91cc\u7684tab.length-1\u76f8\u5f53\u4e8e\u4e00\u4e2amask\uff0c\u6ee4\u6389\u4e86\u5927\u4e8e\u5f53\u524d\u957f\u5ea6\u4f4d\u7684hash\uff0c\u4f7f\u6bcf\u4e2ai\u90fd\u80fd\u63d2\u5165\u5230\u6570\u7ec4\u4e2d\u3002<\/p>\n

        6.2.3 \u751f\u6210\u5305\u88c5\u7c7b<\/h5>\n

        \u8fd9\u4e2a\u5bf9\u8c61\u662f\u4e00\u4e2a\u5305\u88c5\u7c7b\uff0cNode<\/p>\n

        static<\/span> class<\/span> Node<\/span><K<\/span>,V<\/span>> implements<\/span><\/span> Map<\/span>.Entry<\/span><K<\/span>,V<\/span>> { \n   <\/span>\n        final<\/span> int<\/span> hash;\n        final<\/span> K key;\n        V value;\n        Node<K,V> next;\n        \/\/getter and setter .etc.<\/span>\n}<\/code><\/pre>\n
        6.2.4 \u63d2\u5165\u5305\u88c5\u7c7b\u5230\u6570\u7ec4<\/h5>\n

        (1). \u5982\u679c\u8f93\u5165\u5f53\u524d\u7684\u4f4d\u7f6e\u662f\u7a7a\u7684\uff0c\u5c31\u63d2\u8fdb\u53bb\uff0c\u5982\u56fe\uff0c\u5de6\u4e3a\u63d2\u5165\u524d\uff0c\u53f3\u4e3a\u63d2\u5165\u540e<\/p>\n

            0           0\n    |           |\n    1 -> null   1 - > null\n    |           |\n    2 -> null   2 - > null\n    |           | \n    ..-> null   ..- > null\n    |           | \n    i -> null   i - > new node\n    |           |\n    n -> null   n - > null\n<\/code><\/pre>\n

        (2). \u5982\u679c\u5f53\u524d\u4f4d\u7f6e\u5df2\u7ecf\u6709\u4e86node\uff0c\u4e14\u5b83\u4eec\u53d1\u751f\u4e86\u78b0\u649e\uff0c\u5219\u65b0\u7684\u653e\u5230\u524d\u9762\uff0c\u65e7\u7684\u653e\u5230\u540e\u9762\uff0c\u8fd9\u53eb\u505a\u94fe\u5730\u5740\u6cd5\u5904\u7406\u51b2\u7a81\u3002<\/p>\n

            0           0\n    |           |\n    1 -> null   1 - > null\n    |           |\n    2 -> null   2 - > null\n    |           | \n    ..-> null   ..- > null\n    |           | \n    i -> old    i - > new - > old\n    |           |\n    n -> null   n - > null\n<\/code><\/pre>\n

        \u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u5931\u8d25\u7684hashCode\u7b97\u6cd5\u4f1a\u5bfc\u81f4HashMap\u7684\u6027\u80fd\u7531\u6570\u7ec4\u4e0b\u964d\u4e3a\u94fe\u8868\uff0c\u6240\u4ee5\u60f3\u8981\u907f\u514d\u53d1\u751f\u78b0\u649e\uff0c\u5c31\u8981\u63d0\u9ad8hashCode\u7ed3\u679c\u7684\u5747\u5300\u6027\u3002<\/p>\n

        6.3 \u6269\u5bb9<\/h4>\n

        \u5982\u679c\u5f53\u8868\u4e2d\u768475%\u5df2\u7ecf\u88ab\u5360\u7528\uff0c\u5373\u89c6\u4e3a\u9700\u8981\u6269\u5bb9\u4e86<\/p>\n

        (threshold = capacity * load<\/span> factor ) < size<\/span><\/span><\/code><\/pre>\n

        \u5b83\u4e3b\u8981\u6709\u4e24\u4e2a\u6b65\u9aa4\uff1a<\/p>\n

        6.3.1 \u5bb9\u91cf\u52a0\u500d<\/h5>\n

        \u5de6\u79fb1\u4f4d\uff0c\u5c31\u662f\u6269\u5927\u5230\u4e24\u500d\uff0c\u7528\u4f4d\u8fd0\u7b97\u53d6\u4ee3\u4e86\u4e58\u6cd5\u8fd0\u7b97<\/p>\n

        newCap = oldCap << 1<\/span>;<\/span><\/span>\nnewThr = oldThr << 1<\/span>;<\/span><\/span><\/code><\/pre>\n
        6.3.2 \u904d\u5386\u8ba1\u7b97Hash<\/h5>\n
        for<\/span> (int<\/span> j = 0<\/span>; j < oldCap; ++j) {\n        Node<K,V> e;\n        \/\/\u5982\u679c\u53d1\u73b0\u5f53\u524d\u6709Bucket<\/span>\n        if<\/span> ((e = oldTab[j]) != null<\/span>) {\n            oldTab[j] = null<\/span>;\n            \/\/\u5982\u679c\u8fd9\u91cc\u6ca1\u6709\u78b0\u649e<\/span>\n            if<\/span> (e.next == null<\/span>)\n                \/\/\u91cd\u65b0\u8ba1\u7b97Hash\uff0c\u5206\u914d\u4f4d\u7f6e<\/span>\n                newTab[e.hash & (newCap - 1<\/span>)] = e;\n            \/\/\u8fd9\u4e2a\u89c1\u4e0b\u9762\u7684\u65b0\u7279\u6027\u4ecb\u7ecd\uff0c\u5982\u679c\u662f\u6811\uff0c\u5c31\u586b\u5165\u6811<\/span>\n            else<\/span> if<\/span> (e instanceof TreeNode)\n                ((TreeNode<K,V>)e).split(this<\/span>, newTab, j, oldCap);\n            \/\/\u5982\u679c\u662f\u94fe\u8868\uff0c\u5c31\u4fdd\u7559\u987a\u5e8f....\u76ee\u524d\u5c31\u770b\u61c2\u8fd9\u70b9<\/span>\n            else<\/span> { \/\/ preserve order<\/span>\n                Node<K,V> loHead = null<\/span>, loTail = null<\/span>;\n                Node<K,V> hiHead = null<\/span>, hiTail = null<\/span>;\n                Node<K,V> next;\n                do<\/span> {\n                    next = e.next;\n                    if<\/span> ((e.hash & oldCap) == 0<\/span>) {\n                        if<\/span> (loTail == null<\/span>)\n                            loHead = e;\n                        else<\/span>\n                            loTail.next = e;\n                        loTail = e;\n                    }\n                    else<\/span> {\n                        if<\/span> (hiTail == null<\/span>)\n                            hiHead = e;\n                        else<\/span>\n                            hiTail.next = e;\n                        hiTail = e;\n                    }\n                } while<\/span> ((e = next) != null<\/span>);\n                if<\/span> (loTail != null<\/span>) {\n                    loTail.next = null<\/span>;\n                    newTab[j] = loHead;\n                }\n                if<\/span> (hiTail != null<\/span>) {\n                    hiTail.next = null<\/span>;\n                    newTab[j + oldCap] = hiHead;\n                }\n            }\n        }\n    }<\/code><\/pre>\n

        \u7531\u6b64\u53ef\u4ee5\u770b\u51fa\u6269\u5bb9\u9700\u8981\u904d\u5386\u5e76\u91cd\u65b0\u8d4b\u503c\uff0c\u6210\u672c\u975e\u5e38\u9ad8\uff0c\u6240\u4ee5\u9009\u62e9\u4e00\u4e2a\u597d\u7684\u521d\u59cb\u5bb9\u91cf\u975e\u5e38\u91cd\u8981\u3002<\/p>\n

        6.4 \u6269\u5bb9\u5982\u4f55\u63d0\u5347\u6027\u80fd\uff1f<\/h4>\n
          \n
        • \n

          \u89e3\u51b3\u6269\u5bb9\u635f\u5931\uff1a\u5982\u679c\u77e5\u9053\u5927\u81f4\u9700\u8981\u7684\u5bb9\u91cf\uff0c\u628a\u521d\u59cb\u5bb9\u91cf\u8bbe\u7f6e\u597d\u4ee5\u89e3\u51b3\u6269\u5bb9\u635f\u5931\uff1b
          \u6bd4\u5982\u6211\u73b0\u5728\u67091000\u4e2a\u6570\u636e\uff0c\u9700\u8981 1000\/0.75 = 1333 \u4e2a\u5751\u4f4d\uff0c\u53c8 1024 < 1333 < 2048\uff0c\u6240\u4ee5\u6700\u597d\u4f7f\u75282048\u4f5c\u4e3a\u521d\u59cb\u5bb9\u91cf\u3002<\/p>\n<\/li>\n

        • \n

          \u89e3\u51b3\u78b0\u649e\u635f\u5931\uff1a\u4f7f\u7528\u9ad8\u6548\u7684HashCode\u4e0eloadFactor\uff0c\u8fd9\u4e2a\u2026\u7531\u4e8eJDK8\u7684\u9ad8\u6027\u80fd\u51fa\u73b0\uff0c\u8fd9\u513f\u95ee\u9898\u4e5f\u4e0d\u5927\u4e86\u3002<\/p>\n<\/li>\n<\/ul>\n

          6.5 HashMap\u4e0eHashTable\u7684\u4e3b\u8981\u533a\u522b<\/h4>\n

          \u5728\u5f88\u591a\u7684Java\u57fa\u7840\u4e66\u4e0a\u90fd\u5df2\u7ecf\u8bf4\u8fc7\u4e86\uff0c\u4ed6\u4eec\u7684\u4e3b\u8981\u533a\u522b\u5176\u5b9e\u5c31\u662fTable\u5168\u5c40\u52a0\u4e86\u7ebf\u7a0b\u540c\u6b65\u4fdd\u62a4<\/p>\n

            \n
          • HashTable\u7ebf\u7a0b\u66f4\u52a0\u5b89\u5168\uff0c\u4ee3\u4ef7\u5c31\u662f\u56e0\u4e3a\u5b83\u7c97\u66b4\u7684\u6dfb\u52a0\u4e86\u540c\u6b65\u9501\uff0c\u6240\u4ee5\u4f1a\u6709\u6027\u80fd\u635f\u5931\u3002<\/li>\n
          • \u5176\u5b9e\u6709\u66f4\u597d\u7684concurrentHashMap\u53ef\u4ee5\u66ff\u4ee3HashTable\uff0c\u4e00\u4e2a\u662f\u65b9\u6cd5\u7ea7\uff0c\u4e00\u4e2a\u662fClass\u7ea7\u3002<\/li>\n<\/ul>\n

            6.6 \u5728Android\u4e2d\u4f7f\u7528SparseArray\u4ee3\u66ffHashMap<\/h4>\n

            \u5b98\u65b9\u63a8\u8350\u4f7f\u7528SparseArray([sp\u0251:s][\u0259\u2019re\u026a],\u7a00\u758f\u7684\u6570\u7ec4)\u6216\u8005LongSparseArray\u4ee3\u66ffHashMap\u3002\u5b98\u65b9\u603b\u7ed3\u6709\u4e00\u4e0b\u51e0\u70b9\u597d\u5904\uff1a<\/p>\n

              \n
            • \n

              SparseArray\u4f7f\u7528\u57fa\u672c\u7c7b\u578b(Primitive)\u4e2d\u7684int\u4f5c\u4e3aKey\uff0c\u4e0d\u9700\u8981Pair<\/p>\n<\/li>\n<\/ul>\n

              \u603b\u7ed3<\/h3>\n

              \u300cThe Algorithm Design Manual\u300d\u4e00\u4e66\u4e2d\u63d0\u5230\uff0c\u96c5\u864e\u7684 Chief Scientist \uff0cUdi Manber \u66fe\u8bf4\u8fc7\uff0c\u5728 yahoo \u6240\u5e94\u7528\u7684\u7b97\u6cd5\u4e2d\uff0c\u6700\u91cd\u8981\u7684\u4e09\u4e2a\u662f\uff1aHash\uff0cHash \u548c Hash\u3002\u5176\u5b9e\u4ece\u4e0a\u6587\u4e2d\u6240\u4e3e\u7684git\u7528sha1\u5224\u65ad\u6587\u4ef6\u66f4\u6539\uff0c\u5bc6\u7801\u7528MD5\u751f\u6210\u6458\u8981\u540e\u52a0\u76d0\u7b49\u7b49\u5bf9Hash\u7684\u5e94\u7528\u53ef\u770b\u51fa\uff0cHash\u7684\u5728\u8ba1\u7b97\u673a\u4e16\u754c\u626e\u6f14\u7740\u591a\u4e48\u91cd\u8981\u7684\u89d2\u8272\u3002\u53e6\u4e66\u4e2d\u8fd8\u4e3e\u4e86\u4e00\u4e2a\u5f88\u6709\u8da3\u7684\u663e\u793a\u4e2d\u4f8b\u5b50\uff1a<\/p>\n

              \u4e00\u573a\u62cd\u5356\u4f1a\u4e2d\uff0c\u7269\u54c1\u662f\u4ef7\u9ad8\u8005\u5f97\uff0c\u5982\u679c\u6bcf\u4e2a\u4eba\u53ea\u6709\u4e00\u6b21\u51fa\u4ef7\u673a\u4f1a\uff0c\u540c\u65f6\u63d0\u4ea4\u81ea\u5df1\u7684\u4ef7\u683c\u540e\uff0c\u6700\u540e\u4e00\u8d77\u516c\u5e03\uff0c\u51fa\u4ef7\u6700\u9ad8\u5219\u80dc\u51fa\u3002\u8fd9\u79cd\u5f62\u5f0f\u5b58\u5728\u4f5c\u5f0a\u7684\u53ef\u80fd\uff0c\u5982\u679c\u6709\u51fa\u4ef7\u8005\u80fd hack \u8fdb\u540e\u53f0\uff0c\u7136\u540e\u5c06\u81ea\u5df1\u7684\u4ef7\u683c\u6539\u4e3a\u6700\u9ad8\u4ef7 +1\uff0c\u5219\u80fd\u4ee5\u6700\u4f4e\u7684\u4ee3\u4ef7\u83b7\u5f97\u80dc\u5229\u3002\u5982\u4f55\u675c\u7edd\u8fd9\u79cd\u4f5c\u5f0a\u5462\uff1f<\/p>\n

              \u7b54\u6848\u5f88\u7b80\u5355\uff0c\u53c2\u4e0e\u8005\u90fd\u63d0\u4ea4\u81ea\u8eab\u51fa\u4ef7\u7684 hash \u503c\u5c31\u53ef\u4ee5\u4e86\uff0c\u5373\u4f7f\u6709\u4eba\u80fd\u9ed1\u8fdb\u540e\u53f0\u4e5f\u65e0\u6cd5\u5f97\u77e5\u660e\u6587\u4ef7\u683c\uff0c\u7b49\u5230\u516c\u5e03\u4e4b\u65f6\uff0c\u518d\u5bf9\u6bd4\u539f\u51fa\u4ef7\u4e0e hash \u503c\u662f\u5426\u5bf9\u5e94\u5373\u53ef\u3002\u662f\u4e0d\u662f\u5f88\u5de7\u5999\uff1f<\/p>\n

              \u662f\u7684\uff0c\u4e0a\u9762\u7684\u505a\u6cd5\uff0c\u4e0e\u4e0a\u6587\u63d0\u5230\u7684\u7f51\u7ad9\u4e0a\u50a8\u5b58\u5bc6\u7801\u7528MD5 \u503c\u800c\u975e\u660e\u6587\uff0c\u662f\u540c\u4e00\u79cd\u601d\u60f3\uff0c\u6b8a\u9014\u540c\u5f52\u3002<\/p>\n

              \u53ef\u4ee5\u770b\u5230\u65e0\u8bba\u662f\u5bc6\u7801\u5b66\u3001\u6570\u636e\u7ed3\u6784\u3001\u73b0\u5b9e\u751f\u6d3b\u4e2d\u7684\u5e94\u7528\uff0c\u5230\u5904\u53ef\u4ee5\u770b\u5230Hash\u7684\u5f71\u5b50\uff0c\u901a\u8fc7\u8fd9\u7bc7\u6587\u7ae0\u7684\u4ecb\u7ecd\uff0c\u76f8\u4fe1\u4f60\u4e0d\u4ec5\u77e5\u5176\u540d\uff0c\u4e5f\u80fd\u61c2\u5176\u610f\u3002<\/p>\n

              Reference<\/h4>\n
                \n
              1. https:\/\/jizhi.im\/blog\/post\/sha1decrypt<\/li>\n
              2. http:\/\/www.jianshu.com\/p\/e54047b2b563<\/li>\n
              3. https:\/\/www.zhihu.com\/question\/26762707<\/li>\n
              4. http:\/\/mp.weixin.qq.com\/s?__biz=MzA5ODUzOTA0OQ==&mid=2651688220&idx=1&sn=a3f9cb1e186ffe22d9825bca00e85c76&chksm=8b692e5abc1ea74ce61a819f5666dd7d73ee45d6145c92b993de271a315d4f3d3fb3874f9be3&mpshare=1&scene=23&srcid=0414EOLCuLSu17uo8Aw8refB#rd<\/li>\n
              5. http:\/\/mp.weixin.qq.com\/s\/oRLkR7jplqO2qhHtUeTMIA<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"Hash\u7b97\u6cd5\u603b\u7ed3Hash\u662f\u4ec0\u4e48\uff0c\u5b83\u7684\u4f5c\u7528\u5148\u4e3e\u4e2a\u4f8b\u5b50","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7418"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7418"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7418\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}