Contains() private method

private Contains ( char c, TrieNode node ) : TrieNode
c char
node TrieNode
return TrieNode
Exemplo n.º 1
0
        static void Main()
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                string inputText;
                StreamReader reader = new StreamReader(@"../../text.txt");
                using (reader)
                {
                    inputText = reader.ReadToEnd().ToLower();
                }

                var matches = Regex.Matches(inputText, @"[a-zA-Z]+");

                stopwatch.Stop();
                Console.WriteLine("Read from txt file and get words with regex: {0}", stopwatch.Elapsed);

                stopwatch.Reset();
                stopwatch.Restart();

                Tries t = new Tries();
                t.Insert(string.Join(" ", matches.Cast<Match>().Select(s => s.Value)));

                stopwatch.Stop();
                Console.WriteLine("insert words in trie: {0}", stopwatch.Elapsed);

                stopwatch.Reset();
                stopwatch.Restart();

                t.Contains("he");

                stopwatch.Stop();
                Console.WriteLine("search for word 'he': {0}", stopwatch.Elapsed);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                string       inputText;
                StreamReader reader = new StreamReader(@"../../text.txt");
                using (reader)
                {
                    inputText = reader.ReadToEnd().ToLower();
                }

                var matches = Regex.Matches(inputText, @"[a-zA-Z]+");

                stopwatch.Stop();
                Console.WriteLine("Read from txt file and get words with regex: {0}", stopwatch.Elapsed);

                stopwatch.Reset();
                stopwatch.Restart();

                Tries t = new Tries();
                t.Insert(string.Join(" ", matches.Cast <Match>().Select(s => s.Value)));

                stopwatch.Stop();
                Console.WriteLine("insert words in trie: {0}", stopwatch.Elapsed);

                stopwatch.Reset();
                stopwatch.Restart();

                t.Contains("he");

                stopwatch.Stop();
                Console.WriteLine("search for word 'he': {0}", stopwatch.Elapsed);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }