public class TernaryVector extends Object implements SparseVector<Integer>, IntegerVector, Serializable
UnsupportedOperationException if
called.| Modifier and Type | Field and Description |
|---|---|
protected int[] |
negativeDimensions
The indices which are all set to -1.
|
protected int[] |
positiveDimensions
The indices which are all set to +1.
|
| Constructor and Description |
|---|
TernaryVector(int length,
int[] positiveIndices,
int[] negativeIndices)
Create an
TernaryVector with the specified length, and postive
and negative dimensions. |
| Modifier and Type | Method and Description |
|---|---|
int |
add(int index,
int delta)
Throws
UnsupportedOperationException if called. |
int |
get(int index)
Returns the value of this vector at the given index.
|
int[] |
getNonZeroIndices()
Returns all the indices whose values are non-zero
|
Integer |
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
|
int[] |
negativeDimensions()
Returns the indices at which this vector is valued
-1 in sorted
order. |
int[] |
positiveDimensions()
Returns the indices at which this vector is valued
+1 in sorted
order. |
void |
set(int index,
int value)
Throws
UnsupportedOperationException if called. |
void |
set(int index,
Number value)
Throws
UnsupportedOperationException if called. |
int[] |
toArray()
Returns an
int array representing this vector. |
protected int[] positiveDimensions
protected int[] negativeDimensions
public TernaryVector(int length,
int[] positiveIndices,
int[] negativeIndices)
TernaryVector with the specified length, and postive
and negative dimensions. Note that the provided arrays are not
safe. This vector retains references to the arrays and so any
modification to their contents will result in a change to this vector.length - the number of elements in this vector.positiveIndices - all indices whose values are +1.negativeIndices - all indices whose values are -1.public int add(int index,
int delta)
UnsupportedOperationException if called.add in interface IntegerVectorindex - index to change.delta - the amount to change by.public int get(int index)
get in interface IntegerVectorindex - index to retrieve.public int[] getNonZeroIndices()
getNonZeroIndices in interface SparseVector<Integer>public Integer getValue(int index)
Number..getValue in interface IntegerVectorgetValue in interface Vector<Integer>index - index to retrieve.public int length()
Vector..public int[] negativeDimensions()
-1 in sorted
order. Note that the return array is not safe. Any modification
to its contents will result in a change to this vector.public int[] positiveDimensions()
+1 in sorted
order. Note that the return array is not safe. Any modification
to its contents will result in a change to this vector.public double magnitude()
public void set(int index,
int value)
UnsupportedOperationException if called.set in interface IntegerVectorindex - index to set.value - value to set in the vector.public void set(int index,
Number value)
UnsupportedOperationException if called.public int[] toArray()
int array representing this vector. The returned
array will be "safe" in that no changes to the array will be reflected in
the vector, and likewise for changes to to the vector. The caller is
thus free to modify the returned array..toArray in interface IntegerVectorint array of this vector.Copyright © 2012. All Rights Reserved.