mu_tou_man

导航

 
void resize(int newCapacity)
    {
       Entry[] oldTable = table;
        int oldCapacity = oldTable.length;
         if (oldCapacity == MAXIMUM_CAPACITY)
         {
            threshold = Integer.MAX_VALUE;
           return;
         }

        Entry[] newTable = new Entry[newCapacity];
        transfer(newTable, initHashSeedAsNeeded(newCapacity));
        table = newTable;
        threshold = (int) Math.min(newCapacity * loadFactor, MAXIMUM_CAPACITY + 1);
    }

   
    /**
     * Transfers all entries from current table to newTable.
     */
    void transfer(Entry[] newTable, boolean rehash)
    {
        int newCapacity = newTable.length;
        for (Entry<K, V> e : table)
        {
           while (null != e)
          {
             Entry<K, V> next = e.next;
             if (rehash)
             {
                 e.hash = null == e.key ? 0 : hash(e.key);
             }
             int i = indexFor(e.hash, newCapacity);
             e.next = newTable[i];
             newTable[i] = e;
             e = next;
        }
      }
    }

 

posted on 2016-02-01 23:46  mu_tou_man  阅读(323)  评论(0编辑  收藏  举报