示例#1
0
        static void Test(int n)
        {
            Console.Write(n + "\t");
            var data   = new double[n];
            var random = new Random(n);

            for (var i = 0; i < n; i++)
            {
                data[i] = random.NextDouble() * n;
            }

            var bst          = new BSTAnalysis <double, int>();
            var binarySearch = new BinarySearchSTAnalysis <double, int>();

            foreach (var d in data)
            {
                binarySearch.Put(d, 1);
            }

            var binarySearchTime = (double)binarySearch.CompareAndExchangeTimes;

            Console.Write(binarySearchTime + "\t");
            foreach (var d in data)
            {
                bst.Put(d, 1);
            }

            var binaryTreeTime = (double)bst.CompareTimes;

            Console.Write(binaryTreeTime + "\t");
            Console.WriteLine(binarySearchTime / binaryTreeTime);
        }
示例#2
0
        static void Main(string[] args)
        {
            var n     = 10000;
            var trial = 100;

            for (var i = 0; i < 3; i++)
            {
                var odds  = new int[n];
                var evens = new int[n];
                var bst   = new BSTAnalysis <int, int>();
                for (var j = 100; j < n; j++)
                {
                    evens[j] = j;
                    odds[j]  = j + 1;
                }
                Shuffle(odds);
                foreach (var item in odds)
                {
                    bst.Put(item, item);
                }

                Console.WriteLine("n:" + n);
                // hit
                Shuffle(odds);
                Test(bst, odds, trial, "hit");

                // miss
                Shuffle(evens);
                Test(bst, evens, trial, "miss");

                n *= 10;
            }
        }
示例#3
0
        private long[] Test(int n)
        {
            var testCases  = new long[n];
            var testResult = new long[n];

            for (var i = 0; i < n; i++)
            {
                testCases[i] = i;
            }
            Shuffle(testCases);

            var bst = new BSTAnalysis <long, int>();

            for (var i = 0; i < n; i++)
            {
                bst.CompareTimes = 0;
                bst.Put(testCases[i], 1);
                testResult[i] = bst.CompareTimes;
            }

            return(testResult);
        }