I have a problem where I need to sort an extremely large number of numbers but the numbers are in a narrow range (0..r-1) where r is typically around 10, and after googling around a bit it seemed like a good time to use radix sort. I have the following implementation below (I had to extract it out of a much larger program and simplify for illustration). It seems reasonably fast, but is there any other trick I can use to further speed it?
public static void sort(int[] data, int radix) {
int aux[] = new int[data.length];
int count[] = new int[radix];
for (int i = 0; i < data.length; i++) {
count[data[i]]++;
}
int cumulate = 0;
for (int i = 0; i < radix; i++) {
for (int j = 0; j < count[i]; j++)
aux[cumulate + j] = i;
cumulate = cumulate + count[i];
}
for (int i = 0; i < aux.length; i++) {
data[i] = aux[i];
}
}