{"id":112326,"date":"2020-02-14T21:05:20","date_gmt":"2020-02-14T13:05:20","guid":{"rendered":"http:\/\/4563.org\/?p=112326"},"modified":"2020-02-14T21:05:20","modified_gmt":"2020-02-14T13:05:20","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88-hashmap-%e9%87%8c-putmapentries-%e5%8f%aa%e5%88%a4%e6%96%ad%e4%bc%a0%e5%85%a5-map-%e7%9a%84-size-%e6%98%af%e5%90%a6%e5%a4%a7%e4%ba%8e%e5%bd%93%e5%89%8d-map-%e7%9a%84","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=112326","title":{"rendered":"\u4e3a\u4ec0\u4e48 hashmap \u91cc putMapEntries \u53ea\u5224\u65ad\u4f20\u5165 map \u7684 size \u662f\u5426\u5927\u4e8e\u5f53\u524d map \u7684\u9608\u503c\u5462\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4e3a\u4ec0\u4e48 hashmap \u91cc putMapEntries \u53ea\u5224\u65ad\u4f20\u5165 map \u7684 size \u662f\u5426\u5927\u4e8e\u5f53\u524d map \u7684\u9608\u503c\u5462\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <span><i><\/i> 57<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6e90\u7801\u4e3a jdk1.8.<\/p>\n<pre><code>    final void putMapEntries(Map&lt;? extends K, ? extends V&gt; m, boolean evict) {         int s = m.size();         if (s &gt; 0) {             if (table == null) { \/\/ pre-size                 float ft = ((float)s \/ loadFactor) + 1.0F;                 int t = ((ft &lt; (float)MAXIMUM_CAPACITY) ?                          (int)ft : MAXIMUM_CAPACITY);                 if (t &gt; threshold)                     threshold = tableSizeFor(t);             }             \/\/\u8bf4\u660e table \u5df2\u7ecf\u521d\u59cb\u5316\u8fc7\u4e86\uff0c\u76f4\u63a5\u5224\u65ad s \u662f\u5426\u5927\u4e8e\u5f53\u524d map \u7684\u9608\u503c             else if (s &gt; threshold)                 resize();             for (Map.Entry&lt;? extends K, ? extends V&gt; e : m.entrySet()) {                 K key = e.getKey();                 V value = e.getValue();                 putVal(hash(key), key, value, false, evict);             }         }     } <\/code><\/pre>\n<p>\u4f46\u662f<code>else if (s &gt; threshold)<\/code>\u8fd9\u91cc\u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5\u5199\u6210<code>else if ((s + size) &gt; threshold)<\/code>\u5462\uff1f\u96be\u9053\u4e0d\u5e94\u8be5\u628a\u4f20\u5165 map \u7684\u6620\u5c04\u6570\u91cf\u548c\u5f53\u524d map \u7684\u6620\u5c04\u6570\u91cf\u52a0\u8d77\u6765\u518d\u6bd4\u5417\uff1f<\/p>\n<p>\u8fd9\u6837\u7684\u8bdd\uff0c\u53ef\u80fd\u5728\u6700\u540e\u7684\u5faa\u73af\u91cc\u7684\u67d0\u4e2a putVal \u91cc\uff0c\u53c8\u4f1a\u518d\u6b21 resize \u554a\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898\u5c31\u662f\uff0c\u4e3a\u4ec0\u4e48 float ft = ((float)s \/ loadFactor) + 1.0F;\u6700\u540e\u8fd8\u8981\u52a0 1 \u554a\uff1f \u5c31\u662f\u56e0\u4e3a\u8fd9\u4e2a\u52a0 1\uff0c\u5bfc\u81f4\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\uff1a<\/p>\n<pre><code>import java.util.*;  public class test1 {     public static void main(String[] args) {         HashMap&lt;String,Integer&gt; oldMap = new HashMap&lt;String,Integer&gt;();         for(int i=0;i&lt;12;i++){             oldMap.put(\"\"+i,i);         }         HashMap&lt;String,Integer&gt; newMap = new HashMap&lt;String,Integer&gt;(oldMap);         System.out.println();     } } <\/code><\/pre>\n<p>\u91cc\u9762\u7684 newMap \u660e\u660e\u548c oldMap \u7684\u6620\u5c04\u6570\u91cf\u4e00\u6837\uff0c\u4f46\u662f\u5176\u5bb9\u91cf\u548c\u9608\u503c\u90fd\u662f oldMap \u7684\u4e8c\u500d\u4e86\u3002 <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/06\/20200603_5ed7f8dd25142.png\" alt=\"\u4e3a\u4ec0\u4e48 hashmap \u91cc putMapEntries \u53ea\u5224\u65ad\u4f20\u5165 map \u7684 size \u662f\u5426\u5927\u4e8e\u5f53\u524d map \u7684\u9608\u503c\u5462\uff1f\" \/> \u53ef\u89c1 oldMap \u7684\u5bb9\u91cf\u662f 16\uff0c\u9608\u503c\u662f 12.\u4f46 newMap \u7684\u5bb9\u91cf\u662f 32\uff0c\u9608\u503c\u662f 24. \u56e0\u4e3a 12\/0.75=16\uff0c16 \u518d\u52a0=17,17 \u518d tableSizeFor \u5f97\u5230 32.<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>11<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"269262\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : KentY <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3a\u4ec0\u4e48 \/factor +1 \u6bd4\u8f83\u597d\u7406\u89e3, \u56e0\u4e3a\u540e\u9762\u6bd4\u8f83 threshold \u7b49\u90fd\u662f int \u6bd4\u8f83, \u521a\u521a \/factor \u662f\u4e2a float, \u4f60\u540e\u9762\u7684\u4f8b\u5b50\u6b63\u597d\u6574\u9664, \u4f46\u662f\u5927\u591a\u6570\u4e0d\u4f1a\u662f\u6574\u6570\u7ed3\u679c, \u5982\u679c\u662f 3.1, \u6bd4\u5982, \u90a3\u6211\u4eec\u5e94\u8be5\u53d6 4 \u4e0d\u80fd\u662f 3, \u4e5f\u5c31\u662f(int)(3.1+1)<\/p>\n<p>\u53e6\u4e00\u4e2a\u4e3a\u4ec0\u4e48\u4e0d\u628a\u81ea\u8eab\u7684 size \u52a0\u4e0a. \u6211\u7406\u89e3\u662f\u5f53 s \u5c31\u6bd4 threshold \u5927\u4e86, resize \u7684 requirement \u7684\u6982\u7387\u5c31\u5f88\u5927(\u5e76\u4e0d\u662f 100%), \u800c\u4e14 the more empty the table is, the cheaper the resize() costs. \u6240\u4ee5\u63d0\u524d resize(), \u56e0\u4e3a resize \u662f\u6309\u7167 2 \u7684\u5e42\u6765\u7684, \u540e\u9762 put \u662f\u5426\u9700\u8981\u4e0d\u4e00\u5b9a. \u5982\u679c\u52a0\u4e0a\u81ea\u8eab\u7684, \u5373\u4f7f&gt; threshold, \u867d\u7136\u53ef\u80fd\u4e5f\u4f1a\u9700\u8981 resize, \u53ef\u6982\u7387\u4e0d\u5982\u4e0d\u52a0\u5927, \u6240\u4ee5\u5c31\u7b49\u5230\u9700\u8981\u7684\u65f6\u5019\u518d\u8fdb\u884c. (\u8fd9\u662f\u6211\u7684\u7406\u89e3)<\/p>\n<p> \u81f3\u4e8e\u4f60 concern \u7684\u90a3\u4e2a &#8220;\u53ef\u80fd\u5728\u6700\u540e\u7684\u5faa\u73af\u91cc\u7684\u67d0\u4e2a putVal \u91cc\uff0c\u53c8\u4f1a\u518d\u6b21 resize \u554a&#8221; \u8fd9\u4e2a\u5bf9\u4e8e\u52a0\u4e0d\u52a0\u81ea\u8eab size \u51e0\u4e4e\u6ca1\u5f71\u54cd. \u5982\u679c\u9700\u8981\u540e\u9762\u518d\u6b21 resize \u7684\u60c5\u51b5, \u4f60\uff0b\u4e86\u81ea\u8eab size \u5224\u65ad, \u4e00\u6837\u4f1a\u9700\u8981\u518d resize.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269263\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @KentY <br \/>\u8c22\u8c22\u56de\u7b54\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48 \/factor +1 \u4f60\u7684\u89e3\u91ca\u6211\u5927\u6982\u7406\u89e3\u4e86\uff0c\u5c31\u662f\u8bf4\u5982\u679c\u662f\u5c0f\u6570\u7684\u8bdd\uff0c\u90a3\u4e48\u5e94\u8be5\u5411\u4e0a\u53d6\u6574\uff0c\u5373\u4f7f\u6211\u8fd9\u79cd\u60c5\u51b5\u4f1a\u8ba9\u5bb9\u91cf\u548c\u9608\u503c\u53d8\u6210\u5e94\u6709\u7684\u4e8c\u500d\u3002 \u90a3\u662f\u4e0d\u662f\u610f\u601d\u5c31\u662f \/factor +1 \u662f\u4e3a\u4e86\u4fdd\u62a4\u67d0\u4e2a\u7279\u4f8b\uff0c\u8fd9\u79cd\u7279\u4f8b\u5982\u679c\u4e0d\u52a0 1 \u5c31\u4f1a\u9020\u6210\u5bb9\u91cf\u548c\u9608\u503c\u90fd\u4e0d\u591f\u5927 \uff0c\u4f46\u662f\u6211\u73b0\u5728\u53c8\u60f3\u4e0d\u51fa\u6765\u8fd9\u79cd\u7279\u4f8b\uff08\u5c31\u662f s \u4e3a\u591a\u5c11\u65f6\uff0c\u8fd9\u91cc\u5c31\u5fc5\u987b\u52a0 1 \u4e86\uff09\u3002\u3002\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4e0d\u628a\u81ea\u8eab\u7684 size \u52a0\u4e0a\uff0c\u4f60\u8bf4\u7684\u6211\u4e5f\u5927\u6982\u61c2\u4e86\u3002\u5927\u6982\u5c31\u662f hashmap \u7684\u61d2\u6c49\u6a21\u5f0f\u5427\u3002<br \/>\u6bd4\u5982 s &gt; threshold\uff0c\u4e14\u5f53\u524d map \u7684\u6620\u5c04\u96c6\u5408\u662f\u4f20\u5165 map \u7684\u6620\u5c04\u96c6\u5408\u7684\u5b50\u96c6\u65f6\uff08\u5982\u679c\u662f\u5b50\u96c6\uff0c\u4f1a\u4f7f\u5f97\u4e24\u4e2a map \u5408\u5e76\u540e\uff0c\u6620\u5c04\u6570\u91cf\u6700\u5c11\uff09\uff0c\u5373\u4f7f\u662f\u5408\u5e76\u540e\u6620\u5c04\u6570\u91cf\u6700\u5c11\u7684\u60c5\u51b5\uff0c\u4e5f\u662f\u5fc5\u987b resize \u7684\u3002<br \/>\u5982\u679c s &lt;= threshold\uff0c\u4e14\u4f20\u5165 map \u7684\u6620\u5c04\u96c6\u5408\u662f\u5f53\u524d map \u7684\u6620\u5c04\u96c6\u5408\u7684\u5b50\u96c6\u65f6\uff0c\u8fd9\u79cd\u60c5\u51b5\u5c31\u80af\u5b9a\u4e0d\u9700\u8981 resize \u4e86\u3002\uff08\u8fd9\u79cd\u60c5\u51b5\u5f88\u6781\u7aef\uff0c\u5176\u4ed6\u60c5\u51b5\u8fd8\u662f\u6709\u53ef\u80fd\u5728\u540e\u9762\u7684\u5faa\u73af\u91cc\u518d\u6b21 resize \u7684\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269264\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dyrone <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u90e8\u95e8\u63cf\u8ff0\uff1a\uff5e<\/p>\n<p>\u4ee3\u7801\u5e73\u53f0\uff08\u4ee3\u7801\u6258\u7ba1\u3001\u4ee3\u7801\u6548\u80fd\u3001\u4ee3\u7801\u667a\u80fd\uff09\u662f\u963f\u91cc\u5df4\u5df4\u4e00\u7ad9\u5f0f\u667a\u80fd\u7814\u53d1\u534f\u540c\u5e73\u53f0\u7684\u6838\u5fc3\u670d\u52a1\uff0c\u5bf9\u5185\u4e3a\u963f\u91cc\u51e0\u4e07\u4ea7\u54c1\u7814\u53d1\u76f8\u5173\u4eba\u5458\u63d0\u4f9b\u5de5\u5177\u652f\u6491\uff0c\u5bf9\u5916\u662f\u963f\u91cc\u4e91\u5f00\u53d1\u8005\u751f\u6001\u5173\u952e\u4e00\u73af\u3002\u201cWork Like Alibaba\u201d\u5c06\u6210\u4e3a\u4e2d\u56fd\u53ca\u81f3\u5168\u4e16\u754c\u5f00\u53d1\u8005\u6700\u6f6e\u6d41\u7684\u53e3\u53f7\u3002<\/p>\n<p>\u672c\u804c\u4f4d\u4e3b\u8981\u804c\u8d23\u662f\u8d1f\u8d23\u4ee3\u7801\u5e73\u53f0\u57fa\u7840\u8bbe\u65bd\u7684\u67b6\u6784\u6f14\u8fdb\u3001Git \u6838\u5fc3\u6280\u672f\u5f00\u53d1\uff0c\u4ee3\u7801\u9886\u57df\u6280\u672f\u8d8b\u52bf\u8ddf\u8e2a\u3001\u4e0b\u4e00\u4ee3\u4ee3\u7801\u5e73\u53f0\u9884\u8a00\u3002\u6211\u4eec\u662f\u4e00\u7fa4\u61c2\u4ee3\u7801\uff0c\u7231 Git\uff0c\u6709\u6280\u672f\u6709\u68a6\u60f3\u7684\u5de5\u7a0b\u5e08\u3002\u8ba9\u6211\u4eec\u4e00\u8d77\u643a\u624b\u89e3\u51b3\u8de8\u5730\u57df\u3001\u5206\u5e03\u5f0f\u3001\u6d77\u91cf\u4ee3\u7801\u6258\u7ba1\u7b49\u4e16\u754c\u7ea7\u4e1a\u52a1\u548c\u6280\u672f\u96be\u9898\uff0c\u4e3a\u963f\u91cc\u5df4\u5df4\u96c6\u56e2\u5185\u90e8\u3001\u751f\u6001\u4f19\u4f34\u4ee5\u53ca\u4e91\u4e0a\u5f00\u53d1\u8005\u670d\u52a1\u3002<\/p>\n<p>\u6211\u4eec\u7684\u4f7f\u547d\uff1a\u5e2e\u52a9\u4f01\u4e1a\u8ba9\u66f4\u591a\u7684\u5de5\u4f5c\u5185\u5bb9\u548c\u5de5\u4f5c\u884c\u4e3a \u201c\u6709\u610f\u4e49\u201d \u7684\u6570\u5b57\u5316\u3002<br \/>\u6211\u4eec\u7684\u613f\u666f\uff1a\u670d\u52a1\u4e00\u4ebf\u4eba\u7684\u6570\u5b57\u5316\u529e\u516c\u3002<\/p>\n<p>\u5c97\u4f4d\u63cf\u8ff0\uff1a<br \/>1\u3001\u4ee3\u7801\u5e73\u53f0\u540e\u7aef\u5927\u89c4\u6a21\u670d\u52a1\u5668\u96c6\u7fa4\u7684\u5206\u5e03\u5f0f\u67b6\u6784\u6f14\u8fdb\uff1b<br \/>2\u3001\u670d\u52a1\u5668\u8ba1\u7b97\u3001\u5b58\u50a8\u8d44\u6e90\u7684\u518d\u5e73\u8861\u3001\u6545\u969c\u4fee\u590d\u4e0e\u9694\u79bb\uff0c\u670d\u52a1\u5668\u667a\u80fd\u8fd0\u7ef4\uff1b<br \/>3\u3001\u57fa\u4e8e\u5206\u5e03\u5f0f\u5b58\u50a8\u7684\u4e0b\u4e00\u4ee3\u4ee3\u7801\u5e73\u53f0\uff0c\u5b9e\u73b0\u4f4e\u5ef6\u8fdf\u3001\u9ad8\u6548\u7387\u5728\u7ebf\u7f16\u7801\uff1b<br \/>4\u3001Git \u6838\u5fc3\u4ee3\u7801\u5f00\u53d1\uff0c\u4e1a\u754c\u8d8b\u52bf\u8ddf\u8e2a\uff0c\u4fdd\u6301\u6280\u672f\u9886\u5148\uff0c\u4f18\u5316\u7528\u6237\u4f53\u9a8c\u7b49\u7b49\u3002<\/p>\n<p>\u5c97\u4f4d\u8981\u6c42\uff1a<br \/>1\u30013 \u5230 8 \u5e74\u7684\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u7cbe\u901a Go \u8bed\u8a00\u3001C \u8bed\u8a00\u6216 java \u8bed\u8a00\u7684\u4e00\u79cd\u3002<br \/>2\u3001\u719f\u6089\u5206\u5e03\u5f0f\u4e00\u81f4\u6027\u534f\u8bae\uff0c\u6709\u5206\u5e03\u5f0f\u7cfb\u7edf\u5f00\u53d1\u7ecf\u9a8c\u3002<br \/>3\u3001\u719f\u6089\u5fae\u670d\u52a1\u67b6\u6784\uff0cRPC \u7684\u57fa\u672c\u539f\u7406\u3001gRPC\u3001pb \u7b49\u539f\u7406\u548c\u4f7f\u7528\uff0c\u52a0\u5206\u3002<br \/>4\u3001\u70ed\u7231\u6280\u672f\uff0c\u6709\u8f83\u5f3a\u7684\u5b66\u4e60\u80fd\u529b\u3001\u826f\u597d\u7684\u56e2\u961f\u5408\u4f5c\u80fd\u529b\u3001\u6297\u538b\u80fd\u529b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269265\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : KentY <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dyrone \u8fd8\u4eba\u5de5\u7fa4\u53d1\u5e7f\u544a\u7684\u516c\u53f8&#8230;. \u6280\u672f\u80fd\u597d\u5230\u54ea\u53bb                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269266\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6bcf\u6b21\u53d1\u7684\u6e90\u7801\u8ba8\u8bba\u7684\u5e16\u5b50\u56de\u590d\u7684\u4eba\u90fd\u7279\u522b\u5c11\uff0c\u8fd9\u552f\u4e00\u7684\u4e24\u4eba\u5176\u4e2d\u4e00\u4e2a\u8fd8\u662f\u5e7f\u544a\u3002\u3002\u3002\u662f\u6211\u63d0\u7684\u95ee\u9898\u592a\u4f4e\u7aef\u4e86\u5417\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269267\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wc951 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @amiwrong123 \u53cd\u601d\u4e00\u4e0b\u81ea\u5df1\u662f\u4e0d\u662f\u88ab\u5356\u7247\u7684\u76ef\u4e0a\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269268\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : KentY <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @amiwrong123 <br \/>\u5173\u4e8e+1. loadfactor \u7f3a\u7701\u6709\u4e2a\u503c, 75%, \u5c3d\u7ba1 resize \u90fd\u662f\u6309\u7167 2 \u7684\u5e42, \u8fd9\u6837\u8ba1\u7b97, \u8fd9\u4e2a\u5546\u4e0d\u4f1a\u51fa\u73b0\u5c0f\u6570(\u9ed8\u8ba4\u8d77\u59cb capacity \u4e5f\u662f 16). \u4f46\u662f\u4e0d\u8981\u5fd8\u8bb0, capacity and loadfactory \u662f\u53ef\u4ee5\u7528\u6237\u7ed9\u5b9a\u7684. \u53ef\u662f, resize \u7684\u7b97\u6cd5\u662f\u56fa\u5b9a\u7684, \u6240\u4ee5\u4f1a\u51fa\u73b0\u5c0f\u6570\u7684\u60c5\u51b5. \u5982\u679c\u8981\u51fa\u73b0\u4e0d\u6574\u9664\u7684\u60c5\u51b5\u5f88\u5bb9\u6613, \u4f60\u8bbe\u8ba1\u4e00\u4e2a 2 \u7684\u5e42\u65e0\u6cd5\u6574\u9664\u7684\u9664\u6570\u7684\u5012\u6570\u5c31\u597d\u4e86. <\/p>\n<p>resize \u9700\u8981 re-hash, \u8fd9\u662f hash-table data structure \u91cc\u6700 expensive \u7684\u64cd\u4f5c. \u4f46\u662f\u53c8\u5fc5\u987b\u505a. \u6240\u4ee5\u624d\u6709\u4e86 loadfactor, threshold \u90a3\u4e9b\u96f6\u788e. \u8fd9\u4e9b\u90fd\u6ca1\u6709\u5fc5\u5b9a\u6709\u6548\u7684\u7b56\u7565, \u90fd\u662f\u6309\u7167\u6982\u7387\u6765\u7684. \u540e\u9762\u7684\u5b50\u96c6\u60c5\u51b5\u662f\u7279\u6b8a\u60c5\u51b5, \u4f46\u662f\u6709\u4e00\u90e8\u5206 key \u91cd\u53e0\u662f\u5e38\u89c1\u60c5\u51b5.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269269\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @KentY <br \/>\u5bf9\u54c8\uff0c\u56e0\u4e3a\u5bb9\u91cf\u80af\u5b9a\u662f 2 \u7684\u5e42\uff0c\u4e14\u9ed8\u8ba4\u7684 loadfactor \u662f 0.75 \uff0c\u6240\u4ee5\u6211\u90a3\u79cd\u60c5\u51b5\u4f1a\u5206\u914d\u8fc7\u5927\u3002\u4f46\u5982\u679c loadfactor \u662f\u7528\u6237\u7ed9\u7684\u4e00\u4e2a\u5947\u602a\u7684\u5c0f\u6570\uff08\u8fd9\u5f97\u5565\u7528\u6237\u554a\u3002\u3002\uff09\uff0c\u4f7f\u5f97\u5bb9\u91cf*loadfactor \u4e0d\u7b49\u4e8e\u6574\u6570\u7684\u8bdd\uff0c\u7b97\u51fa\u6765\u7684\u9608\u503c\u4e5f\u662f\u8981\u5411\u4e0b\u53d6\u6574\u7684\u3002\u6240\u4ee5\uff0c\u53cd\u8fc7\u6765\u60f3\uff0c\u7528 size \/ loadfactor \u7b97\u51fa\u7684\u5bb9\u91cf\uff0c\u80af\u5b9a\u4e5f\u8981\u5411\u4e0a\u53d6\u6574\u4e86\u3002<\/p>\n<p>\u56e0\u4e3a\u64cd\u4f5c\u6602\u8d35\uff0c\u6240\u4ee5\u53ea\u8981\u5728\u5fc5\u987b resize \u7684\u60c5\u51b5\u4e0b\u624d resize\uff0c\u5176\u4f59\u9700\u8981 resize \u7684\u60c5\u51b5\uff0c\u5c31\u4ea4\u7ed9 putVal \u518d\u53bb\u89e6\u53d1 resize\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269270\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wc951 <br \/>\u6211\u53ef\u592a\u96be\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269271\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : KentY <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;\u56e0\u4e3a\u64cd\u4f5c\u6602\u8d35\uff0c\u6240\u4ee5\u53ea\u8981\u5728\u5fc5\u987b resize \u7684\u60c5\u51b5\u4e0b\u624d resize\uff0c\u5176\u4f59\u9700\u8981 resize \u7684\u60c5\u51b5\uff0c\u5c31\u4ea4\u7ed9 putVal \u518d\u53bb\u89e6\u53d1 resize\u3002&#8221;<br \/>@amiwrong123 <br \/>\u6211\u89c9\u5f97\u4f60\u8bf4\u7684\u8fd9\u6761\u4e0d\u662f\u592a\u5408\u9002, \u6211\u4eec\u53ef\u4ee5\u8ba8\u8bba.<br \/>resize \u6602\u8d35, \u4f46\u5982\u679c table \u91cc\u9762\u4e1c\u897f\u8d8a\u5c11, \u8fd9\u4e2a&#8221;\u6602\u8d35&#8221;\u7684\u64cd\u4f5c\u8d8a&#8221;\u5ec9\u4ef7&#8221;. \u6240\u4ee5\u6211\u4eec\u5c31\u8981\u627e\u4e00\u4e2a\u60c5\u51b5, \u770b table \u9700\u8981\u8fd9\u4e2a\u6602\u8d35\u64cd\u4f5c\u7684\u6982\u7387\u6709\u591a\u5927, \u5982\u679c\u5f88\u5927, \u6211\u4eec\u5c31\u5c3d\u91cf\u65e9\u505a, \u5982\u679c\u6ca1\u90a3\u4e48\u80af\u5b9a, \u90a3\u5c31\u7b49\u5230\u8be5\u505a\u7684\u65f6\u5019\u505a. \u8fd9\u662f\u6211\u5bf9\u90a3\u4e2a if \u8bed\u53e5\u7684\u60f3\u6cd5.<\/p>\n<p>\u518d\u56de\u6765\u8bf4\u4f60\u7684\u4f8b\u5b50, \u597d\u50cf\u4f60\u89c9\u5f97\u672c\u6765 12, \u53d8\u6210\u4e86 24, \u597d\u50cf\u7a7a\u95f4\u5360\u7528\u4e00\u4e0b\u591a\u4e86\u4e00\u500d. \u5176\u5b9e\u4f60\u4ed4\u7ec6\u60f3\u60f3, \u4f60\u8fd9\u4e2a\u662f\u7279\u4f8b, \u4e0d\u80fd\u63a8\u5e7f\u5230\u6240\u6709\u8be5 x \u7a7a\u95f4\u7684\u90fd\u53d8\u6210 2x, \u56e0\u4e3a\u4f60\u7684\u90a3\u4e2a size \u589e\u957f\u662f\u7ebf\u6027\u7684, \u4f46\u662f resize \u7684\u7ed3\u679c\u662f\u6307\u6570\u7684, \u4f60\u8bf4\u7684\u8fd9\u4e2a\u60c5\u51b5\u53ea\u6709\u5728\u90a3\u4e2a t \u662f\u6574\u6570, \u800c\u4e14\u521a\u597d\u7b49\u4e8e threshold \u7684\u60c5\u51b5\u624d\u4f1a\u53d1\u751f. \u4f60\u518d\u60f3\u60f3, \u5f53\u4e0d\u662f\u521d\u59cb\u5316\u7f3a\u7701\u503c\u7684 case \u4e0b, \u8fd9\u79cd\u60c5\u51b5\u53d1\u751f\u4f1a\u5f88\u5c0f, \u800c\u4e14\u8fd9\u79cd\u5bb3\u5904\u53ea\u4f53\u73b0\u5728 table \u672c\u8eab\u5f88\u5927\u7684\u65f6\u5019. \u53ef\u662f, \u5f53 size \u8d8a\u5927,\u8fd9\u79cd\u60c5\u51b5\u51fa\u73b0\u7684\u6982\u7387\u5c31\u8d8a\u4f4e.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"269272\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : amiwrong123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @KentY <br \/>\u55ef\uff0c\u4f60\u8bf4\u7684\u5173\u4e8e\u9700\u8981\u505a\u7684\u6982\u7387\u8fd9\u4e00\u70b9\u6211\u89c9\u5f97\u6709\u9053\u7406\uff0c\u53cd\u6b63\u5c31\u662f\uff0c\u5982\u679c\u90fd\u63d0\u524d\u77e5\u9053\u9700\u8981\u4e86\uff0c\u90a3\u5c31\u5c3d\u65e9\u505a\u5457\u3002<\/p>\n<p>\u55ef\uff0c\u660e\u767d\u5566\u3002\u6211\u8fd9\u662f\u786e\u5b9e\u662f\u4e2a\u7279\u4f8b\u4e86\uff0c\u800c\u4e14\u5c31\u7b97\u51fa\u73b0\u4e86\u8fd9\u79cd\u7279\u4f8b\uff08\u53d1\u751f\u6982\u7387\u4e5f\u5f88\u4f4e\uff09\uff0c\u4e5f\u53ea\u662f\u591a\u5206\u914d\u70b9\u5927\u5c0f\u561b\uff0c\u4e5f\u6ca1\u5565\u5173\u7cfb\u3002<\/p>\n<p>\u8bdd\u8bf4 jdk \u4f5c\u8005\u8fd8\u60f3\u5f97\u633a\u5468\u5168\uff0c\u56de\u5934\u6211\u7ee7\u7eed\u7cbe\u8bfb HashMap \u6e90\u7801\uff0c\u8981\u662f\u6709\u95ee\u9898\u6211\u8fd8\u60f3\u8bf7\u6559\u4e0b\u5c42\u4e3b                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48 hashmap \u91cc put&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/112326"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=112326"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/112326\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=112326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=112326"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=112326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}