Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Firstly,I want to inform you that my overall/main target is to execute certain functions using their function name(string) as an argument,I defined a function as below: (I want to generate a unique number for each string data that I inserted as argument to a function).
C#
#include <iostream>
    #include <string>
    #include <hash_set>

    using namespace std;
    void Func_Execution(string &s){
        int k=stdext::hash_value(s);
     #if(_MSC_VER ==1500)
        switch (k)
        {
        case -336300864: GETBATTERYCALLSIGNS();
            break;
        case -1859542241:GETGUNIDS();
            break;
        case 323320073:Foo(); // here int k=323320073 for string s="Foo"
            break;
        case 478877555:Bar();
            break;
            defalut :Exit();
               break;
         }
    #endif
    }


Here I call Func_Execution function as below:

C#
void main(){
string s="Foo";
Func_Execution(s);
}


I want to know that is there any efficient(considering perfomance/time consuming) and effective mechanism to generate a unique numerical value for certain string(character pattern) rather than using stdext::hash_value() function?(Also notice I want to implement switch-case too)
Posted

1 solution

Try using std::map first. Yep, the performance is rubbish but often you can't tell the difference between optimal and rubbish when you've got a small number of things (less than thousands) to choose between. Another thing you might want to try is std::unordered_map as you can then write portable code. Basically grab and use stuff out of the standard library until you know (by measuring it) that it's not going to be fast enough.

Final thought... if you want to use functions by name rather than by address then perhaps a language like JavaScript or Python which supports finding functions by name would be more appropriate for your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900