public class SparseHashVector<T extends Number> extends AbstractVector<T> implements SparseVector<T>, Serializable
SparseVector
implementation backed by a HashMap
. 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.
Modifier and Type | Field and Description |
---|---|
protected double |
magnitude
The magnitude of the vector or -1 if the value is currently invalid needs
to be recomputed
|
protected SparseHashArray<Number> |
vector
The backing array that holds the vector values
|
Constructor and Description |
---|
SparseHashVector(int length)
Create a
SparseHashVector with the given size, having no
non-zero values. |
SparseHashVector(T[] array)
Create a
SparseHashVector from an array, saving only the non
zero entries. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Returns
true if the object is a Vector of the same length
and whose corresponding indices have equivalent values. |
int[] |
getNonZeroIndices()
Returns all the indices whose values are non-zero
|
Number |
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,
Number value)
Set the value in the vector (optional operation).
|
add, hashCode, toString
protected SparseHashArray<Number> vector
protected double magnitude
public SparseHashVector(int length)
SparseHashVector
with the given size, having no
non-zero values.length
- The length of this Vector
public SparseHashVector(T[] array)
SparseHashVector
from an array, saving only the non
zero entries.array
- the values of this vectorpublic boolean equals(Object o)
true
if the object is a Vector
of the same length
and whose corresponding indices have equivalent values.public int[] getNonZeroIndices()
getNonZeroIndices
in interface SparseVector<T extends Number>
public Number getValue(int index)
Number
.public int length()
Vector
.public double magnitude()
Copyright © 2012. All Rights Reserved.