Beispiel #1
0
        static void Main(string[] args)
        {
            ThetaList <int> theta = new ThetaList <int>();

            int largeNumber = 1000000;

            for (int i = 0; i < largeNumber; i++)
            {
                theta.Add(i);
            }
            Console.WriteLine("Stating " + largeNumber + " inserts on a theta list");

            // all the operations you perform are cached in a red black tree
            // the size of the tree is bound by the amount of the operations you perform
            for (int i = 0; i < largeNumber; i++)
            {
                theta.Insert(i, i);
            }

            // loopups and sets correspond to the operations you have performed
            theta[5] = 0;
            Console.WriteLine("value at index 5 is : " + theta[5]);

            theta.RemoveAt(5);

            // call commit to apply the red black tree back to the arraylist.
            // this will leave the tree empty and the theata list behaves exacly like an array list for lookups and set operations
            theta.Commit();        // calling commit will not reallocate the array , unless it's capcity is exceeded

            Console.WriteLine("done");



            // let's compare it with a regular list
            List <int> list = new List <int>();

            for (int i = 0; i < largeNumber; i++)
            {
                list.Add(i);
            }

            Console.WriteLine("Stating " + largeNumber + " inserts on a regular array list, this is gonna take some time...");

            for (int i = 0; i < largeNumber; i++)
            {
                list.Insert(i, i);
            }
            Console.WriteLine("done");
            Console.WriteLine("Press any key to end");
            Console.ReadKey(true);
        }
Beispiel #2
0
        /// <summary>
        /// this program tests the operations of a theta list using a regular array list to verify integrity
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Random r = new Random();

            ThetaList <int> theta      = new ThetaList <int>();
            List <int>      list       = new List <int>();
            int             totalTests = 100000;

            for (int t = 0; t < totalTests; t++)
            {
                int total    = r.Next(0, t);  // use randomly increaseing values
                int totalOps = r.Next(0, t);; //

                Console.WriteLine("start test " + t);
                Console.WriteLine("total in list: " + total);
                Console.WriteLine("total operations: " + totalOps);

                list.Clear();       //clear both lists from previous tests
                theta.Clear();

                for (int i = 0; i < total; i++)
                {
                    list.Add(r.Next());             // create both lists with random data
                }
                theta.AddRange(list);


                /*---------------------*/


                for (int i = 0; i < totalOps; i++)
                {
                    int op = r.Next(0, 3);
                    if (list.Count == 0)
                    {
                        op = 0;
                    }
                    if (op == 0)
                    {
                        int index = r.Next(list.Count);
                        int item  = r.Next();
                        //Console.WriteLine("inserting at: " + index + " value: " + item);
                        list.Insert(index, item);
                        theta.Insert(index, item);
                    }
                    else if (op == 1)
                    {
                        int index = r.Next(list.Count);
                        int item  = r.Next();
                        //  Console.WriteLine("set at: " + index + " value: " + item);
                        list[index]  = item;
                        theta[index] = item;
                    }
                    else
                    {
                        int index = r.Next(list.Count);
                        list.RemoveAt(index);
                        theta.RemoveAt(index);
                    }
                }
                if (Compare(list, theta) == false)  // compare the lists before calling commit
                {
                    Debugger.Break();
                }

                theta.Commit();

                if (Compare(list, theta) == false)  // compare the lists after calling commit
                {
                    Debugger.Break();
                }
                Console.WriteLine("test succeeded");
            }
            Console.WriteLine("done");
            Console.ReadKey(true);
        }