Example #1
0
        public void Insert(string insertType, STBase <int, string> st, int count)
        {
            switch (insertType)
            {
            case "asc":
                for (int i = 0; i < count; i++)
                {
                    st.Put(i, "a");
                }
                break;

            case "desc":
                for (int i = count; i > 0; i--)
                {
                    st.Put(i, "a");
                }
                break;

            case "random":
                Random random = new Random();
                for (int i = 0; i < count; i++)
                {
                    int j = random.Next(0, count);
                    st.Put(j, "a");
                }
                break;

            default:
                break;
            }
        }
Example #2
0
        public void Run(STBase <string, int> st, string path, int minlen)
        {
            int       wordCount = 0;
            Stopwatch watch     = Stopwatch.StartNew();

            using (Stream stream = new FileStream(path, FileMode.Open))
                using (StreamReader reader = new StreamReader(stream))
                {
                    string   content = reader.ReadToEnd();
                    string[] lines   = content.Split('\n', '\r');
                    foreach (string line in lines)
                    {
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] words = line.Split(' ');
                            foreach (string word in words)
                            {
                                if (word.Length < minlen)
                                {
                                    continue;
                                }
                                else
                                {
                                    wordCount++;
                                    if (st.Contains(word))
                                    {
                                        st.Put(word, st.Get(word) + 1);
                                    }
                                    else
                                    {
                                        st.Put(word, 1);
                                    }
                                }
                            }
                        }
                    }
                }

            string max = "";

            st.Put(max, 0);
            int keyCount = 0;

            foreach (string key in st.Keys())
            {
                keyCount++;
                if (st.Get(key) > st.Get(max))
                {
                    max = key;
                }
            }
            Console.WriteLine("Words: {0}, Keys: {1}", wordCount, keyCount);
            Console.WriteLine("{0} {1} ({2}ms)", max, st.Get(max), watch.ElapsedMilliseconds);
        }
Example #3
0
        public void Run(STBase <string, int> st)
        {
            string s = "SEARCHEXAMPLE";
            //string s = "SEARCHX";
            var chars = s.ToCharArray();

            for (int i = 0; i < chars.Length; i++)
            {
                st.Put(chars[i].ToString(), i);
            }
            foreach (string key in st.Keys())
            {
                Console.Write("{0}:{1} ", key, st.Get(key));
            }
            Console.WriteLine();
            Console.WriteLine(st.Size());

            //st.Delete("C");
            //var v = st.Get("H");
            //Console.WriteLine(v);

            //for (int i = 0; i < chars.Length; i++)
            //{
            //    string k = chars[i].ToString();
            //    Console.WriteLine("Delete {0}", k);
            //    st.Delete(k);
            //    foreach (string key in st.Keys())
            //    {
            //        Console.Write("{0}:{1} ", key, st.Get(key));
            //    }
            //    Console.WriteLine();
            //}
        }