Author |
Message |
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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? _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
|
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Mon Mar 06, 2006 8:20 pm Post subject: |
|
|
|
|
How often is the data changing? Just once per run/load/whatever? _________________
|
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Mon Mar 06, 2006 10:24 pm Post subject: |
|
|
|
|
Only once per run. Sorry, I should have made that clearer. |
|
Back to top |
|
|
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: 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. |
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. |
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: 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?" _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. |
|
Back to top |
|
|
|