public static readonly int N = 2; // We use 2 as 3 doesn't allow '*c#*' wildcards (but '*c#' and 'c#*' work), public static Trie <int> CreateTrie(TagLookup allTags) { // From http://algs4.cs.princeton.edu/52trie/ // 15. Substring matches. // Given a list of (short) strings, your goal is to support queries where the user looks up a string s // and your job is to report back all strings in the list that contain s. // Hint: if you only want prefix matches (where the strings have to start with s), use a TST as described in the text. // To support substring matches, insert the suffixes of each word (e.g., string, tring, ring, ing, ng, g) into the TST. var trieSetupTimer = Stopwatch.StartNew(); var trie = new Trie <int>(); trie.AddRange(allTags.Select(t => new TrieEntry <int>(t.Key, TrieTerminator))); trie.AddRangeAllowDuplicates(allTags.Select(t => new TrieEntry <int>(Reverse(t.Key), TrieReverseTerminator))); trieSetupTimer.Stop(); Logger.LogStartupMessage("\nTook {0} ({1,6:N2} ms) to SETUP the Trie (ONE-OFF cost)", trieSetupTimer.Elapsed, trieSetupTimer.Elapsed.TotalMilliseconds); return(trie); }