public class SparseVector extends Vector
Vector.Entry| Modifier | Constructor and Description |
|---|---|
protected |
SparseVector(double[] values) |
protected |
SparseVector(int size) |
|
SparseVector(int size,
int capacity)
Construct with the given length and capacity
|
| Modifier and Type | Method and Description |
|---|---|
double |
add(int key,
double value)
Add the given value to the value at the given index
|
double |
dot(Vector x)
Returns the dot/scalar product.
|
Iterable<Vector.Entry> |
entries()
Iterates over all entries.
|
boolean |
equals(Object obj) |
boolean |
equals(SparseVector v)
Test for equality
|
boolean |
equals(Vector v,
double epsilon)
Test for equality
|
double |
get(int key)
Get the value at the given index
|
int |
hashCode() |
boolean |
isUsed(int key)
Test if an index has a set value
|
int[] |
keys() |
double |
put(int key,
double value)
Set the value at an index
|
void |
resizeTo(int newSize)
Resize the vector
|
void |
scaleAndAddTo(double a,
Vector y)
y = y + a*
this. |
int |
size() |
Vector |
times(double scalar)
Multiply by a constant, creating a new vector
|
Vector |
timesEquals(double scalar)
Multiply by a constant in-place
|
void |
trim()
Trim the underlying dense arrays to compact space and save memory
|
int |
used()
Returns number of non-zero-valued entries.
|
double[] |
values() |
protected SparseVector(double[] values)
protected SparseVector(int size)
public SparseVector(int size, int capacity)
size - the length of the vectorcapacity - the number of expected non-zero elementspublic double add(int key, double value)
Vectorpublic Iterable<Vector.Entry> entries()
Vectorpublic boolean equals(SparseVector v)
v - public double get(int key)
Vectorpublic boolean isUsed(int key)
key - the indexpublic double put(int key, double value)
Vectorpublic void resizeTo(int newSize)
newSize - new sizepublic int used()
Vectorpublic void trim()
public double dot(Vector x)
Vectorpublic void scaleAndAddTo(double a, Vector y)
Vectorthis.scaleAndAddTo in class Vectorpublic boolean equals(Vector v, double epsilon)
Vectorpublic Vector times(double scalar)
Vectorpublic Vector timesEquals(double scalar)
VectortimesEquals in class Vectorpublic int[] keys()
public double[] values()