public class AmortizedSparseVector extends Object implements SparseDoubleVector, Serializable
SparseVector at the expense of increased memory usage, for certain usage
patterns. Only non-zero values in the vector are stored in an ArrayList, which tracks both the index of the value, and the value itself.
Lookups for all indices are O(log n). Writes to already existing indices are
O(log n). Writes to non-existing indices are dependent on the insertion time
of a ArrayList, but are at a minimum O(log n).| Constructor and Description |
|---|
AmortizedSparseVector()
An
AmortizedSparseVector with Integer.MAX_VALUE
dimensions. |
AmortizedSparseVector(int length)
Create
AmortizedSparseVector of size @{code length}, which
initially has all dimensions set to 0. |
| Modifier and Type | Method and Description |
|---|---|
double |
add(int index,
double delta)
Changes the value in this vector by a specified amount (optional
operation).
|
double |
get(int index)
Returns the value of this vector at the given index.
|
int[] |
getNonZeroIndices()
Returns all the indices whose values are non-zero
|
Double |
getValue(int index)
Return the value of the vector at the given index as a
Number. |
int |
length()
Return the size of the
Vector. |
double |
magnitude()
Returns the magnitude of this vector
|
void |
set(double[] value)
Note that any values which are 0 are left out of the vector.
|
void |
set(int index,
double value)
Sets the length in this vector (optional operation).
|
void |
set(int index,
Number value)
Set the value in the vector (optional operation).
|
double[] |
toArray()
Returns a double array representing this vector.
|
public AmortizedSparseVector()
AmortizedSparseVector with Integer.MAX_VALUE
dimensions.public AmortizedSparseVector(int length)
AmortizedSparseVector of size @{code length}, which
initially has all dimensions set to 0.length - The maximum length of the Vector.public double add(int index,
double delta)
add in interface DoubleVectorindex - index to change.delta - the amount to change by.public double get(int index)
get in interface DoubleVectorindex - index to retrieve.public Double getValue(int index)
Number.getValue in interface DoubleVectorgetValue in interface Vector<Double>index - index to retrieve.public double magnitude()
public void set(int index,
double value)
set in interface DoubleVectorindex - index to set.value - value to set in the vector.public void set(int index,
Number value)
public void set(double[] value)
public double[] toArray()
toArray in interface DoubleVectordouble array of this vector.public int[] getNonZeroIndices()
getNonZeroIndices in interface SparseVector<Double>Copyright © 2012. All Rights Reserved.