@@ -40,28 +40,28 @@ public class RadixSort {
40
40
* of always copying the data back to position zero for efficiency.
41
41
*/
42
42
public static int sort (
43
- LongArray array , int numRecords , int startByteIndex , int endByteIndex ,
43
+ LongArray array , long numRecords , long startByteIndex , long endByteIndex ,
44
44
boolean desc , boolean signed ) {
45
45
assert startByteIndex >= 0 : "startByteIndex (" + startByteIndex + ") should >= 0" ;
46
46
assert endByteIndex <= 7 : "endByteIndex (" + endByteIndex + ") should <= 7" ;
47
47
assert endByteIndex > startByteIndex ;
48
48
assert numRecords * 2 <= array .size ();
49
- int inIndex = 0 ;
50
- int outIndex = numRecords ;
49
+ long inIndex = 0 ;
50
+ long outIndex = numRecords ;
51
51
if (numRecords > 0 ) {
52
52
long [][] counts = getCounts (array , numRecords , startByteIndex , endByteIndex );
53
- for (int i = startByteIndex ; i <= endByteIndex ; i ++) {
54
- if (counts [i ] != null ) {
53
+ for (long i = startByteIndex ; i <= endByteIndex ; i ++) {
54
+ if (counts [( int ) i ] != null ) {
55
55
sortAtByte (
56
- array , numRecords , counts [i ], i , inIndex , outIndex ,
56
+ array , numRecords , counts [( int ) i ], i , inIndex , outIndex ,
57
57
desc , signed && i == endByteIndex );
58
- int tmp = inIndex ;
58
+ long tmp = inIndex ;
59
59
inIndex = outIndex ;
60
60
outIndex = tmp ;
61
61
}
62
62
}
63
63
}
64
- return inIndex ;
64
+ return ( int ) inIndex ;
65
65
}
66
66
67
67
/**
@@ -78,7 +78,7 @@ public static int sort(
78
78
* @param signed whether this is a signed (two's complement) sort (only applies to last byte).
79
79
*/
80
80
private static void sortAtByte (
81
- LongArray array , int numRecords , long [] counts , int byteIdx , int inIndex , int outIndex ,
81
+ LongArray array , long numRecords , long [] counts , long byteIdx , long inIndex , long outIndex ,
82
82
boolean desc , boolean signed ) {
83
83
assert counts .length == 256 ;
84
84
long [] offsets = transformCountsToOffsets (
@@ -106,7 +106,7 @@ private static void sortAtByte(
106
106
* significant byte. If the byte does not need sorting the array will be null.
107
107
*/
108
108
private static long [][] getCounts (
109
- LongArray array , int numRecords , int startByteIndex , int endByteIndex ) {
109
+ LongArray array , long numRecords , long startByteIndex , long endByteIndex ) {
110
110
long [][] counts = new long [8 ][];
111
111
// Optimization: do a fast pre-pass to determine which byte indices we can skip for sorting.
112
112
// If all the byte values at a particular index are the same we don't need to count it.
@@ -121,12 +121,12 @@ private static long[][] getCounts(
121
121
}
122
122
long bitsChanged = bitwiseMin ^ bitwiseMax ;
123
123
// Compute counts for each byte index.
124
- for (int i = startByteIndex ; i <= endByteIndex ; i ++) {
124
+ for (long i = startByteIndex ; i <= endByteIndex ; i ++) {
125
125
if (((bitsChanged >>> (i * 8 )) & 0xff ) != 0 ) {
126
- counts [i ] = new long [256 ];
126
+ counts [( int ) i ] = new long [256 ];
127
127
// TODO(ekl) consider computing all the counts in one pass.
128
128
for (long offset = array .getBaseOffset (); offset < maxOffset ; offset += 8 ) {
129
- counts [i ][(int )((Platform .getLong (baseObject , offset ) >>> (i * 8 )) & 0xff )]++;
129
+ counts [( int ) i ][(int )((Platform .getLong (baseObject , offset ) >>> (i * 8 )) & 0xff )]++;
130
130
}
131
131
}
132
132
}
@@ -146,7 +146,7 @@ private static long[][] getCounts(
146
146
* @return the input counts array.
147
147
*/
148
148
private static long [] transformCountsToOffsets (
149
- long [] counts , int numRecords , long outputOffset , int bytesPerRecord ,
149
+ long [] counts , long numRecords , long outputOffset , long bytesPerRecord ,
150
150
boolean desc , boolean signed ) {
151
151
assert counts .length == 256 ;
152
152
int start = signed ? 128 : 0 ; // output the negative records first (values 129-255).
@@ -176,41 +176,41 @@ private static long[] transformCountsToOffsets(
176
176
*/
177
177
public static int sortKeyPrefixArray (
178
178
LongArray array ,
179
- int startIndex ,
180
- int numRecords ,
181
- int startByteIndex ,
182
- int endByteIndex ,
179
+ long startIndex ,
180
+ long numRecords ,
181
+ long startByteIndex ,
182
+ long endByteIndex ,
183
183
boolean desc ,
184
184
boolean signed ) {
185
185
assert startByteIndex >= 0 : "startByteIndex (" + startByteIndex + ") should >= 0" ;
186
186
assert endByteIndex <= 7 : "endByteIndex (" + endByteIndex + ") should <= 7" ;
187
187
assert endByteIndex > startByteIndex ;
188
188
assert numRecords * 4 <= array .size ();
189
- int inIndex = startIndex ;
190
- int outIndex = startIndex + numRecords * 2 ;
189
+ long inIndex = startIndex ;
190
+ long outIndex = startIndex + numRecords * 2L ;
191
191
if (numRecords > 0 ) {
192
192
long [][] counts = getKeyPrefixArrayCounts (
193
193
array , startIndex , numRecords , startByteIndex , endByteIndex );
194
- for (int i = startByteIndex ; i <= endByteIndex ; i ++) {
195
- if (counts [i ] != null ) {
194
+ for (long i = startByteIndex ; i <= endByteIndex ; i ++) {
195
+ if (counts [( int ) i ] != null ) {
196
196
sortKeyPrefixArrayAtByte (
197
- array , numRecords , counts [i ], i , inIndex , outIndex ,
197
+ array , numRecords , counts [( int ) i ], i , inIndex , outIndex ,
198
198
desc , signed && i == endByteIndex );
199
- int tmp = inIndex ;
199
+ long tmp = inIndex ;
200
200
inIndex = outIndex ;
201
201
outIndex = tmp ;
202
202
}
203
203
}
204
204
}
205
- return inIndex ;
205
+ return ( int ) inIndex ;
206
206
}
207
207
208
208
/**
209
209
* Specialization of getCounts() for key-prefix arrays. We could probably combine this with
210
210
* getCounts with some added parameters but that seems to hurt in benchmarks.
211
211
*/
212
212
private static long [][] getKeyPrefixArrayCounts (
213
- LongArray array , int startIndex , int numRecords , int startByteIndex , int endByteIndex ) {
213
+ LongArray array , long startIndex , long numRecords , long startByteIndex , long endByteIndex ) {
214
214
long [][] counts = new long [8 ][];
215
215
long bitwiseMax = 0 ;
216
216
long bitwiseMin = -1L ;
@@ -223,11 +223,11 @@ private static long[][] getKeyPrefixArrayCounts(
223
223
bitwiseMin &= value ;
224
224
}
225
225
long bitsChanged = bitwiseMin ^ bitwiseMax ;
226
- for (int i = startByteIndex ; i <= endByteIndex ; i ++) {
226
+ for (long i = startByteIndex ; i <= endByteIndex ; i ++) {
227
227
if (((bitsChanged >>> (i * 8 )) & 0xff ) != 0 ) {
228
- counts [i ] = new long [256 ];
228
+ counts [( int ) i ] = new long [256 ];
229
229
for (long offset = baseOffset ; offset < limit ; offset += 16 ) {
230
- counts [i ][(int )((Platform .getLong (baseObject , offset + 8 ) >>> (i * 8 )) & 0xff )]++;
230
+ counts [( int ) i ][(int )((Platform .getLong (baseObject , offset + 8 ) >>> (i * 8 )) & 0xff )]++;
231
231
}
232
232
}
233
233
}
@@ -238,7 +238,7 @@ private static long[][] getKeyPrefixArrayCounts(
238
238
* Specialization of sortAtByte() for key-prefix arrays.
239
239
*/
240
240
private static void sortKeyPrefixArrayAtByte (
241
- LongArray array , int numRecords , long [] counts , int byteIdx , int inIndex , int outIndex ,
241
+ LongArray array , long numRecords , long [] counts , long byteIdx , long inIndex , long outIndex ,
242
242
boolean desc , boolean signed ) {
243
243
assert counts .length == 256 ;
244
244
long [] offsets = transformCountsToOffsets (
0 commit comments