Exemple #1
0
 public void put(K key, V value) {
   if (size == keys.length) resize(Math.max(8, (int) (size * 1.75f)));
   int index = indexOfKey(key);
   if (index == -1) index = size++;
   keys[index] = key;
   values[index] = value;
 }
Exemple #2
0
 /**
  * Clears the map and reduces the size of the backing arrays to be the specified capacity if they
  * are larger.
  */
 public void clear(int maximumCapacity) {
   if (keys.length <= maximumCapacity) {
     clear();
     return;
   }
   size = 0;
   resize(maximumCapacity);
 }
Exemple #3
0
 public void putAll(ArrayMap map, int offset, int length) {
   if (offset + length > map.size)
     throw new IllegalArgumentException(
         "offset + length must be <= size: " + offset + " + " + length + " <= " + map.size);
   int sizeNeeded = size + length - offset;
   if (sizeNeeded >= keys.length) resize(Math.max(8, (int) (sizeNeeded * 1.75f)));
   System.arraycopy(map.keys, offset, keys, size, length);
   System.arraycopy(map.values, offset, values, size, length);
   size += length;
 }
Exemple #4
0
 public void put(K key, V value, int index) {
   if (size == keys.length) resize(Math.max(8, (int) (size * 1.75f)));
   int existingIndex = indexOfKey(key);
   if (existingIndex != -1) removeIndex(existingIndex);
   System.arraycopy(keys, index, keys, index + 1, size - index);
   System.arraycopy(values, index, values, index + 1, size - index);
   keys[index] = key;
   values[index] = value;
   size++;
 }
Exemple #5
0
 public void insert(int index, K key, V value) {
   if (index > size) throw new IndexOutOfBoundsException(String.valueOf(index));
   if (size == keys.length) resize(Math.max(8, (int) (size * 1.75f)));
   if (ordered) {
     System.arraycopy(keys, index, keys, index + 1, size - index);
     System.arraycopy(values, index, values, index + 1, size - index);
   } else {
     keys[size] = keys[index];
     values[size] = values[index];
   }
   size++;
   keys[index] = key;
   values[index] = value;
 }
Exemple #6
0
 /**
  * Increases the size of the backing arrays to acommodate the specified number of additional
  * entries. Useful before adding many entries to avoid multiple backing array resizes.
  */
 public void ensureCapacity(int additionalCapacity) {
   int sizeNeeded = size + additionalCapacity;
   if (sizeNeeded >= keys.length) resize(Math.max(8, sizeNeeded));
 }
Exemple #7
0
 /**
  * Reduces the size of the backing arrays to the size of the actual number of entries. This is
  * useful to release memory when many items have been removed, or if it is known that more entries
  * will not be added.
  */
 public void shrink() {
   if (keys.length == size) return;
   resize(size);
 }