24package umontreal.ssj.util.multidimsort;
26import java.util.Arrays;
77 double[] batchExponents;
91 if (batchNumbers ==
null)
92 throw new NullPointerException(
"batchNumbers is null");
94 this.batchNumbers = batchNumbers;
95 dimension = batchNumbers.length;
97 for (
int i = 0; i < batchNumbers.length; ++i)
98 batchProduct *= batchNumbers[i];
108 if (batchExponents ==
null)
109 throw new NullPointerException(
"batchExponents is null");
110 this.batchExponents = batchExponents;
112 dimension = batchExponents.length;
113 batchNumbers =
new int[dimension];
115 for (
int j = 0; j < dimension; ++j)
116 sum += batchExponents[j];
117 if (Math.abs(sum - 1) > 1.0e-10)
118 throw new IllegalArgumentException(
"Sum of batchExponents not equal to 1");
129 if (batchExponents ==
null)
130 throw new NullPointerException(
"batchExponents is null");
131 if (useExponents ==
false)
132 throw new IllegalArgumentException(
"method allowed only when using proportion exponents");
135 for (
int dim = 0; dim < dimension; ++dim) {
136 batchNumbers[dim] = (int) Math.ceil(Math.pow(n, batchExponents[dim]));
137 batchProduct *= batchNumbers[dim];
150 if (batchExponents ==
null)
151 throw new NullPointerException(
"batchExponents is null");
152 if (batchExponents.length != dimension)
153 throw new IllegalArgumentException(
"batchExponents has wrong dimension");
156 this.batchExponents = batchExponents;
157 double sumExponents = 0.0;
158 for (
int dim = 0; dim < dimension; ++dim) {
159 sumExponents += batchExponents[dim];
161 if (Math.abs(sumExponents - 1.0) > 1.0e-10)
162 throw new IllegalArgumentException(
"Sum of batchExponents not equal to 1");
183 return batchExponents;
186 public int dimension() {
193 public void sort(T[] a,
int iMin,
int iMax) {
194 if (iMin + 1 == iMax)
196 if (useExponents && (nSaved != iMax - iMin))
199 int bsize = iMax - iMin;
200 for (
int j = 0; (j < dimension) && (bsize > 1); ++j) {
203 if (batchNumbers[j] == 1)
211 Arrays.sort(a, i1, i2, compar);
214 bsize = (int) Math.ceil(bsize / batchNumbers[j]);
222 sort(a, 0, a.length);
228 public void sort(
double[][] a,
int iMin,
int iMax) {
229 if (iMin + 1 == iMax)
231 if (useExponents && (nSaved != iMax - iMin))
234 int bsize = iMax - iMin;
235 for (
int j = 0; (j < dimension) && (bsize > 1); ++j) {
238 if (batchNumbers[j] == 1)
245 Arrays.sort(a, i1, i2, compar);
248 bsize = (int) Math.ceil(bsize / batchNumbers[j]);
255 public void sort(
double[][] a) {
256 sort(a, 0, a.length);
int getBatchProduct()
Returns the product of current batch numbers.
void sort(T[] a)
Sorts the entire array.
int[] getBatchNumbers()
Returns the current vector of batch numbers .
void setBatchExponents(double[] batchExponents)
Sets the vector of proportion exponents to the values in batchExponents.
BatchSort(double[] batchExponents)
Constructs a BatchSort that will use the proportion exponents in batchExponents, which must contain n...
void sort(double[][] a)
Sorts the entire array.
void setBatchNumbers(int n)
Resets the corresponding vector of batch numbers for the given number of objects.
double[] getBatchExponents()
Returns the current vector of batch exponents .
void sort(double[][] a, int iMin, int iMax)
Sorts the subarray a[iMin..iMax-1] using this batch sort.
void sort(T[] a, int iMin, int iMax)
Sorts the subarray a[iMin..iMax-1] using this batch sort.
BatchSort(int[] batchNumbers)
Constructs a BatchSort that will always use the (fixed) batch numbers given in batchNumbers.
This provides an implementation of Comparator in which arrays of double in dimensions are compared b...
This class is useful if one wishes to perform an ordinary one-dimensional sort on MultiDimComparable<...
This interface is an extension (or variant) of the Comparable interface in Java.
This interface extends MultiDimSort<T> to implement multivariate sorting algorithms that sort objects...