jsat.utils
Class DoubleList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<java.lang.Double>
-
- jsat.utils.DoubleList
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Iterable<java.lang.Double>, java.util.Collection<java.lang.Double>, java.util.List<java.lang.Double>, java.util.RandomAccess
public class DoubleList extends java.util.AbstractList<java.lang.Double> implements java.io.Serializable, java.util.RandomAccessProvides a modifiable implementation of a List using a double array. This provides considerable memory efficency improvements over using anArrayListto store doubles.
Null is not allowed into the list.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DoubleList()Creates a new empty DoubleListDoubleList(java.util.Collection<java.lang.Double> c)Creates a new DoubleList containing the values of the given collectionDoubleList(int capacity)Creates a new empty DoubleList
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanadd(double e)Performs exactly the same asadd(java.lang.Double).booleanadd(java.lang.Double e)voidadd(int index, double element)Operates exactly asadd(int, java.lang.Double)voidadd(int index, java.lang.Double element)voidclear()java.lang.Doubleget(int index)double[]getBackingArray()Returns the reference to the array that backs this list.doublegetD(int index)Operates exactly asget(int)VecgetVecView()Obtains a view of this double list as a dense vector with equal length.doublepeek()This method treats the underlying list as a stack.doublepop()This method treats the underlying list as a stack.doublepush(double e)This method treats the underlying list as a stack.java.lang.Doubleremove(int index)doubleremoveD(int index)Operates exactly asremove(int)doubleset(int index, double element)Operates exactly asset(int, java.lang.Double)java.lang.Doubleset(int index, java.lang.Double element)intsize()static java.util.List<java.lang.Double>unmodifiableView(double[] array, int length)Creates an returns an unmodifiable view of the given double array that requires only a small object allocation.static DoubleListview(double[] array, int length)Creates and returns a view of the given double array that requires only a small object allocation.-
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
DoubleList
public DoubleList()
Creates a new empty DoubleList
-
DoubleList
public DoubleList(int capacity)
Creates a new empty DoubleList- Parameters:
capacity- the starting internal capacity of the list
-
DoubleList
public DoubleList(java.util.Collection<java.lang.Double> c)
Creates a new DoubleList containing the values of the given collection- Parameters:
c- the collection of values to fill this double list with
-
-
Method Detail
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<java.lang.Double>- Specified by:
clearin interfacejava.util.List<java.lang.Double>- Overrides:
clearin classjava.util.AbstractList<java.lang.Double>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<java.lang.Double>- Specified by:
sizein interfacejava.util.List<java.lang.Double>- Specified by:
sizein classjava.util.AbstractCollection<java.lang.Double>
-
add
public boolean add(double e)
Performs exactly the same asadd(java.lang.Double).- Parameters:
e- the value to add- Returns:
- true if it was added, false otherwise
-
push
public double push(double e)
This method treats the underlying list as a stack. Pushes an item onto the top of this "stack".- Parameters:
e- the item to push onto the stack- Returns:
- the value added to the stack
-
pop
public double pop()
This method treats the underlying list as a stack. Removes the item at the top of this "stack" and returns that item as the value.- Returns:
- the item at the top of this stack (the last item pushed onto it)
-
peek
public double peek()
This method treats the underlying list as a stack. Gets the item at the top of this "stack" and returns that item as the value, but leaves it on the stack.- Returns:
- the item at the top of this stack (the last item pushed onto it)
-
add
public boolean add(java.lang.Double e)
- Specified by:
addin interfacejava.util.Collection<java.lang.Double>- Specified by:
addin interfacejava.util.List<java.lang.Double>- Overrides:
addin classjava.util.AbstractList<java.lang.Double>
-
getD
public double getD(int index)
Operates exactly asget(int)- Parameters:
index- the index of the value to get- Returns:
- the value at the given index
-
get
public java.lang.Double get(int index)
- Specified by:
getin interfacejava.util.List<java.lang.Double>- Specified by:
getin classjava.util.AbstractList<java.lang.Double>
-
set
public double set(int index, double element)Operates exactly asset(int, java.lang.Double)- Parameters:
index- the index to setelement- the value to set- Returns:
- the previous value at said index
-
set
public java.lang.Double set(int index, java.lang.Double element)- Specified by:
setin interfacejava.util.List<java.lang.Double>- Overrides:
setin classjava.util.AbstractList<java.lang.Double>
-
add
public void add(int index, double element)Operates exactly asadd(int, java.lang.Double)- Parameters:
index- the index to add atelement- the value to add
-
add
public void add(int index, java.lang.Double element)- Specified by:
addin interfacejava.util.List<java.lang.Double>- Overrides:
addin classjava.util.AbstractList<java.lang.Double>
-
removeD
public double removeD(int index)
Operates exactly asremove(int)- Parameters:
index- the index to remove- Returns:
- the value removed
-
remove
public java.lang.Double remove(int index)
- Specified by:
removein interfacejava.util.List<java.lang.Double>- Overrides:
removein classjava.util.AbstractList<java.lang.Double>
-
getBackingArray
public double[] getBackingArray()
Returns the reference to the array that backs this list. Alterations to the array will be visible to the DoubelList and vise versa. The array returned may not the the same size as the value returned bysize()- Returns:
- the underlying array used by this DoubleList
-
getVecView
public Vec getVecView()
Obtains a view of this double list as a dense vector with equal length. This is a soft reference, and altering the values in the matrix with alter the double list, and vise versa.
While no error will be thrown if the size of the underlying list changes, this view should be discarded if the size of the list changes. Once the list has changed sizes, there is no guarantee on the behavior that will occur if the vector is used.- Returns:
- a vector view of this list
-
unmodifiableView
public static java.util.List<java.lang.Double> unmodifiableView(double[] array, int length)Creates an returns an unmodifiable view of the given double array that requires only a small object allocation.- Parameters:
array- the array to wrap into an unmodifiable listlength- the number of values of the array to use, starting from zero- Returns:
- an unmodifiable list view of the array
-
view
public static DoubleList view(double[] array, int length)
Creates and returns a view of the given double array that requires only a small object allocation. Changes to the list will be reflected in the array up to a point. If the modification would require increasing the capacity of the array, a new array will be allocated - at which point operations will no longer be reflected in the original array.- Parameters:
array- the array to wrap by a DoubleList objectlength- the initial length of the list- Returns:
- a DoubleList backed by the given array, unless modified to the point of requiring the allocation of a new array
-
-
DataMelt 3.0 © DataMelt by jWork.ORG