|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.aitools.aq.algebra.vector.VectorSort
public final class VectorSort
An optimized implementation of a priority queue of build in doubles.
Instead of putting the doubles in the queue, it handles the indices
of a vector.
So instead of a remove(double value) a
remove(int valueIndex) is implemented.
The queue always sorts descending and there is no method to add new
values to the queue (beside the constructor).
Creating the queue has a complexity of O(n log n). Removing
(including polling) or changing a value has a complexity of
O(log n). Note that a direct change in the vector
(not using queue.change(int valueIndex, double newValue)) will
most likely lead to a malfunctioned queue. Do not do this unlike you
know what you are doing.
Field Summary | |
---|---|
static int |
NO_NODE
|
Constructor Summary | |
---|---|
VectorSort(double[] nodeValues)
Create a new VectorSort with a new Vector created
using given values. |
|
VectorSort(Vector nodeValues,
boolean copyVector)
Create a new VectorSort . |
|
VectorSort(Vector nodeValues,
boolean copyVector,
int numNodes)
Create a new VectorSort . |
Method Summary | |
---|---|
void |
changeValue(int valueIndex,
double value)
Change a value. |
boolean |
isYetUnremoved(int valueIndex)
|
int |
peek()
|
int |
poll()
Returns the index of the biggest value left and removes it from the queue. This works exactly like calling int index = queue.peek() and queue.remove(index). |
void |
remove(int valueIndex)
Remove a node from the sorting. |
static int[] |
sortedIndices(Vector input)
Return the indices of the input vector, sorted in descending order. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int NO_NODE
Constructor Detail |
---|
public VectorSort(double[] nodeValues)
VectorSort
with a new Vector
created
using given values. Trailing zeros will be sorted as well. Note that
this class uses some kind of index pointers to do the sorting. This
means only an intern array of the value indexes will be sorted and
nodeValues will be left untouched (if the method
change is not invoked).
nodeValues
- The values to sortpublic VectorSort(Vector nodeValues, boolean copyVector)
VectorSort
. The coordinates of the vector will
be sorted (up to it's range). Note that
this class uses some kind of index pointers to do the sorting. This
means only an intern array of the value indexes will be sorted and
nodeValues will be left untouched (if the method
change is not invoked).
nodeValues
- The vector to sortcopyVector
- If to copy the vectorpublic VectorSort(Vector nodeValues, boolean copyVector, int numNodes)
VectorSort
. The coordinates of the vector will
be sorted. Note that
this class uses some kind of index pointers to do the sorting. This
means only an intern array of the value indexes will be sorted and
nodeValues will be left untouched (if the method
change is not invoked).
nodeValues
- The vector to sortcopyVector
- If to copy the vectornumNodes
- The number of coordinates to be sortedMethod Detail |
---|
public int poll()
public int peek()
public boolean isYetUnremoved(int valueIndex)
valueIndex
-
True
if the value was not yet removed
(using remove(valueIndex)public void remove(int valueIndex)
valueIndex
- The index of the value in double array that
should be removedpublic void changeValue(int valueIndex, double value)
valueIndex
- The index of the value in the double array
to changevalue
- New valuepublic java.lang.String toString()
toString
in class java.lang.Object
public static int[] sortedIndices(Vector input)
input
- The vector which indices to sort
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |