public class SparseHashDoubleVector extends Object implements SparseDoubleVector, Serializable
SparseVector
implementation backed by a Map
. This
provides amoritized constant time access to all get and set operations, while
using more space than the CompactSparseVector
or AmortizedSparseVector
classes.
See SparseHashArray
for implementation details.
Constructor and Description |
---|
SparseHashDoubleVector(double[] values)
Creates a new vector using the non-zero values of the specified array.
|
SparseHashDoubleVector(DoubleVector values) |
SparseHashDoubleVector(int length)
Creates a new vector of the specified length
|
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(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 SparseHashDoubleVector(int length)
length
- the length of this vectorpublic SparseHashDoubleVector(double[] values)
values
- the intial values for this vector to havepublic SparseHashDoubleVector(DoubleVector values)
public double add(int index, double delta)
add
in interface DoubleVector
index
- index to change.delta
- the amount to change by.public double get(int index)
get
in interface DoubleVector
index
- index to retrieve.public Double getValue(int index)
Number
.getValue
in interface DoubleVector
getValue
in interface Vector<Double>
index
- index to retrieve.public void set(int index, Number value)
public void set(int index, double value)
set
in interface DoubleVector
index
- index to set.value
- value to set in the vector.public double[] toArray()
toArray
in interface DoubleVector
double
array of this vector.public int length()
Vector
.public double magnitude()
public int[] getNonZeroIndices()
getNonZeroIndices
in interface SparseVector<Double>
Copyright © 2012. All Rights Reserved.