Fast dictator in C without linear search

How can I make a fast dictator (String => Pointer and Int => Pointer) in C without linear search? I need a few (or more) lines of code, not a library, and this should be possible to use in closed source software (LGPL, ...).

+2


source to share


4 answers


Use a Hash Table . The hash table will have a persistent lookup. Here are some excerpts from C and a C (and Portuguese) implementation :) .



+6


source


You need to implement a Hash Table that stores objects using a hash code. The search time is constant.



A Binary tree can traverse and search for an element in log (n) time.

+2


source


For this mission, the Triple Search Tree was born .

+1


source


If the strings are long, you won't be able to consider the "Hash Table" constant! execution time depends on the length of the string! for long lines this will cause problems. also, you have the problem of collisions with too small table or too bad hash function.

if you want to use hashing look at rabin carp. if you want to be dependent on the SOLELY algorithm for the word size you are looking for, please have a look at aho-corasick.

+1


source







All Articles