コード例 #1
0
        static void Main(string[] args)
        {
            GC_MemoryStart = System.GC.GetTotalMemory(true);
            TernaryTreeExtended <int> tree = new TernaryTreeExtended <int>();

            var lines = File.ReadAllLines("../../resources/sa.txt");

            for (int i = 0; i < lines.Length; i++)
            {
                var line = lines[i];

                var words = GetWords(line);
                foreach (var word in words)
                {
                    tree.Add(word.Trim(), i);
                }
            }

            GC_MemoryEnd = System.GC.GetTotalMemory(true);

            Console.WriteLine("========================");
            Console.WriteLine(ConvertBytesToMegabytes(GC_MemoryEnd - GC_MemoryStart) + " mb in use");
            Console.WriteLine("========================");

            Console.WriteLine();
            Console.WriteLine("Enter a search term.");
            Console.WriteLine("--------------------");

            string input;

            while ((input = Console.ReadLine()) != "xx")
            {
                var words = GetWords(input.ToLower());
                IEnumerable <int> results = null;
                foreach (var w in words)
                {
                    if (results != null)
                    {
                        results = System.Linq.Enumerable.Intersect(results, tree.Search(w));
                    }
                    else
                    {
                        results = tree.Search(w);
                    }
                }


                foreach (var r in results)
                {
                    Console.WriteLine(lines[r]);
                }

                Console.WriteLine();
                Console.WriteLine("Enter a search term.");
                Console.WriteLine("--------------------");
                Console.WriteLine();
            }
        }
コード例 #2
0
        public void TestTreePrefixSearchForValues()
        {
            TernaryTreeExtended <string> tree = new TernaryTreeExtended <string>();
            var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' ');

            foreach (var key in InputKeys)
            {
                tree.Add(key, "value of " + key);
            }

            {
                var matches = tree.Search("ab");
                int count   = getCount(matches);
                Assert.AreEqual(12, count);
                int i = 0;
                foreach (var val in matches)
                {
                    Assert.AreEqual("value of " + InputKeys[i++], val);
                }
            }
        }
コード例 #3
0
        public void TestTreePrefixSearchForValues()
        {
            TernaryTreeExtended<string> tree = new TernaryTreeExtended<string>();
            var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' ');
            foreach (var key in InputKeys)
            {
                tree.Add(key, "value of " + key);
            }

            {
                var matches = tree.Search("ab");
                int count = getCount(matches);
                Assert.AreEqual(12, count);
                int i = 0;
                foreach (var val in matches)
                {
                    Assert.AreEqual("value of " + InputKeys[i++], val);
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: gaiaing/TernaryTree
        static void Main(string[] args)
        {
            GC_MemoryStart = System.GC.GetTotalMemory(true);
            TernaryTreeExtended<int> tree = new TernaryTreeExtended<int>();

            var lines = File.ReadAllLines("../../resources/sa.txt");

            for (int i = 0; i < lines.Length; i++)
            {
                var line = lines[i];

                var words = GetWords(line);
                foreach (var word in words)
                {
                    tree.Add(word.Trim(), i);
                }

            }

            GC_MemoryEnd = System.GC.GetTotalMemory(true);

            Console.WriteLine("========================");
            Console.WriteLine(ConvertBytesToMegabytes(GC_MemoryEnd - GC_MemoryStart) + " mb in use");
            Console.WriteLine("========================");

            Console.WriteLine();
            Console.WriteLine("Enter a search term.");
            Console.WriteLine("--------------------");

            string input;
            while ((input = Console.ReadLine()) != "xx")
            {

                var words = GetWords(input.ToLower());
                IEnumerable<int> results = null;
                foreach (var w in words) {
                    if (results != null)
                    {
                        results = System.Linq.Enumerable.Intersect(results, tree.Search(w));
                    }
                    else
                    {
                        results = tree.Search(w);
                    }
                }

                foreach (var r in results)
                {
                    Console.WriteLine(lines[r]);
                }

                Console.WriteLine();
                Console.WriteLine("Enter a search term.");
                Console.WriteLine("--------------------");
                Console.WriteLine();
            }
        }