示例#1
0
        public static void Main()
        {
            // Library from NuGet Packages
            TextGenerator generator = new TextGenerator(WordTypes.Name);

            string           names = generator.GenerateText(1000);
            Trie             trie  = new Trie();
            HashSet <string> words = new HashSet <string>();

            names.Split(' ').ToList().ForEach(
                x =>
            {
                words.Add(x);
                trie.AddWord(x);
            });

            var result = new StringBuilder();

            foreach (var word in words.OrderBy(x => x))
            {
                int occurenceCount;
                trie.TryFindWord(word, out occurenceCount);
                result.AppendFormat("{0} -> {1} times", word, occurenceCount).AppendLine();
            }

            Console.WriteLine(result);

            Console.WriteLine("Number of words: " + words.Count);
        }
示例#2
0
        private static Trie GenerateTrie(string[] words, int count)
        {
            var trie = new Trie();

            for (int i = 0; i < count; i++)
            {
                trie.AddWord(words[random.GenerateRandomNumber(0, words.Length - 1)]);
            }

            return(trie);
        }
示例#3
0
        private static Trie GenerateTrie(string[] words, int count)
        {
            var trie = new Trie();

            for (int i = 0; i < count; i++)
            {
                trie.AddWord(words[random.GenerateRandomNumber(0, words.Length - 1)]);
            }

            return trie;
        }