Question: Is there a way for the compiler to sort the different cases in a switch-case table and parse them in binary search style? I want to reduce the worst-case number of comparisons.
I'm building a user interface where an incoming command character from the user is compared to 20 recognized commands. Then when a comparison matches the MCU will know what to do.
So if the user enters the first recognized command character on the comparison list, the first comparison matches. But if it's the last compared command character it will take 20 comparisons to get a match. And if the user enters somehting that isn't on the list it will take 20 comparisons to determine that. In my code I do this quite frequently.
It's easy for me to sequence the recognized command characters and build a binary-search-style tree structure out of them that reduces the worst-case number of comparisons. But that would make the code less readable. And it would make the list of recognized commands harder to edit.