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 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. Whenthere 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 expansionMode
and expansionFactor
properties. The expansionMode
determines whether the size of the array is multiplied by the expansionFactor
(MULTIPLICATIVE_MODE) or if the expansion is additive (ADDITIVE_MODE -- expansionFactor
storage locations added). The default expansionMode
is MULTIPLICATIVE_MODE and the default expansionFactor
is 2.0.
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 numElements
property) and if the difference is too large, the internal array is contracted to size numElements + 1.
The determination of when the internal storage array is "too large" depends on the expansionMode
and contractionFactor
properties. If the expansionMode
is MULTIPLICATIVE_MODE
, contraction is triggered when the ratio between storage array length and numElements
exceeds contractionFactor.
If the expansionMode
is ADDITIVE_MODE,
the number of excess storage locations is compared to contractionFactor.
To avoid cycles of expansions and contractions, the expansionFactor
must not exceed the contractionFactor.
Constructors and mutators for both of these properties enforce this requirement, throwing IllegalArgumentException if it is violated.
|
|
|
|
|
|