public class SparseHashIntegerVector extends AbstractIntegerVector implements SparseIntegerVector, Iterable<IntegerEntry>, 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.
| Constructor and Description |
|---|
SparseHashIntegerVector(int length)
Creates a new vector of the specified length
|
SparseHashIntegerVector(int[] values)
Creates a new vector using the non-zero values of the specified array.
|
| Modifier and Type | Method and Description |
|---|---|
int |
add(int index,
int delta)
Throws an
UnsupportedOperationException if called (vector is
unmodifiable). |
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
|
Iterator<IntegerEntry> |
iterator()
Returns an iterator over the non-
0 values in this vector. |
int |
length()
Return the size of the
Vector. |
void |
set(int index,
int value)
Throws an
UnsupportedOperationException if called (vector is
unmodifiable). |
equals, getValue, hashCode, magnitude, set, toArray, toStringaddclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetValue, toArraypublic SparseHashIntegerVector(int length)
length - the length of this vectorpublic SparseHashIntegerVector(int[] values)
values - the intial values for this vector to havepublic int add(int index,
int delta)
UnsupportedOperationException if called (vector is
unmodifiable).add in interface IntegerVectoradd in class AbstractIntegerVectorindex - 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 Iterator<IntegerEntry> iterator()
0 values in this vector. This
method makes no guarantee about the order in which the indices are
returned.iterator in interface Iterable<IntegerEntry>public int length()
Vector.public void set(int index,
int value)
UnsupportedOperationException if called (vector is
unmodifiable).set in interface IntegerVectorset in class AbstractIntegerVectorindex - index to set.value - value to set in the vector.Copyright © 2012. All Rights Reserved.