Original Post
I have the radix sort implemented in Java. I use a byte sort implementation. What I don't get is why it's so slow. This was for a previous assignment that I've already turned in, but I thought it be handy to use in my own programming and I'd like to get it faster. On my 1.5ghz PowerBook, it can only sort 500,000 numbers in 5 seconds. The code is below. QueueList is just a basic queue data structure that I've made.
public void sort(QueueList numbers) {//{{{
boolean negative = false;
boolean update = true;
int count = 1;
for (int j = 0; j < count; ++j) {
while (!numbers.isEmpty()) {
try {
Integer num = (Integer) numbers.dequeue();
int value = num.intValue();
int index = (value >> j * 8) & 0xFF;
queue[index].enqueue(num);
int next = (value >> (j + 1) * 8) & 0xFF;
if (update && next != 0 && next != 255) {
++count;
update = false;
}
if (!negative && next == 255) {
++count;
negative = true;
}
} catch (Underflow e) {
}
}
update = true;
if (negative && j == count - 1) {
while (!queue[255].isEmpty()) {
try {
numbers.enqueue(queue[255].dequeue());
} catch (Underflow e) {
}
}
}
for (int i = 0; i < queue.length; ++i) {
while(!queue.isEmpty()) {
try {
numbers.enqueue(queue.dequeue());
} catch (Underflow e) {
}
}
}
}
}//}}}