Hello,
My algorithm has a few "modes", currently defined by an integer 'id'. A lot of my code features "breaker functions", which accept generic input and then return a mode-specific result, e.g.:
1 2 3 4 5 6
|
int breakerSomething(int A) {
switch(mode) {
case 0: return A+5;
case 1: return A-3;
}
}
|
That kind of stuff. Now, the number assigned to each mode does have an impact, because the algorithm cycles through modes in a pre-determined order. I switch the order by changing the id numbers of each mode (mode 0 is always first). That also means I have to adjust my cases each time.
I'm pretty sure I could solve this by defining an enum and naming each mode, then adjust the order of the names in the enum. Sadly, I've never used them and I don't know how they work. Can someone provide me an example of how to use them?
Secondly, I once read the specific case id's can have an effect on performance. The example in the article was comparing cases (0, 1, 2, 3, ..) versus (1, 18, 105, 106, ..) or so, as in "random" numbers rather than the structured 0->3. I think enums use the first (sequential numbers), but would the order in which cases appear cause performance issues, e.g. having case 1 appear before case 0, or so?
Lastly, one of the breaker functions can be replaced with a lookup table, because it just returns a constant for each "mode". Is there a way to do this safely with the enum-types? (i.e. safe from changes in order of the enum-types)
Thanks in advance!