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)
Vector
public Iterable<Vector.Entry> entries()
Vector
public boolean equals(SparseVector v)
v
- public double get(int key)
Vector
public boolean isUsed(int key)
key
- the indexpublic double put(int key, double value)
Vector
public void resizeTo(int newSize)
newSize
- new sizepublic int used()
Vector
public void trim()
public double dot(Vector x)
Vector
public void scaleAndAddTo(double a, Vector y)
Vector
this
.scaleAndAddTo
in class Vector
public boolean equals(Vector v, double epsilon)
Vector
public Vector times(double scalar)
Vector
public Vector timesEquals(double scalar)
Vector
timesEquals
in class Vector
public int[] keys()
public double[] values()