Cttrie – Compile-time trie-based string matching for C++
smilingthax.github.io
Cttrie – Compile-time trie-based string matching for C++
1–10 of 21 posts
Re: Cttrie – Compile-time trie-based string matching for C++
#2[1] https://github.com/llvm-mirror/llvm/blob/master/include/llvm...
Re: Cttrie – Compile-time trie-based string matching for C++
#3Re: Cttrie – Compile-time trie-based string matching for C++
#4It allows you to write something like this: https://github.com/lpereira/lwan/blob/master/src/lib/lwan-ti... -- which is generated as a binary search by GCC.
Re: Cttrie – Compile-time trie-based string matching for C++
#5Another approach not mentioned: LLVM's StringSwitch [1]. Unfortunately it's not designed to be used independent of LLVM, so it has a dependency or two. Also note that it's a slightly different use case (can only return different values, is not used for flow control). [1] https://github.com/llvm-mirror/llvm/blob/master/include/llvm...
Re: Cttrie – Compile-time trie-based string matching for C++
#6And then you get the power of regexes too. re2c will match an arbitrary set of regexes (including constant strings) by walking through the string byte-by-byte, a single time.
A trie is basically a special case of a DFA.
Re: Cttrie – Compile-time trie-based string matching for C++
#7I like this trick that I use in C. It's limited, as it only matches string prefixes, but it works pretty well in the end: https://tia.mat.br/posts/2018/02/01/more_on_string_switch_in... It allows you to write something like this: https://github.com/lpereira/lwan/blob/master/src/lib/lwan-ti... -- which is generated as a binary search by GCC.
1. http://lolengine.net/blog/2011/12/20/cpp-constant-string-has...
Re: Cttrie – Compile-time trie-based string matching for C++
#8Re: Cttrie – Compile-time trie-based string matching for C++
#9This only an issue if you want to have many hardcoded strings in a switch. If you want that, there is a probably a better way to organize the code.