Package cnuphys.splot.pdata
Class GrowableArray
java.lang.Object
cnuphys.splot.pdata.GrowableArray
- Direct Known Subclasses:
DataColumn
This class supports named arrays that grow. They are an alternative to
Vectors or ArrayLists. The advantages are speed and usage for those cases
where arrays are more convenient. Clients only have access to minimal copies
which can be used as "just the right size" arrays.
- Author:
- heddle
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a GrowableArray with initial capacity 100 and increment 100.GrowableArray
(int initCap, int increment) Create a GrowableArray -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double val) Add a value to the array, growing it if necessary.void
clear()
Reset the data array to the initial capacity and fill with all NaNs.double
get
(int index) Get the value at the given indexdouble
Get the maximum data valuedouble[]
Get the minimal copy of the data array.double
Get the minimum data valuevoid
removes the first entry and moves all other entries up onevoid
set
(int index, double val) Set the value at the given indexint
size()
Get the number of real data in the array, which in general is less than the length of the array.
-
Field Details
-
_data
protected double[] _data -
_dataLen
protected int _dataLen -
_increment
protected int _increment -
_initCap
protected int _initCap -
_minValue
protected double _minValue -
_maxValue
protected double _maxValue
-
-
Constructor Details
-
GrowableArray
public GrowableArray()Creates a GrowableArray with initial capacity 100 and increment 100. -
GrowableArray
public GrowableArray(int initCap, int increment) Create a GrowableArray- Parameters:
initCap
- the initial capacityincrement
- the increment when the array grows.
-
-
Method Details
-
size
public int size()Get the number of real data in the array, which in general is less than the length of the array. This is the effective length of the array, so loops should go from 0 to this value minus 1.- Returns:
- the number of real data.
-
getMinimalCopy
public double[] getMinimalCopy()Get the minimal copy of the data array. This copies the actual data into a new array of just the right size. This new array can be used normally, i.e., it is safe to use itslength
.- Returns:
- a copy of the data array of just the right length
-
removeFirst
public void removeFirst()removes the first entry and moves all other entries up one -
add
public void add(double val) Add a value to the array, growing it if necessary.- Parameters:
val
- the value to add
-
getMinValue
public double getMinValue()Get the minimum data value- Returns:
- the minimum data value
-
getMaxValue
public double getMaxValue()Get the maximum data value- Returns:
- the maximum data value
-
clear
public void clear()Reset the data array to the initial capacity and fill with all NaNs. -
get
public double get(int index) Get the value at the given index- Parameters:
index
- the index- Returns:
- the value at the index
-
set
public void set(int index, double val) Set the value at the given index- Parameters:
index
- the indexval
- the value at the index
-