A variable length DoubleArray implementation that automatically
handles expanding and contracting its internal storage array as elements
are added and removed.
synchronized.
This qualifier will be dropped in the next major release (4.0).
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
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
expansionMode and expansionFactor properties.
The expansionMode determines whether the size of the array is
multiplied by the expansionFactor
(ExpansionMode#MULTIPLICATIVE) or if the expansion is additive
(ExpansionMode#ADDITIVE -- expansionFactor storage
locations added).
The default expansionMode is MULTIPLICATIVE and the default
expansionFactor is 2.
The addElementRolling(double) method adds a new element to the end
of 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 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, contraction is triggered when the
ratio between storage array length and numElements exceeds
contractionFactor. If the expansionMode
is ADDITIVE, 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 a MathIllegalArgumentException if it is
violated.
| Modifier and Type | Class and Description |
|---|---|
| public static enum | ResizableDoubleArray.
Specification of expansion algorithm. |
| Modifier and Type | Field and Description |
|---|---|
| public static final int | ADDITIVE_MODE
Deprecated
As of 3.1. Please use Additive expansion mode.
ExpansionMode#ADDITIVE instead.
|
| private double | contractionCriterion
The contraction criteria determines when the internal array will be contracted to fit the number of elements contained in the element array + 1. |
| private static final double | DEFAULT_CONTRACTION_DELTA
Default value for the difference between |
| private static final double | DEFAULT_EXPANSION_FACTOR
Default value for array size modifier. |
| private static final int | DEFAULT_INITIAL_CAPACITY
Default value for initial capacity. |
| private double | expansionFactor
The expansion factor of the array. |
| private ResizableDoubleArray. | expansionMode
Determines whether array expansion by |
| private double[] | internalArray
The internal storage array. |
| public static final int | MULTIPLICATIVE_MODE
Deprecated
As of 3.1. Please use Multiplicative expansion mode.
ExpansionMode#MULTIPLICATIVE instead.
|
| private int | numElements
The number of addressable elements in the array. |
| private static final long | serialVersionUID
Serializable version identifier. |
| private int | startIndex
The position of the first addressable element in the internal storage array. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ResizableDoubleArray(int
Initial size of the internal storage array. initialCapacity)Creates an instance with the specified initial capacity. |
| public | ResizableDoubleArray(double[]
initial array initialArray)Creates an instance from an existing |
| public | ResizableDoubleArray(int
Initial size of the internal storage array. initialCapacity, float The array will be expanded based on this
parameter. expansionFactor)
Deprecated
As of 3.1. Please use
ResizableDoubleArray(int, double) instead.
Creates an instance with the specified initial capacity and expansion factor. |
| public | ResizableDoubleArray(int
Initial size of the internal storage array. initialCapacity, double The array will be expanded based on this
parameter. expansionFactor)Creates an instance with the specified initial capacity and expansion factor. |
| public | ResizableDoubleArray(int
Initial size of the internal storage array.. initialCapacity, float The array will be expanded based on this
parameter. expansionFactor, float Contraction criteria. contractionCriteria)
Deprecated
As of 3.1. Please use
ResizableDoubleArray(int, double, double) instead.
Creates an instance with the specified initialCapacity, expansionFactor, and contractionCriterion. |
| public | ResizableDoubleArray(int
Initial size of the internal storage array.. initialCapacity, double The array will be expanded based on this
parameter. expansionFactor, double Contraction criterion. contractionCriterion)Creates an instance with the specified initial capacity, expansion factor, and contraction criteria. |
| public | ResizableDoubleArray(int
the initial size of the internal storage array initialCapacity, float the array will be expanded based on this
parameter expansionFactor, float the contraction Criteria contractionCriteria, int the expansion mode expansionMode)
Deprecated
As of 3.1.
Create a ResizableArray with the specified properties. |
| public | ResizableDoubleArray(int
Initial size of the internal storage array. initialCapacity, double The array will be expanded based on this
parameter. expansionFactor, double Contraction criteria. contractionCriterion, ResizableDoubleArray.Expansion mode. expansionMode,Initial contents of the array. data)Creates an instance with the specified properties. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | addElement(double
Value to be added to end of array. value)Implements org. Adds an element to the end of this expandable array. |
| public synchronized double | Returns: the value which has been discarded or "pushed" out of the array by this rolling insert.Value to be added to the array. value)Implements org. Adds an element to the end of the array and removes the first element in the array. |
| public synchronized void | addElements(double[]
Values to be added to end of array. values)Implements org. Adds several element to the end of this expandable array. |
| protected void | checkContractExpand(float
criteria to be checked contraction, float factor to be checked expansion)
Deprecated
As of 3.1. Please use
checkContractExpand(double, double) instead.
Checks the expansion factor and the contraction criterion and throws an IllegalArgumentException if the contractionCriteria is less than the expansionCriteria |
| protected void | checkContractExpand(double
Criterion to be checked. contraction, double Factor to be checked. expansion)Checks the expansion factor and the contraction criterion and raises an exception if the contraction criterion is smaller than the expansion criterion. |
| public synchronized void | clear()
Implements org. Clear the array contents, resetting the number of elements to zero. |
| public double | Returns: the result.Function to be applied on this array. fPerforms an operation on the addressable elements of the array. |
| public synchronized void | contract()
Contracts the storage array to the (size of the element set) + 1 - to avoid a zero length array. |
| public static void | copy(ResizableDoubleArray
ResizableDoubleArray to copy source, ResizableDoubleArray ResizableArray to replace with a copy of the source array dest)Copies source to dest, copying the underlying data, so dest is a new, independent copy of source. |
| public synchronized ResizableDoubleArray | Returns: a new ResizableDoubleArray with the same data and configuration properties as thisReturns a copy of the ResizableDoubleArray. |
| private synchronized void | discardExtremeElements(int
the number of elements to discard from the front/end of the array i, boolean true if elements are to be discarded from the front
of the array, false if elements are to be discarded from the end
of the array front)Discards the |
| public synchronized void | discardFrontElements(int
the number of elements to discard from the front of the array i)Discards the |
| public synchronized void | discardMostRecentElements(int
the number of elements to discard from the end of the array i)Discards the |
| public boolean | Returns: true iff object is a ResizableDoubleArray with the same data and properties as thisobject to be compared for equality with this object)Overrides java. Returns true iff object is a ResizableDoubleArray with the same properties as this and an identical internal storage array. |
| protected synchronized void | |
| private synchronized void | expandTo(int
Size of the new internal storage array. size)Expands the internal storage array to the specified size. |
| protected double[] | Returns: the internal storage array used by this object.Provides direct access to the internal storage array. |
| public int | Returns: the length of the internal array.Gets the currently allocated size of the internal data structure used for storing elements. |
| public float | Returns: the contraction criteria used to reclaim memory.
Deprecated
As of 3.1. Please use
getContractionCriterion()
instead.
The contraction criteria defines when the internal array will contract to store only the number of elements in the element array. |
| public double | Returns: the contraction criterion used to reclaim memory.The contraction criterion defines when the internal array will contract to store only the number of elements in the element array. |
| public synchronized double | Returns: value stored at the specified indexindex to fetch a value from index)Implements org. Returns the element at the specified index |
| public synchronized double[] | Returns: the double array.Implements org. Returns a double array containing the elements of this
|
| public float | Returns: the expansion factor of this expandable double array
Deprecated
As of 3.1. Return type will be changed to "double" in 4.0.
The expansion factor controls the size of a new array when an array needs to be expanded. |
| public int | Returns: the expansion mode.
Deprecated
As of 3.1. Return value to be changed to
ExpansionMode in 4.0.
The expansion mode determines whether the internal storage array grows additively or multiplicatively when it is expanded. |
| pack-priv synchronized int | Returns: the length of the internal storage array.
Deprecated
As of 3.1. Please use
getCapacity() instead.
Notice the package scope on this method. |
| public synchronized double[] | Returns: the internal storage array used by this object
Deprecated
As of 3.1.
Returns the internal storage array. |
| public synchronized int | Returns: the number of elements.Implements org. Returns the number of elements currently in the array. |
| protected int | |
| public synchronized int | Returns: the hash code representing thisResizableDoubleArray.Overrides java. Returns a hash code consistent with equals. |
| public void | setContractionCriteria(float
contraction criteria contractionCriteria)
Deprecated
As of 3.1 (to be removed in 4.0 as field will become "final").
Sets the contraction criteria. |
| public synchronized void | setElement(int
index to store a value in index, double value to store at the specified index value)Implements org. Sets the element at the specified index. |
| public void | setExpansionFactor(float
the new expansion factor value. expansionFactor)
Deprecated
As of 3.1 (to be removed in 4.0 as field will become "final").
Sets the expansionFactor. |
| public void | setExpansionMode(int
The expansionMode to set. expansionMode)
Deprecated
As of 3.1.
Sets the |
| public void | setExpansionMode(ResizableDoubleArray.
Expansion mode to use for resizing the array. expansionMode
Deprecated
As of 3.1 (to be removed in 4.0 as field will become "final").
Sets the |
| protected void | setInitialCapacity(int
of the array initialCapacity)
Deprecated
As of 3.1, this is a no-op.
Sets the initial capacity. |
| public synchronized void | setNumElements(int
a new number of elements i)This function allows you to control the number of elements contained in this array, and can be used to "throw out" the last n values in an array. |
| private synchronized boolean | Returns: true if array satisfies the contraction criteriaReturns true if the internal storage array has too many unused storage positions. |
| public synchronized int | Returns: the starting index.
Deprecated
As of 3.1.
Returns the starting index of the internal array. |
| public synchronized double | Returns: the value that has been replaced in the array.New value to substitute for the most recently added value value)Substitutes |
| ADDITIVE_MODE | back to summary |
|---|---|
| public static final int ADDITIVE_MODE
Deprecated As of 3.1. Please use Additive expansion mode. | |
| contractionCriterion | back to summary |
|---|---|
| private double contractionCriterion The contraction criteria determines when the internal array will be contracted to fit the number of elements contained in the element array + 1. | |
| DEFAULT_CONTRACTION_DELTA | back to summary |
|---|---|
| private static final double DEFAULT_CONTRACTION_DELTA Default value for the difference between | |
| DEFAULT_EXPANSION_FACTOR | back to summary |
|---|---|
| private static final double DEFAULT_EXPANSION_FACTOR Default value for array size modifier. | |
| DEFAULT_INITIAL_CAPACITY | back to summary |
|---|---|
| private static final int DEFAULT_INITIAL_CAPACITY Default value for initial capacity. | |
| expansionFactor | back to summary |
|---|---|
| private double expansionFactor The expansion factor of the array. When the array needs to be expanded,
the new array size will be
| |
| expansionMode | back to summary |
|---|---|
| private ResizableDoubleArray. Determines whether array expansion by | |
| internalArray | back to summary |
|---|---|
| private double[] internalArray The internal storage array. | |
| MULTIPLICATIVE_MODE | back to summary |
|---|---|
| public static final int MULTIPLICATIVE_MODE
Deprecated As of 3.1. Please use Multiplicative expansion mode. | |
| numElements | back to summary |
|---|---|
| private int numElements The number of addressable elements in the array. Note that this has nothing to do with the length of the internal storage array. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serializable version identifier. | |
| startIndex | back to summary |
|---|---|
| private int startIndex The position of the first addressable element in the internal storage
array. The addressable elements in the array are
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray() Creates an instance with default properties.
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray(int initialCapacity) throws MathIllegalArgumentException Creates an instance with the specified initial capacity. Other properties take default values:
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray(double[] initialArray) Creates an instance from an existing
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray(int initialCapacity, float expansionFactor) throws MathIllegalArgumentException
Deprecated As of 3.1. Please use
Creates an instance with the specified initial capacity and expansion factor. The remaining properties take default values:
Throws IllegalArgumentException if the following conditions are not met:
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray(int initialCapacity, double expansionFactor) throws MathIllegalArgumentException Creates an instance with the specified initial capacity and expansion factor. The remaining properties take default values:
Throws IllegalArgumentException if the following conditions are not met:
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray(int initialCapacity, float expansionFactor, float contractionCriteria) throws MathIllegalArgumentException
Deprecated As of 3.1. Please use
Creates an instance with the specified initialCapacity,
expansionFactor, and contractionCriterion.
The expansion mode will default to
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray(int initialCapacity, double expansionFactor, double contractionCriterion) throws MathIllegalArgumentException Creates an instance with the specified initial capacity,
expansion factor, and contraction criteria.
The expansion mode will default to
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray(int initialCapacity, float expansionFactor, float contractionCriteria, int expansionMode) throws MathIllegalArgumentException
Deprecated As of 3.1. Please use
Create a ResizableArray with the specified properties. Throws IllegalArgumentException if the following conditions are not met:
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray(int initialCapacity, double expansionFactor, double contractionCriterion, ResizableDoubleArray. Creates an instance with the specified properties.
| |
| ResizableDoubleArray | back to summary |
|---|---|
| public ResizableDoubleArray(ResizableDoubleArray original) throws NullArgumentException Copy constructor. Creates a new ResizableDoubleArray that is a deep,
fresh copy of the original. Needs to acquire synchronization lock
on original. Original may not be null; otherwise a
| |
| addElement | back to summary |
|---|---|
| public synchronized void addElement(double value) Implements org. Adds an element to the end of this expandable array.
| |
| addElementRolling | back to summary |
|---|---|
| public synchronized double addElementRolling(double value) Implements org. Adds an element to the end of the array and removes the first element in the array. Returns the discarded first element. The effect is similar to a push operation in a FIFO queue. Example: If the array contains the elements 1, 2, 3, 4 (in that order) and addElementRolling(5) is invoked, the result is an array containing the entries 2, 3, 4, 5 and the value returned is 1.
| |
| addElements | back to summary |
|---|---|
| public synchronized void addElements(double[] values) Implements org. Adds several element to the end of this expandable array.
| |
| checkContractExpand | back to summary |
|---|---|
| protected void checkContractExpand(float contraction, float expansion) throws MathIllegalArgumentException
Deprecated As of 3.1. Please use
Checks the expansion factor and the contraction criterion and throws an IllegalArgumentException if the contractionCriteria is less than the expansionCriteria
| |
| checkContractExpand | back to summary |
|---|---|
| protected void checkContractExpand(double contraction, double expansion) throws NumberIsTooSmallException Checks the expansion factor and the contraction criterion and raises an exception if the contraction criterion is smaller than the expansion criterion.
| |
| clear | back to summary |
|---|---|
| public synchronized void clear() Implements org. Clear the array contents, resetting the number of elements to zero. | |
| compute | back to summary |
|---|---|
| public double compute(MathArrays. Performs an operation on the addressable elements of the array.
| |
| contract | back to summary |
|---|---|
| public synchronized void contract() Contracts the storage array to the (size of the element set) + 1 - to avoid a zero length array. This function also resets the startIndex to zero. | |
| copy | back to summary |
|---|---|
| public static void copy(ResizableDoubleArray source, ResizableDoubleArray dest) throws NullArgumentException Copies source to dest, copying the underlying data, so dest is a new, independent copy of source. Does not contract before the copy. Obtains synchronization locks on both source and dest (in that order) before performing the copy. Neither source nor dest may be null; otherwise a
| |
| copy | back to summary |
|---|---|
| public synchronized ResizableDoubleArray copy() Returns a copy of the ResizableDoubleArray. Does not contract before the copy, so the returned object is an exact copy of this.
| |
| discardExtremeElements | back to summary |
|---|---|
| private synchronized void discardExtremeElements(int i, boolean front) throws MathIllegalArgumentException Discards the
| |
| discardFrontElements | back to summary |
|---|---|
| public synchronized void discardFrontElements(int i) throws MathIllegalArgumentException Discards the
| |
| discardMostRecentElements | back to summary |
|---|---|
| public synchronized void discardMostRecentElements(int i) throws MathIllegalArgumentException Discards the
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object object) Overrides java. Returns true iff object is a ResizableDoubleArray with the same properties as this and an identical internal storage array. | |
| expand | back to summary |
|---|---|
| protected synchronized void expand() Expands the internal storage array using the expansion factor.
if | |
| expandTo | back to summary |
|---|---|
| private synchronized void expandTo(int size) Expands the internal storage array to the specified size.
| |
| getArrayRef | back to summary |
|---|---|
| protected double[] getArrayRef() Provides direct access to the internal storage array.
Please note that this method returns a reference to this object's
storage array, not a copy.
| |
| getCapacity | back to summary |
|---|---|
| public int getCapacity() Gets the currently allocated size of the internal data structure used
for storing elements.
This is not to be confused with
| |
| getContractionCriteria | back to summary |
|---|---|
| public float getContractionCriteria()
Deprecated As of 3.1. Please use The contraction criteria defines when the internal array will contract
to store only the number of elements in the element array.
If the
| |
| getContractionCriterion | back to summary |
|---|---|
| public double getContractionCriterion() The contraction criterion defines when the internal array will contract
to store only the number of elements in the element array.
If the
| |
| getElement | back to summary |
|---|---|
| public synchronized double getElement(int index) Implements org. Returns the element at the specified index
| |
| getElements | back to summary |
|---|---|
| public synchronized double[] getElements() Implements org. Returns a double array containing the elements of this
| |
| getExpansionFactor | back to summary |
|---|---|
| public float getExpansionFactor()
Deprecated As of 3.1. Return type will be changed to "double" in 4.0. The expansion factor controls the size of a new array when an array
needs to be expanded. The
| |
| getExpansionMode | back to summary |
|---|---|
| public int getExpansionMode()
Deprecated As of 3.1. Return value to be changed to
The expansion mode determines whether the internal storage array grows additively or multiplicatively when it is expanded.
| |
| getInternalLength | back to summary |
|---|---|
| pack-priv synchronized int getInternalLength()
Deprecated As of 3.1. Please use Notice the package scope on this method. This method is simply here for the JUnit test, it allows us check if the expansion is working properly after a number of expansions. This is not meant to be a part of the public interface of this class.
| |
| getInternalValues | back to summary |
|---|---|
| public synchronized double[] getInternalValues()
Deprecated As of 3.1. Returns the internal storage array. Note that this method returns
a reference to the internal storage array, not a copy, and to correctly
address elements of the array, the
| |
| getNumElements | back to summary |
|---|---|
| public synchronized int getNumElements() Implements org. Returns the number of elements currently in the array. Please note that this is different from the length of the internal storage array.
| |
| getStartIndex | back to summary |
|---|---|
| protected int getStartIndex() Returns the "start index" of the internal array.
This index is the position of the first addressable element in the
internal storage array.
The addressable elements in the array are at indices contained in
the interval [
| |
| hashCode | back to summary |
|---|---|
| public synchronized int hashCode() Overrides java. Returns a hash code consistent with equals.
| |
| setContractionCriteria | back to summary |
|---|---|
| public void setContractionCriteria(float contractionCriteria) throws MathIllegalArgumentException
Deprecated As of 3.1 (to be removed in 4.0 as field will become "final"). Sets the contraction criteria.
| |
| setElement | back to summary |
|---|---|
| public synchronized void setElement(int index, double value) Implements org. Sets the element at the specified index. If the specified index is greater than
| |
| setExpansionFactor | back to summary |
|---|---|
| public void setExpansionFactor(float expansionFactor) throws MathIllegalArgumentException
Deprecated As of 3.1 (to be removed in 4.0 as field will become "final"). Sets the expansionFactor. Throws IllegalArgumentException if the the following conditions are not met:
| |
| setExpansionMode | back to summary |
|---|---|
| public void setExpansionMode(int expansionMode) throws MathIllegalArgumentException
Deprecated As of 3.1. Please use Sets the
| |
| setExpansionMode | back to summary |
|---|---|
| public void setExpansionMode(ResizableDoubleArray. Deprecated As of 3.1 (to be removed in 4.0 as field will become "final"). Sets the
| |
| setInitialCapacity | back to summary |
|---|---|
| protected void setInitialCapacity(int initialCapacity) throws MathIllegalArgumentException
Deprecated As of 3.1, this is a no-op. Sets the initial capacity. Should only be invoked by constructors.
| |
| setNumElements | back to summary |
|---|---|
| public synchronized void setNumElements(int i) throws MathIllegalArgumentException This function allows you to control the number of elements contained in this array, and can be used to "throw out" the last n values in an array. This function will also expand the internal array as needed.
| |
| shouldContract | back to summary |
|---|---|
| private synchronized boolean shouldContract() Returns true if the internal storage array has too many unused storage positions.
| |
| start | back to summary |
|---|---|
| public synchronized int start()
Deprecated As of 3.1. Returns the starting index of the internal array. The starting index is
the position of the first addressable element in the internal storage
array. The addressable elements in the array are
| |
| substituteMostRecentElement | back to summary |
|---|---|
| public synchronized double substituteMostRecentElement(double value) throws MathIllegalStateException Substitutes
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final ResizableDoubleArray. | ADDITIVE
Additive expansion mode. |
| public static final ResizableDoubleArray. | MULTIPLICATIVE
Multiplicative expansion mode. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ResizableDoubleArray. | |
| public static ResizableDoubleArray. |
| ADDITIVE | back to summary |
|---|---|
| public static final ResizableDoubleArray. Additive expansion mode. | |
| MULTIPLICATIVE | back to summary |
|---|---|
| public static final ResizableDoubleArray. Multiplicative expansion mode. | |
| ExpansionMode | back to summary |
|---|---|
| private ExpansionMode() | |
| valueOf | back to summary |
|---|---|
| public static ResizableDoubleArray. | |
| values | back to summary |
|---|---|
| public static ResizableDoubleArray. | |