Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Help in C

Name: Anonymous 2012-04-09 0:47

I need to execute certain commands depending on what the value of a string is. Instead of making a lot of if statements to check the string against all possible cases I thought I would hah the strings and hash the possible values for the string for which i want to do something then handle it with a switch statement. The number of different strings I'll be comparing it to is less than 100 so i dont have to worry about collisions. Is this a good idea? Do you have other ideas?

Name: Anonymous 2012-04-09 6:01

>>10
not really. >>6 can still be considered premature optimization by statically allocating a data structure that functions as a dictionary. But by storing it as an array for linear or binary search, ey's just being lazy. A completely flexible solution would be to just use a mutable hash table, load it when the program starts via a config file, and then use it for look ups. The only difference between >>6 and >>1 is ease of implementation, which is dependent on what language features you have. Some actually have the string switches that OP wants built in.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List