static void Main() { string fileLocation = "@../../text.txt"; StreamReader reader = new StreamReader(fileLocation); string text; using (reader) { text = reader.ReadToEnd(); } char[] separators = new char[] { '.', ',', ' ', '?', '!', '-', '(', ')' }; string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries); WordsTree tree = new WordsTree(); Dictionary <string, int> dict = new Dictionary <string, int>(); Stopwatch watch = new Stopwatch(); watch.Start(); foreach (var word in words) { tree.Add(word); } Console.WriteLine(tree.SearchOccurences("sit")); watch.Stop(); Console.WriteLine("Time elapsed trie structure: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var word in words) { if (dict.ContainsKey(word)) { dict[word]++; } else { dict.Add(word, 1); } } Console.WriteLine(dict["sit"]); watch.Stop(); Console.WriteLine("Time elapsed dictionary: {0}", watch.Elapsed); }
static void Main() { string fileLocation = "@../../text.txt"; StreamReader reader = new StreamReader(fileLocation); string text; using(reader) { text = reader.ReadToEnd(); } char[] separators = new char[] { '.', ',', ' ', '?', '!', '-', '(', ')' }; string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries); WordsTree tree = new WordsTree(); Dictionary<string, int> dict = new Dictionary<string, int>(); Stopwatch watch = new Stopwatch(); watch.Start(); foreach (var word in words) { tree.Add(word); } Console.WriteLine(tree.SearchOccurences("sit")); watch.Stop(); Console.WriteLine("Time elapsed trie structure: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var word in words) { if (dict.ContainsKey(word)) { dict[word]++; } else { dict.Add(word, 1); } } Console.WriteLine(dict["sit"]); watch.Stop(); Console.WriteLine("Time elapsed dictionary: {0}", watch.Elapsed); }