Jump to content
  • Advertisement
Sign in to follow this  
Xilo

Radix Sort

This topic is 4501 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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) {
				}
			}
		}
	}
}//}}}

Share this post


Link to post
Share on other sites
Advertisement
Proper Radix Sort implementation (in C++, just translate it):
http://www.codercorner.com/RadixSortRevisited.htm

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!