Use max() instead of min() when enlarging the array.

Adding n elements subsequently has now an O(n) running time while it was
O(n^2) before.
This commit is contained in:
Sebastian Bauer 2016-08-18 20:09:48 +02:00
parent 9d2e9d7911
commit b03ba67a88

View File

@ -53,7 +53,7 @@ public class TArrayList<E> extends TAbstractList<E> implements TCloneable, TSeri
public void ensureCapacity(int minCapacity) {
if (array.length < minCapacity) {
array = TArrays.copyOf(array, array.length + TMath.min(5, array.length / 2));
array = TArrays.copyOf(array, array.length + TMath.max(5, array.length / 2));
}
}