Exemple #1
0
  /**
   * Grows the capacity of the map to ensure that no additional growth is needed until the size
   * exceeds the specified minimum capacity.
   */
  protected boolean grow(int minimumCapacity) {
    ++modCount;
    int oldCapacity = entryData == null ? 0 : entryData.length;
    if (minimumCapacity > oldCapacity) {
      BasicEList<Entry<K, V>>[] oldEntryData = entryData;
      entryData = newEntryData(2 * oldCapacity + 4);

      for (int i = 0; i < oldCapacity; ++i) {
        BasicEList<Entry<K, V>> oldEList = oldEntryData[i];
        if (oldEList != null) {
          Object[] entries = oldEList.data;
          int size = oldEList.size;
          for (int j = 0; j < size; ++j) {
            @SuppressWarnings("unchecked")
            Entry<K, V> entry = (Entry<K, V>) entries[j];
            int index = indexOf(entry.getHash());
            BasicEList<Entry<K, V>> eList = entryData[index];
            if (eList == null) {
              eList = entryData[index] = newList();
            }
            eList.add(entry);
          }
        }
      }

      return true;
    } else {
      return false;
    }
  }
Exemple #2
0
  /**
   * Called to return the entry list index given the index, the hash, and the key.
   *
   * @param index the entry data index of the key.
   * @param hash the hash code of the key.
   * @param key the key.
   * @return the entry list index.
   */
  protected int entryIndexForKey(int index, int hash, Object key) {
    if (useEqualsForKey() && key != null) {
      BasicEList<Entry<K, V>> eList = entryData[index];
      if (eList != null) {
        Object[] entries = eList.data;
        int size = eList.size;
        for (int j = 0; j < size; ++j) {
          @SuppressWarnings("unchecked")
          Entry<K, V> entry = (Entry<K, V>) entries[j];
          if (entry.getHash() == hash && key.equals(entry.getKey())) {
            return j;
          }
        }
      }
    } else {
      BasicEList<Entry<K, V>> eList = entryData[index];
      if (eList != null) {
        Object[] entries = eList.data;
        int size = eList.size;
        for (int j = 0; j < size; ++j) {
          @SuppressWarnings("unchecked")
          Entry<K, V> entry = (Entry<K, V>) entries[j];
          if (entry.getKey() == key) {
            return j;
          }
        }
      }
    }

    return -1;
  }
Exemple #3
0
 /**
  * Removes the entry from the map.
  *
  * @param entry an entry in the map.
  */
 protected void doRemove(Entry<K, V> entry) {
   if (entryData == null) {
     ++modCount;
     --size;
   } else {
     Object key = entry.getKey();
     int hash = entry.getHash();
     int index = indexOf(hash);
     removeEntry(index, entryIndexForKey(index, hash, key));
     didRemove(entry);
   }
 }
Exemple #4
0
 /**
  * Adds the new entry to the map.
  *
  * @param entry the new entry.
  */
 protected void doPut(Entry<K, V> entry) {
   if (entryData == null) {
     ++modCount;
     ++size;
   } else {
     int hash = entry.getHash();
     grow(size + 1);
     int index = indexOf(hash);
     BasicEList<Entry<K, V>> eList = entryData[index];
     if (eList == null) {
       eList = entryData[index] = newList();
     }
     eList.add(entry);
     ++size;
     didAdd(entry);
   }
 }