Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var trie = new TrieLib.Trie();

            var itemsSet = new Dictionary <int, string>();

            itemsSet.Add(1, "Victor test hiking club biography");
            itemsSet.Add(2, "Alex");
            itemsSet.Add(3, "Constructor");
            itemsSet.Add(4, "Destructor");

            trie.InsertSet(itemsSet);



            Console.WriteLine(string.Join(",", trie.Search("Alex").OrderBy(e => e.Value).Select(s => $"{itemsSet[s.Key]}")));
            Console.WriteLine(string.Join(",", trie.Search("Test").OrderBy(e => e.Value).Select(s => $"{itemsSet[s.Key]}")));
            Console.WriteLine(string.Join(",", trie.Search("Victor").OrderBy(e => e.Value).Select(s => $"{itemsSet[s.Key]}")));
            Console.WriteLine(string.Join(",", trie.Search("tor").OrderBy(e => e.Value).Select(s => $"{itemsSet[s.Key]}")));
            Console.WriteLine(string.Join(",", trie.Search("e").OrderBy(e => e.Value).Select(s => $"{itemsSet[s.Key]}")));
            Console.WriteLine(string.Join(",", trie.Search("o").OrderBy(e => e.Value).Select(s => $"{itemsSet[s.Key]}")));
            Console.WriteLine(string.Join(",", trie.Search("hik").OrderBy(e => e.Value).Select(s => $"{itemsSet[s.Key]}")));

            Console.ReadLine();
        }
Exemplo n.º 2
0
        private TrieLib.Trie GetTrie(int cultureId)
        {
            if (!_cultureTries.ContainsKey(cultureId))
            {
                var translations = (from t in _context.Translation
                                    where t.CultureId == cultureId
                                    select t).ToList();
                var entries = new Dictionary <int, string>();
                translations.ForEach(translation => entries.Add(translation.Id, translation.Text.ToLower()));
                lock (lockObject)
                {
                    var cultureTrie = new TrieLib.Trie();
                    cultureTrie.InsertSet(entries);
                    _cultureTries.TryAdd(cultureId, cultureTrie);
                }
            }

            TrieLib.Trie tree;
            if (_cultureTries.TryGetValue(cultureId, out tree))
            {
                return(tree);
            }
            return(new TrieLib.Trie());
        }