A variable length {@link DoubleArray} implementation that automaticallyhandles expanding and contracting its internal storage array as elements are added and removed.
The internal storage array starts with capacity determined by the {@code initialCapacity} property, which can be set by the constructor.The default initial capacity is 16. Adding elements using {@link #addElement(double)} appends elements to the end of the array.When there are no open entries at the end of the internal storage array, the array is expanded. The size of the expanded array depends on the {@code expansionMode} and {@code expansionFactor} properties.The {@code expansionMode} determines whether the size of the array ismultiplied by the {@code expansionFactor}( {@link ExpansionMode#MULTIPLICATIVE}) or if the expansion is additive ( {@link ExpansionMode#ADDITIVE} -- {@code expansionFactor} storagelocations added). The default {@code expansionMode} is {@code MULTIPLICATIVE} and the default{@code expansionFactor} is 2.
The {@link #addElementRolling(double)} method adds a new element to the endof the internal storage array and adjusts the "usable window" of the internal array forward by one position (effectively making what was the second element the first, and so on). Repeated activations of this method (or activation of {@link #discardFrontElements(int)}) will effectively orphan the storage locations at the beginning of the internal storage array. To reclaim this storage, each time one of these methods is activated, the size of the internal storage array is compared to the number of addressable elements (the {@code numElements} property) and if the differenceis too large, the internal array is contracted to size {@code numElements + 1}. The determination of when the internal storage array is "too large" depends on the {@code expansionMode} and{@code contractionFactor} properties. If the {@code expansionMode}is {@code MULTIPLICATIVE}, contraction is triggered when the ratio between storage array length and {@code numElements} exceeds{@code contractionFactor.} If the {@code expansionMode}is {@code ADDITIVE}, the number of excess storage locations is compared to {@code contractionFactor}.
To avoid cycles of expansions and contractions, the {@code expansionFactor} must not exceed the {@code contractionFactor}. Constructors and mutators for both of these properties enforce this requirement, throwing a {@code MathIllegalArgumentException} if it isviolated.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|