First lets say you have functions
void foo1 (...)
{...}
void foo2 (...)
{...}
void foo3 (...)
{...}
void foo4 (...)
{...}
void foo5 (...)
{...}
Now I know we can pick a function by using either of these
void pickFunction1(char input[])
{
if (strcmp(input, "foo1") == 0) foo1(...);
else if (strcmp(input, "foo2") == 0) foo2(...);
else if (strcmp(input, "foo3") == 0) foo3(...);
else if (strcmp(input, "foo4") == 0) foo4(...);
else if (strcmp(input, "foo5") == 0) foo5(...);
}
void pickFunction2(char input[])
{
switch(input) {
case 'foo1' :
foo1(... );
break;
case 'foo2' :
foo2(... );
break;
case 'foo3' :
foo3(... );
break;
case 'foo4' :
foo4(... );
break;
case 'foo5' :
foo5(... );
break;
}
Now my question is what happens when you have many more options, lets say you have foo1(), foo2(),....foo10000()
then the previous two pickFunction
s will grow linearly (O(N) where N is the number of options) with the amount of options available. Is there a way to make this linear growth of function selection into to a more constant growth function selection? Like something akin to (funcall input)
in LISP?