Skip to content

Commit 28256e7

Browse files
committed
Committing before git pull. Tests and friends.
1 parent f444a3c commit 28256e7

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public final class ParallelRadixSort {
1515
/**
1616
* The index of the most significant byte.
1717
*/
18-
private static final int MOST_SIGNIFICANT_BYTE_INDEX = 3;
18+
private static final int DEEPEST_RECURSION_DEPTH = 3;
1919

2020
/**
2121
* The mask for extracting the sign bit.
@@ -194,7 +194,9 @@ private static void radixSortImpl(int[] source,
194194
for (int i = sourceFromIndex;
195195
i != sourceToIndex;
196196
i++) {
197-
bucketSizeMap[getBucketIndex(source[i], recursionDepth)]++;
197+
int datum = source[i];
198+
int bucketIndex = getBucketIndex(datum, recursionDepth);
199+
bucketSizeMap[bucketIndex]++;
198200
}
199201

200202
// Start computin the map mapping each bucket key to the index in the
@@ -216,7 +218,7 @@ private static void radixSortImpl(int[] source,
216218
processedMap [bucketKey]++] = datum;
217219
}
218220

219-
if (recursionDepth == MOST_SIGNIFICANT_BYTE_INDEX) {
221+
if (recursionDepth == DEEPEST_RECURSION_DEPTH) {
220222
System.arraycopy(
221223
target,
222224
targetFromIndex,
@@ -411,7 +413,7 @@ private static void merge(int[] source,
411413

412414
static int getBucketIndex(int element, int recursionDepth) {
413415
return ((recursionDepth == 0 ? element ^ SIGN_BIT_MASK : element)
414-
>>> ((MOST_SIGNIFICANT_BYTE_INDEX - recursionDepth)
416+
>>> ((DEEPEST_RECURSION_DEPTH - recursionDepth)
415417
* BITS_PER_BYTE))
416418
& EXTRACT_BYTE_MASK;
417419
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,26 @@ public void getBucketIndex() {
184184
3);
185185

186186
assertEquals(0x78, bucketKey);
187+
188+
bucketKey =
189+
ParallelRadixSort.getBucketIndex(
190+
0x8000_0001,
191+
0);
192+
193+
assertEquals(0, bucketKey);
194+
195+
bucketKey =
196+
ParallelRadixSort.getBucketIndex(
197+
0x8000_00ff,
198+
0);
199+
200+
assertEquals(0, bucketKey);
201+
202+
bucketKey =
203+
ParallelRadixSort.getBucketIndex(
204+
0x8000_0503,
205+
0);
206+
207+
assertEquals(1, bucketKey);
187208
}
188209
}

0 commit comments

Comments
 (0)