* @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
* memory copy. */\r
public Array (boolean ordered, T[] array, int start, int count) {\r
- this(ordered, array.length, (Class)array.getClass().getComponentType());\r
+ this(ordered, count, (Class)array.getClass().getComponentType());\r
size = count;\r
System.arraycopy(array, 0, items, 0, size);\r
}\r
/** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
* been removed, or if it is known that more items will not be added. */\r
public void shrink () {\r
+ if (items.length == size) return;\r
resize(size);\r
}\r
\r
\r
/** An ordered or unordered map of objects. This implementation uses arrays to store the keys and values, which means\r
* {@link #getKey(Object, boolean) gets} do a comparison for each key in the map. This is slower than a typical hash map\r
- * implementation, but may be acceptable for small maps and has the benefits that keys and values can be accessed by\r
- * index, which makes iteration fast. Like {@link Array}, if ordered is false, * this class avoids a memory copy when\r
- * removing elements (the last element is moved to the removed element's position).\r
+ * implementation, but may be acceptable for small maps and has the benefits that keys and values can be accessed by index, which\r
+ * makes iteration fast. Like {@link Array}, if ordered is false, * this class avoids a memory copy when removing elements (the\r
+ * last element is moved to the removed element's position).\r
* @author Nathan Sweet */\r
public class ArrayMap<K, V> {\r
public K[] keys;\r
/** Reduces the size of the backing arrays to the size of the actual number of entries. This is useful to release memory when\r
* many items have been removed, or if it is known that more entries will not be added. */\r
public void shrink () {\r
+ if (keys.length == size) return;\r
resize(size);\r
}\r
\r
* @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
* memory copy. */\r
public BooleanArray (boolean ordered, boolean[] array, int startIndex, int count) {\r
- this(ordered, array.length);\r
+ this(ordered, count);\r
size = count;\r
System.arraycopy(array, startIndex, items, 0, count);\r
}\r
/** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
* been removed, or if it is known that more items will not be added. */\r
public void shrink () {\r
+ if (items.length == size) return;\r
resize(size);\r
}\r
\r
* @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
* memory copy. */\r
public CharArray (boolean ordered, char[] array, int startIndex, int count) {\r
- this(ordered, array.length);\r
+ this(ordered, count);\r
size = count;\r
System.arraycopy(array, startIndex, items, 0, count);\r
}\r
/** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
* been removed, or if it is known that more items will not be added. */\r
public void shrink () {\r
+ if (items.length == size) return;\r
resize(size);\r
}\r
\r
* @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
* memory copy. */\r
public FloatArray (boolean ordered, float[] array, int startIndex, int count) {\r
- this(ordered, array.length);\r
+ this(ordered, count);\r
size = count;\r
System.arraycopy(array, startIndex, items, 0, count);\r
}\r
addAll(array.items, offset, length);\r
}\r
\r
- public void addAll (float[] array) {\r
+ public void addAll (float... array) {\r
addAll(array, 0, array.length);\r
}\r
\r
/** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
* been removed, or if it is known that more items will not be added. */\r
public void shrink () {\r
+ if (items.length == size) return;\r
resize(size);\r
}\r
\r
* @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
* memory copy. */\r
public IntArray (boolean ordered, int[] array, int startIndex, int count) {\r
- this(ordered, array.length);\r
+ this(ordered, count);\r
size = count;\r
System.arraycopy(array, startIndex, items, 0, count);\r
}\r
/** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
* been removed, or if it is known that more items will not be added. */\r
public void shrink () {\r
+ if (items.length == size) return;\r
resize(size);\r
}\r
\r
* @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
* memory copy. */\r
public LongArray (boolean ordered, long[] array, int startIndex, int count) {\r
- this(ordered, array.length);\r
+ this(ordered, count);\r
size = count;\r
System.arraycopy(array, startIndex, items, 0, count);\r
}\r
/** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
* been removed, or if it is known that more items will not be added. */\r
public void shrink () {\r
+ if (items.length == size) return;\r
resize(size);\r
}\r
\r
* @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a\r
* memory copy. */\r
public ShortArray (boolean ordered, short[] array, int startIndex, int count) {\r
- this(ordered, array.length);\r
+ this(ordered, count);\r
size = count;\r
System.arraycopy(array, startIndex, items, 0, count);\r
}\r
/** Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have\r
* been removed, or if it is known that more items will not be added. */\r
public void shrink () {\r
+ if (items.length == size) return;\r
resize(size);\r
}\r
\r