Server Help

Non-Subspace Related Coding - Opinion on Alphabetic Sort

Cyan~Fire - Mon Mar 06, 2006 8:06 pm
Post subject: Opinion on Alphabetic Sort
In an effort to make a program more customizeable, some data that used to be hardcoded is now read from an XML file on load. This data sometimes has to be sorted alphabetically.

Since the data used to be static, I just had a lookup array to perform the sorting really quickly, but now of course I can't do that hardcoded. So: is it worth it to build the array when the data is loaded? Or should I just let it sort on-the-fly?
D1st0rt - Mon Mar 06, 2006 8:20 pm
Post subject:
How often is the data changing? Just once per run/load/whatever?
Cyan~Fire - Mon Mar 06, 2006 10:24 pm
Post subject:
Only once per run. Sorry, I should have made that clearer.
D1st0rt - Tue Mar 07, 2006 2:14 pm
Post subject:
If your data structure preserves order, couldn't you just sort it at the very beginning and have it always in order? If not, you could probably just make a sorted array at the beginning and keep it around for ez lookups.
Cyan~Fire - Tue Mar 07, 2006 9:41 pm
Post subject:
To put it simply, different combinations of the list have to be sorted, depending on user input. So I can't just sort it at the beginning.

Thanks.
Dr Brain - Tue Mar 07, 2006 11:39 pm
Post subject:
It sounds like a time/space tradeoff.

Is this list massively huge? If the answer is no, then it doesn't matter which way you do it. Computers are fast and can sort data quickly. Computers also have lots of ram and can hold it all after computing it once.

If it is massively huge, then the question you want to ask is "do I want it to run slowly, or have a large memory footprint?"
Cyan~Fire - Wed Mar 08, 2006 6:46 pm
Post subject:
It's not huge, usually less than 900 entires. But the size doesn't affect the speed of the alphabetic sort. I'll just leave it without the array for now, and put it in later when I'm bored.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group