Is there any speed- and cache-efficient implementations of trie in C/C++? I know what a trie is, but I don't want reinvent the wheel, implementing it myself.
Is there any speed- and cache-efficient implementations of trie in C/C++? I know what a trie is, but I don't want reinvent the wheel, implementing it myself.
if you are looking for an ANSI C implementation you can "steal" it from FreeBSD. The file you are looking for is called radix.c. It's used for managing routing data in kernel.
I've had good luck with libTrie. It may not be specifically cache optimized but the performance has always been decent for my applications.
References,
C implementation)Judy arrays: Very fast and memory efficient ordered sparse dynamic arrays for bits, integers and strings. Judy arrays are faster and more memory efficient than any binary-search-tree (incl. avl & red-black-trees).
You can also try TommyDS at http://tommyds.sourceforge.net/
See the benchmarks page on the site for a speed comparison with nedtries and judy.
Cache optimizations are something you'll probably are going to have to do, because you'll have to fit the data into a single cacheline which generally is something like 64 bytes (which will probably work if you start combining data, such as pointers). But it's tricky :-)
I've had very good results (very good balance between performance and size) with marisa-trie compared to several TRIE implementations mentioned with my data set.