Skip to content

Commit fbd14ad

Browse files
committed
...
1 parent 740d009 commit fbd14ad

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

src/main/java/com/github/coderodde/util/ParallelRadixSort.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,19 @@ public final class ParallelRadixSort {
4949
*/
5050
private static final int DEFAULT_THREAD_THRESHOLD = 65536;
5151

52-
private static final int MINIMUM_MERGESORT_THRESHOLD = 61;
52+
/**
53+
* Minimum mergesort threshold.
54+
*/
55+
private static final int MINIMUM_MERGESORT_THRESHOLD = 7;
56+
57+
/**
58+
* Minimum insertion sort threshold.
59+
*/
5360
private static final int MINIMUM_INSERTION_SORT_THRESHOLD = 7;
61+
62+
/**
63+
* Minimum thread workload.
64+
*/
5465
private static final int MINIMUM_THREAD_WORKLOAD = 4001;
5566

5667
private static int insertionSortThreshold = DEFAULT_INSERTION_SORT_THRESHOLD;
@@ -263,7 +274,7 @@ private static void radixSortImpl(int[] source,
263274
target,
264275
source,
265276
startIndexMap[i],
266-
startIndexMap[i] + bucketSizeMap[i],
277+
startIndexMap[i],
267278
bucketSizeMap[i],
268279
recursionDepth + 1);
269280
}

src/main/java/com/github/coderodde/util/Utils.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ public final class Utils {
66

77
private static final int MAX_VALUE = 1000;
88

9-
public static int[] createRandomIntArray(int size, Random random) {
9+
public static int[] createRandomIntArray(
10+
int size,
11+
int maxValue,
12+
Random random) {
13+
1014
int[] a = new int[size];
1115

1216
for (int i = 0; i < size; i++) {
13-
a[i] = random.nextInt(MAX_VALUE + 1);
17+
a[i] = random.nextInt(maxValue);
1418
}
1519

1620
return a;
1721
}
22+
23+
public static int[] createRandomIntArray(int size, Random random) {
24+
return createRandomIntArray(size, MAX_VALUE, random);
25+
}
1826
}

src/test/java/com/github/coderodde/util/ParallelRadixSortTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
import java.util.Random;
55
import static org.junit.Assert.assertEquals;
66
import static org.junit.Assert.assertTrue;
7+
import org.junit.BeforeClass;
78
import org.junit.Test;
89

910
public final class ParallelRadixSortTest {
1011

12+
@BeforeClass
13+
public static void setupBeforeClass() {
14+
ParallelRadixSort.setInsertionSortThreshold(-1);
15+
ParallelRadixSort.setMergesortThreshold(-1);
16+
}
17+
1118
@Test
1219
public void testInsertionSort() {
1320
Random random = new Random(13L);
@@ -49,12 +56,16 @@ public void testMergesort() {
4956
@Test
5057
public void testSerialRadixSort() {
5158
Random random = new Random(26);
52-
final int SIZE = 50_000;
53-
int[] array1 = Utils.createRandomIntArray(SIZE, random);
59+
final int SIZE = 128;
60+
int[] array1 = Utils.createRandomIntArray(
61+
SIZE,
62+
Integer.MAX_VALUE - 1,
63+
random);
64+
5465
int[] array2 = array1.clone();
5566

56-
final int FROM_INDEX = 20;
57-
final int TO_INDEX = SIZE - 20;
67+
final int FROM_INDEX = 14;
68+
final int TO_INDEX = SIZE - 14;
5869

5970
Arrays.sort(array1, FROM_INDEX, TO_INDEX);
6071
ParallelRadixSort.parallelSort(

0 commit comments

Comments
 (0)