Skip to content

Commit

Permalink
Corrected blockyMergeSort
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Rhodes committed Feb 3, 2016
1 parent 42e3224 commit fb8c745
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
5 changes: 0 additions & 5 deletions src/main/java/com/yahoo/sketches/quantiles/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,6 @@ static void blockyTandemMergeSort(double[] keyArr, long[] valArr, int arrLen, in
keyArr, valArr,
0, numblks,
blkSize, arrLen);

/* verify sorted order */
for (int i = 0; i < arrLen-1; i++) {
assert keyArr[i] <= keyArr[i+1];
}
}

/**
Expand Down
25 changes: 16 additions & 9 deletions src/test/java/com/yahoo/sketches/quantiles/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ private static void assertMergeTestPostcondition (double [] arr, long [] brr, i
}


private static double [] makeMergeTestInput (int arrLen, int blkSize) {
double [] arr = new double [arrLen];
private static double[] makeMergeTestInput(int arrLen, int blkSize) {
double[] arr = new double[arrLen];

double pick = Math.random ();

Expand Down Expand Up @@ -236,18 +236,25 @@ public void checkBlockyTandemMergeSort() {
* @param numTries number of tries
* @param maxArrLen maximum length of array size
*/
private static void testBlockyTandemMergeSort (int numTries, int maxArrLen) {
for (int arrLen = 0; arrLen <= maxArrLen; arrLen++) {
private static void testBlockyTandemMergeSort(int numTries, int maxArrLen) {
int arrLen = 0;
double[] arr = null;
for (arrLen = 0; arrLen <= maxArrLen; arrLen++) {
for (int blkSize = 1; blkSize <= arrLen + 100; blkSize++) {
for (int tryno = 1; tryno <= numTries; tryno++) {
double [] arr = makeMergeTestInput (arrLen, blkSize);
long [] brr = makeTheTandemArray (arr);
assertMergeTestPrecondition (arr, brr, arrLen, blkSize);
Util.blockyTandemMergeSort (arr, brr, arrLen, blkSize);
assertMergeTestPostcondition (arr, brr, arrLen);
arr = makeMergeTestInput(arrLen, blkSize);
long [] brr = makeTheTandemArray(arr);
assertMergeTestPrecondition(arr, brr, arrLen, blkSize);
Util.blockyTandemMergeSort(arr, brr, arrLen, blkSize);
/* verify sorted order */
for (int i = 0; i < arrLen-1; i++) {
assert arr[i] <= arr[i+1];
}
assertMergeTestPostcondition(arr, brr, arrLen);
}
}
}

//System.out.printf ("Passed: testBlockyTandemMergeSort\n");
}

Expand Down

0 comments on commit fb8c745

Please sign in to comment.