Class DoubleArray
- java.lang.Object
-
- elki.utilities.datastructures.arraylike.DoubleArray
-
- All Implemented Interfaces:
ArrayAdapter<java.lang.Double,DoubleArray>,NumberArrayAdapter<java.lang.Double,DoubleArray>
public class DoubleArray extends java.lang.Object implements NumberArrayAdapter<java.lang.Double,DoubleArray>
Array of double values (primitive, avoiding the boxing overhead of ArrayList). This class is generated from a code template.
- Since:
- 0.7.0
- Author:
- Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description double[]data(Reused) store for numerical attributes.private static intLAST_GROW_SIZELast value where we can grow by 50%.private static intMAX_ARRAY_SIZEMaximum array size permitted by Java.intsizeNumber of numerical attributes.
-
Constructor Summary
Constructors Constructor Description DoubleArray()Constructor.DoubleArray(int initialsize)Constructor.DoubleArray(DoubleArray existing)Constructor from an existing array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(double attribute)Append a value.voidclear()Reset the numeric attribute counter.doubleget(int pos)Get the value at this position.java.lang.Doubleget(DoubleArray array, int off)Get the off'th item from the array.bytegetByte(DoubleArray array, int off)Get the off'th item from the array as byte.doublegetDouble(DoubleArray array, int off)Get the off'th item from the array as double.floatgetFloat(DoubleArray array, int off)Get the off'th item from the array as float.intgetInteger(DoubleArray array, int off)Get the off'th item from the array as integer.longgetLong(DoubleArray array, int off)Get the off'th item from the array as long.shortgetShort(DoubleArray array, int off)Get the off'th item from the array as short.private voidgrow()Grow the current array.voidinsert(int pos, double val)Insert a value at the given position.booleanisEmpty()Test if the array is empty.voidremove(int start, int len)Remove a range from the array.voidset(int pos, double value)Set the value at this position.intsize()Get the size of the array.intsize(DoubleArray array)Get the size of the array.voidsort()Sort the contents.voidswap(int p1, int p2)Swap two values.double[]toArray()Return a copy of the contents as array.
-
-
-
Field Detail
-
MAX_ARRAY_SIZE
private static final int MAX_ARRAY_SIZE
Maximum array size permitted by Java.This is JVM dependent, but 2^31 - 5 is the usual OpenJDK8 value.
- See Also:
- Constant Field Values
-
LAST_GROW_SIZE
private static final int LAST_GROW_SIZE
Last value where we can grow by 50%.- See Also:
- Constant Field Values
-
data
public double[] data
(Reused) store for numerical attributes.
-
size
public int size
Number of numerical attributes.
-
-
Constructor Detail
-
DoubleArray
public DoubleArray()
Constructor.
-
DoubleArray
public DoubleArray(int initialsize)
Constructor.- Parameters:
initialsize- Initial size.
-
DoubleArray
public DoubleArray(DoubleArray existing)
Constructor from an existing array.The new array will be allocated as small as possible, so modifications will cause a resize!
- Parameters:
existing- Existing array
-
-
Method Detail
-
clear
public void clear()
Reset the numeric attribute counter.
-
add
public void add(double attribute)
Append a value.- Parameters:
attribute- Attribute value.
-
grow
private void grow() throws java.lang.OutOfMemoryErrorGrow the current array.- Throws:
java.lang.OutOfMemoryError
-
get
public double get(int pos)
Get the value at this position.- Parameters:
pos- Position- Returns:
- Value
-
set
public void set(int pos, double value)Set the value at this position.- Parameters:
pos- Positionvalue- Value
-
swap
public void swap(int p1, int p2)Swap two values.- Parameters:
p1- First positionp2- Second position
-
remove
public void remove(int start, int len)Remove a range from the array.- Parameters:
start- Startlen- Length
-
insert
public void insert(int pos, double val)Insert a value at the given position.- Parameters:
pos- Insert positionval- Value to insert
-
size
public int size()
Get the size of the array.- Returns:
- Size
-
isEmpty
public boolean isEmpty()
Test if the array is empty.- Returns:
trueif empty.
-
sort
public void sort()
Sort the contents.
-
size
public int size(DoubleArray array)
Description copied from interface:ArrayAdapterGet the size of the array.- Specified by:
sizein interfaceArrayAdapter<java.lang.Double,DoubleArray>- Specified by:
sizein interfaceNumberArrayAdapter<java.lang.Double,DoubleArray>- Parameters:
array- Array-like thing- Returns:
- Size
-
get
public java.lang.Double get(DoubleArray array, int off) throws java.lang.IndexOutOfBoundsException
Description copied from interface:ArrayAdapterGet the off'th item from the array.- Specified by:
getin interfaceArrayAdapter<java.lang.Double,DoubleArray>- Specified by:
getin interfaceNumberArrayAdapter<java.lang.Double,DoubleArray>- Parameters:
array- Array to get fromoff- Offset- Returns:
- Item at offset off
- Throws:
java.lang.IndexOutOfBoundsException- for an invalid index.
-
getDouble
public double getDouble(DoubleArray array, int off) throws java.lang.IndexOutOfBoundsException
Description copied from interface:NumberArrayAdapterGet the off'th item from the array as double.- Specified by:
getDoublein interfaceNumberArrayAdapter<java.lang.Double,DoubleArray>- Parameters:
array- Array to get fromoff- Offset- Returns:
- Item at offset off
- Throws:
java.lang.IndexOutOfBoundsException- for an invalid index.
-
getFloat
public float getFloat(DoubleArray array, int off) throws java.lang.IndexOutOfBoundsException
Description copied from interface:NumberArrayAdapterGet the off'th item from the array as float.- Specified by:
getFloatin interfaceNumberArrayAdapter<java.lang.Double,DoubleArray>- Parameters:
array- Array to get fromoff- Offset- Returns:
- Item at offset off
- Throws:
java.lang.IndexOutOfBoundsException- for an invalid index.
-
getInteger
public int getInteger(DoubleArray array, int off) throws java.lang.IndexOutOfBoundsException
Description copied from interface:NumberArrayAdapterGet the off'th item from the array as integer.- Specified by:
getIntegerin interfaceNumberArrayAdapter<java.lang.Double,DoubleArray>- Parameters:
array- Array to get fromoff- Offset- Returns:
- Item at offset off
- Throws:
java.lang.IndexOutOfBoundsException- for an invalid index.
-
getShort
public short getShort(DoubleArray array, int off) throws java.lang.IndexOutOfBoundsException
Description copied from interface:NumberArrayAdapterGet the off'th item from the array as short.- Specified by:
getShortin interfaceNumberArrayAdapter<java.lang.Double,DoubleArray>- Parameters:
array- Array to get fromoff- Offset- Returns:
- Item at offset off
- Throws:
java.lang.IndexOutOfBoundsException- for an invalid index.
-
getLong
public long getLong(DoubleArray array, int off) throws java.lang.IndexOutOfBoundsException
Description copied from interface:NumberArrayAdapterGet the off'th item from the array as long.- Specified by:
getLongin interfaceNumberArrayAdapter<java.lang.Double,DoubleArray>- Parameters:
array- Array to get fromoff- Offset- Returns:
- Item at offset off
- Throws:
java.lang.IndexOutOfBoundsException- for an invalid index.
-
getByte
public byte getByte(DoubleArray array, int off) throws java.lang.IndexOutOfBoundsException
Description copied from interface:NumberArrayAdapterGet the off'th item from the array as byte.- Specified by:
getBytein interfaceNumberArrayAdapter<java.lang.Double,DoubleArray>- Parameters:
array- Array to get fromoff- Offset- Returns:
- Item at offset off
- Throws:
java.lang.IndexOutOfBoundsException- for an invalid index.
-
toArray
public double[] toArray()
Return a copy of the contents as array.- Returns:
- Copy of the contents.
-
-