11package com .github .coderodde .util ;
22
33import java .util .ArrayList ;
4- import java .util .Arrays ;
54import java .util .List ;
65import java .util .Random ;
76
@@ -279,6 +278,7 @@ private static void parallelRadixSortImpl(
279278
280279 int spawnDegree = Math .min (numberOfNonemptyBuckets , threads );
281280 int [] startIndexMap = new int [BUCKETS ];
281+ startIndexMap [0 ] = targetFromIndex ;
282282
283283 for (int i = 1 ; i != BUCKETS ; i ++) {
284284 startIndexMap [i ] = startIndexMap [i - 1 ]
@@ -301,7 +301,6 @@ private static void parallelRadixSortImpl(
301301 }
302302
303303 int sourceStartIndex = sourceFromIndex ;
304- int targetStartIndex = targetFromIndex ;
305304
306305 BucketInserterThread [] bucketInserterThreads =
307306 new BucketInserterThread [spawnDegree ];
@@ -314,14 +313,12 @@ private static void parallelRadixSortImpl(
314313 source ,
315314 target ,
316315 sourceStartIndex ,
317- targetStartIndex ,
318316 startIndexMap ,
319317 processedMaps [i ],
320318 subrangeLength ,
321319 recursionDepth );
322320
323321 sourceStartIndex += subrangeLength ;
324- // targetStartIndex += subrangeLength;
325322
326323 bucketInserterThread .start ();
327324 bucketInserterThreads [i ] = bucketInserterThread ;
@@ -332,7 +329,6 @@ private static void parallelRadixSortImpl(
332329 source ,
333330 target ,
334331 sourceStartIndex ,
335- targetStartIndex ,
336332 startIndexMap ,
337333 processedMaps [spawnDegree - 1 ],
338334 rangeLength - (spawnDegree - 1 ) * subrangeLength ,
@@ -450,8 +446,11 @@ private static void parallelRadixSortImpl(
450446 new SorterTask (
451447 target ,
452448 source ,
453- targetFromIndex + startIndexMap [bucketKey ],
454- sourceStartIndex + startIndexMap [bucketKey ],
449+ startIndexMap [bucketKey ],
450+ startIndexMap [bucketKey ] -
451+ targetFromIndex +
452+ sourceFromIndex ,
453+
455454 globalBucketSizeMap [bucketKey ],
456455 recursionDepth + 1 ,
457456 threadCountMap [i ]);
@@ -562,8 +561,8 @@ private static void radixSortImpl(int[] source,
562561 int datum = source [i ];
563562 int bucketKey = getBucketIndex (datum , recursionDepth );
564563
565- target [/*targetFromIndex + */ startIndexMap [bucketKey ] +
566- processedMap [bucketKey ]++] = datum ;
564+ target [startIndexMap [bucketKey ] +
565+ processedMap [bucketKey ]++] = datum ;
567566 }
568567
569568 if (recursionDepth == DEEPEST_RECURSION_DEPTH ) {
@@ -802,7 +801,6 @@ private static final class BucketInserterThread extends Thread {
802801 private final int [] source ;
803802 private final int [] target ;
804803 private final int sourceFromIndex ;
805- private final int targetFromIndex ;
806804 private final int [] startIndexMap ;
807805 private final int [] processedMap ;
808806 private final int rangeLength ;
@@ -811,15 +809,13 @@ private static final class BucketInserterThread extends Thread {
811809 BucketInserterThread (int [] source ,
812810 int [] target ,
813811 int sourceFromIndex ,
814- int targetFromIndex ,
815812 int [] startIndexMap ,
816813 int [] processedMap ,
817814 int rangeLength ,
818815 int recursionDepth ) {
819816 this .source = source ;
820817 this .target = target ;
821818 this .sourceFromIndex = sourceFromIndex ;
822- this .targetFromIndex = targetFromIndex ;
823819 this .startIndexMap = startIndexMap ;
824820 this .processedMap = processedMap ;
825821 this .rangeLength = rangeLength ;
@@ -834,8 +830,8 @@ public void run() {
834830 int datum = source [i ];
835831 int bucketKey = getBucketIndex (datum , recursionDepth );
836832
837- target [targetFromIndex + startIndexMap [bucketKey ] +
838- processedMap [bucketKey ]++] = datum ;
833+ target [startIndexMap [bucketKey ] +
834+ processedMap [bucketKey ]++] = datum ;
839835 }
840836 }
841837 }
0 commit comments