I need a quick method to determine if a given string is in the string list.
The list of strings is unknown before execution, but after that it will not change.
I could just have List<String>, called strings, and then do:
if (strings.Contains(item))
However, this will not work well if there are many lines in the list.
I could also use HashSet<String>, but this would require a call GetHashCodefor each incoming line, as well Equals, which would be empty if, for example, there are only 3 lines in the list. Did I mention it should be fast ?
When setting up, I could decide whether to use Listor HashSetdepending on the number of lines (for example, use a List of less than 10 lines, a HashSet otherwise), rather, as the logic in HybridDictionary.
Since strings are unicode, the standard Trie structure will not work, although the Radix / Patricia trie tree can. Are there any good C # implementations out there with benchmarks?
Some mentioned a workaround String GetHashCodeand used a faster hash function. Are there any benchmarks there?
Using LINQ expressions to create an optimized switch statement is a new approach that looks very interesting.
What else will work? The installation cost is not important, just the speed of the search.
If that matters, incoming line values rarely appear in the list.