Thread: Table Sorting
View Single Post
07-20-14, 05:27 PM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
No language I've ever worked with has any way of sorting a hash table either. The very definition of a hash table is that it's an "unordered associative array".

Originally Posted by Resike View Post
Because i want to keep the categoies in alphabetical order, however i want to keep the subcats in order of apperance : "Character Info", "SpellBookFrame", "PlayerTalentFrame", "AchievementFrame" and not sorted.
But why do you want to "keep" the categories in alphabetical order? Are you expecting to have them in alphabetical order in your saved variables file? (That's impossible, so just give up now.) Are you showing them in a list in a GUI to the addon user? (Just use the solution I posted, as it's the only solution possible; the helper function Malakahh posted earlier is just a more complicated variation on the same thing with a lot of unnecessary overhead.) Are you doing something else? If so, what is it?

I also really don't understand why you keep talking about the subcategories. The solution posted in this thread only addresses the issue of iterating over the top-level keys in alphabetical order and does not in any way affect the values of those keys, nor any keys in sub-tables. If you want to iterate over keys in sub-tables in a fixed order, you can do that too, but as with the alphabetical iteration, it will require either using a second, indexed table to hold the keys in the desired order, or changing your whole table structure to only use indexed tables.

I feel like you're focusing too hard on this specific method you've imagined, and forgetting about the actual problem you're trying to solve. Right now you're trying to put the square peg in the round hole, and you keep asking how to do that, rather than realizing that what you really need to do is just get the peg into the box, and then taking a step back and realizing that there is a round hole right next to the square hole, and you don't actually have to put the square peg through the round hole after all. But if you won't tell us what the real problem is, all we can do is keep trying to explain why the solution you want to use just isn't going to work.

I really want to help you here, but unless you can actually tell us what the general problem you're trying to solve is, I just don't think there's anything more I can add to this topic.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote