public class IndexTable extends Object implements Serializable
sort(java.util.List, java.util.Comparator)
methods. This can be
called on inputs of varying size, and the internal order will be expanded
when necessary.Constructor and Description |
---|
IndexTable(double[] array)
Creates a new index table based on the given array.
|
IndexTable(int size)
Creates a new index table of a specified size that is in linear order.
|
IndexTable(List<T> list)
Creates a new index table based on the given list.
|
IndexTable(List<T> list,
Comparator<T> comparator)
Creates a new index table based on the given list and comparator.
|
IndexTable(T[] array)
Creates a new index table based on the given array.
|
Modifier and Type | Method and Description |
---|---|
void |
apply(double[] target)
Applies this index table to the specified target, putting
target
into the same ordering as this IndexTable. |
void |
apply(List target)
Applies this index table to the specified target, putting
target
into the same ordering as this IndexTable. |
void |
apply(List target,
List tmp)
Applies this index table to the specified target, putting
target
into the same ordering as this IndexTable. |
static <T> Comparator<T> |
getReverse(Comparator<T> cmp)
Obtains the reverse order comparator
|
int |
index(int i)
Given the index i into what would be the sorted array, the index in the unsorted original array is returned.
|
int |
length()
The length of the previous array that was sorted
|
void |
reset()
Resets the index table so that the returned indices are in linear order,
meaning the original input would be returned in its original order
instead of sorted order.
|
void |
reverse()
Reverse the current index order
|
void |
sort(double[] array)
Adjusts this index table to contain the sorted index order for the given
array
|
<T extends Comparable<T>> |
sort(List<T> list)
Adjust this index table to contain the sorted index order for the given
list
|
<T> void |
sort(List<T> list,
Comparator<T> cmp)
Sets up the index table based on the given list of the same size and
comparator.
|
void |
sortR(double[] array)
Adjusts this index table to contain the reverse sorted index order for
the given array
|
<T extends Comparable<T>> |
sortR(List<T> list)
Adjusts this index table to contain the reverse sorted index order for
the given list
|
void |
swap(int i,
int j)
Swaps the given indices in the index table.
|
public IndexTable(int size)
size
- the size of the index table to createpublic IndexTable(double[] array)
array
- the array to create an index table for.public IndexTable(T[] array)
array
- the array to create an index table forpublic IndexTable(List<T> list)
list
- the list to create an index table forpublic IndexTable(List<T> list, Comparator<T> comparator)
list
- the list of points to obtain a sorted IndexTable forcomparator
- the comparator to determined the sorted orderpublic static <T> Comparator<T> getReverse(Comparator<T> cmp)
T
- the data typecmp
- the original comparatorpublic void reset()
public void reverse()
public void sort(double[] array)
array
- the input to get sorted order ofpublic void sortR(double[] array)
array
- the input to get sorted order ofpublic <T extends Comparable<T>> void sort(List<T> list)
T
- the data typelist
- the list of objectspublic <T extends Comparable<T>> void sortR(List<T> list)
T
- the data typelist
- the list of objectspublic <T> void sort(List<T> list, Comparator<T> cmp)
T
- the type in uselist
- the list of points to obtain a sorted IndexTable forcmp
- the comparator to determined the sorted orderpublic void swap(int i, int j)
i
- the second index to swapj
- the first index to swappublic int index(int i)
for(int i = 0; i < indexTable.length
(); i++)
System.out.println(vals[indexTable.get(i)]);
i
- the index of the i'th sorted valuepublic int length()
public void apply(double[] target)
target
into the same ordering as this IndexTable.RuntimeException
- if the length of the target array is not the same as the index tablepublic void apply(List target)
target
into the same ordering as this IndexTable.RuntimeException
- if the length of the target List is not the same as the index tablepublic void apply(List target, List tmp)
target
into the same ordering as this IndexTable. It will use the provided
tmp
space to store the original values in target in the same
ordering. It will be modified, and may be expanded using the add
method if it does not contain sufficient
space. Extra size in the tmp list will be ignored. After this method is
called, tmp
will contain the same ordering that was in
target
target
- the list to sort, that should be the same size as the
previously sorted list.tmp
- the temp list that may be of any sizeCopyright © 2017. All rights reserved.