I understand that I should not optimize every single spot of my program so please consider this question to be \"academic\"
I have maximum 100 strings and integer n
If the strings are known at compile-time you can just use an enumeration:
enum
{
Str1,
Str2
};
const char *Strings = {
"Str1",
"Str2"
};
Using some macro tricks you can remove the redundancy of re-creating the table in two locations (using file inclusion and #undef).
Then lookup can be achieved as fast as indexing an array:
const char *string = Strings[Str1]; // set to "Str1"
This would have optimal lookup time and locality of reference.