I am writing an advanced calculator in C. As you can guess, it currently has many functions, and I use the switch to perform the correct operation for each function name. This happens something like this:
switch(hash_of(function_name_currently_being_parsed))
{
case HASH_COS:
break;
case HASH_SIN:
break;
}
So far, I have used this simple function that I found somewhere on the Internet to do hashing:
#define NHASH 29989
#define MULT 31
unsigned int simple_hash(char *p)
{
unsigned int h = 0;
for(; *p; p++)
h = MULT * h + tolower(*p);
return h % NHASH;
}
He did this job just fine and really fast. However, now that the calculator is expanding more and more, as well as users can define their own functions and variables, collisions become very visible - for example, condand dotpthe two hash to 612.
- , , ? , , , , .
.