Example #1
0
        public static void exampleTests()
        {
            BTree<string> T1 = new BTree<string>();
            T1.Add("programming");  T1.Add("languages");
            T1.Add("provide");      T1.Add("lots");
            T1.Add("opportunity");  T1.Add("for");
            T1.Add("mistakes");

            string[] arr = new string[10];
            T1.CopyTo(arr, 0);

            BTree<string> T2 = new BTree<string>();
            T2.Add("pg"); T2.Add("lg");
            T2.Add("asdf"); T2.Add("l");

            BTree<string> asdf = T1 + T2;
            asdf.ToString();
            IEnumerator<string> e = T1.GetEnumerator();
            while (e.MoveNext())
                Console.WriteLine(e.Current);
            e.Reset();
            while (e.MoveNext())
                Console.WriteLine(e.Current);

            Console.WriteLine(T1.ToString());

            T1.Remove("languages");
        }
Example #2
0
        static void RunBTree()
        {
            try
            {
                BTree<Number> tree0 = new BTree<Number>();
                tree0.Add(new Number(5));
                tree0.Add(new Number(3));
                tree0.Add(new Number(2));
                tree0.Add(new Number(4));
                tree0.Add(new Number(6));
            }
            catch (ComparationException e) { Console.WriteLine(e.Message); }

            BTree<int> tree = new BTree<int>();

            tree.Add(5);
            tree.Add(3);
            tree.Add(2);
            tree.Add(4);
            tree.Add(6);

            foreach (int i in tree) Console.Write(i + " ");
            Console.WriteLine();
            tree.TraverseOrder = BTree<int>.Order.INORDER;
            foreach (int i in tree) Console.Write(i + " ");
            Console.WriteLine();
            tree.TraverseOrder = BTree<int>.Order.POSTODER;
            foreach (int i in tree) Console.Write(i + " ");
            Console.WriteLine();
        }
Example #3
0
        static void Main(string[] args)
        {
            BTree<int> tree = new BTree<int>(1);
            tree.Add(5, 5);
            tree.Add(1, 1);
            tree.Add(2, 2);
            tree.Add(4, 4);
            tree.Add(6, 6);

            Console.WriteLine(tree.ToPrint());
        }
Example #4
0
        public static void abcTests()
        {
            BTree<string> tree = new BTree<string>();
            tree.Add("D");
            tree.Add("B");
            tree.Add("F");
            tree.Add("A");
            tree.Add("C");
            tree.Add("E");
            tree.Add("G");

            Console.WriteLine(tree.Count);
            tree.Remove("B");
            Console.WriteLine(tree.Count);
            BTree<string> cloneTree = tree.Clone();
            Console.WriteLine(cloneTree.ToString());
            Console.WriteLine(tree.ToString());
            BTree<string> t1 = new BTree<string>();
            BTree<string> t2 = new BTree<string>();
            t1.Remove("12");
            BTree<string> nulltest = t1 + t2;

            t1.Add("D");
            t1.Add("B");
            t1.Add("A");
            t1.Add("C");

            t2.Add("F");
            t2.Add("E");
            t2.Add("G");

            BTree<float> t3 = new BTree<float>();
            t3.Add((float)11.23);
            t3.Add((float)1.7);

            float[] vals = new float[t3.Count + 5];
            t3.CopyTo(vals, 5);

            Console.WriteLine(t1.Count + "\n" + t2.Count);
            BTree<string> addedTree = t1 + t2;
            Console.WriteLine(addedTree.Count);
            addedTree.Clear();
            Console.WriteLine(addedTree.ToString() + addedTree.Count);

            BTree<string> asdf = addedTree + tree;
            Console.WriteLine(asdf);
        }
Example #5
0
 protected virtual void Add(Transaction transaction, int element)
 {
     _btree.Add(transaction, element);
 }
Example #6
0
 private void AddSlot(Slot slot)
 {
     _slotsByLength.Add(Transaction(), slot);
     _slotsByAddress.Add(Transaction(), slot);
     _listener.SlotAdded(slot.Length());
 }
Example #7
0
        public void ForEachEnumeratorTest()
        {
            var bt = new BTree <int, string>(4);

            bt.Add(50, "Alpha50");
            bt.Add(70, "Alpha70");
            bt.Add(30, "Alpha30");
            bt.Add(35, "Alpha35");
            bt.Add(25, "Alpha25");
            bt.Add(65, "Alpha65");
            bt.Add(75, "Alpha75");

            bt.TraversalType = TreeTraversalType.PreOrder;

            System.Collections.Generic.List <int> lst = new System.Collections.Generic.List <int>();
            foreach (KeyValuePair <int, string> thisOne in bt)
            {
                lst.Add(thisOne.Key);
            }

            Assert.AreEqual(50, lst[0]);
            Assert.AreEqual(25, lst[1]);
            Assert.AreEqual(30, lst[2]);
            Assert.AreEqual(35, lst[3]);
            Assert.AreEqual(65, lst[4]);
            Assert.AreEqual(70, lst[5]);
            Assert.AreEqual(75, lst[6]);

            lst.Clear();

            bt.TraversalType = TreeTraversalType.PostOrder;
            foreach (KeyValuePair <int, string> thisOne in bt)
            {
                lst.Add(thisOne.Key);
            }

            Assert.AreEqual(25, lst[0]);
            Assert.AreEqual(30, lst[1]);
            Assert.AreEqual(35, lst[2]);
            Assert.AreEqual(65, lst[3]);
            Assert.AreEqual(70, lst[4]);
            Assert.AreEqual(75, lst[5]);
            Assert.AreEqual(50, lst[6]);

            lst.Clear();

            bt.TraversalType = TreeTraversalType.InOrder;
            foreach (KeyValuePair <int, string> thisOne in bt)
            {
                lst.Add(thisOne.Key);
            }

            Assert.AreEqual(25, lst[0]);
            Assert.AreEqual(30, lst[1]);
            Assert.AreEqual(35, lst[2]);
            Assert.AreEqual(50, lst[3]);
            Assert.AreEqual(65, lst[4]);
            Assert.AreEqual(70, lst[5]);
            Assert.AreEqual(75, lst[6]);

            lst.Clear();

            bt.TraversalType = TreeTraversalType.LevelOrder;
            foreach (KeyValuePair <int, string> thisOne in bt)
            {
                lst.Add(thisOne.Key);
            }

            Assert.AreEqual(50, lst[0]);
            Assert.AreEqual(25, lst[1]);
            Assert.AreEqual(30, lst[2]);
            Assert.AreEqual(35, lst[3]);
            Assert.AreEqual(65, lst[4]);
            Assert.AreEqual(70, lst[5]);
            Assert.AreEqual(75, lst[6]);
        }
Example #8
0
 protected override void InternalAdd(Transaction trans, int id)
 {
     _btreeIndex.Add(trans, id);
 }
Example #9
0
        public static void intTests()
        {
            BTree<int> tree = new BTree<int>();
            for (int i = 10, j = 1;j < 6; i--,j++)
            {
                tree.Add(i);
                tree.Add(j);
            }
            Console.WriteLine(tree.ToString());
            tree.Remove(3);
            Console.WriteLine(tree.ToString());

            BTree<double> b;
            b = new BTree<double>();
            b.Add(123.45);
            b.Add(-45.8);
            b.Add(36.1);
            b.Add(42.9);
            b.Add(234.0);
            b.Remove(36.1);
            foreach (double v in b)
                Console.Write(" {0}", v);
            Console.WriteLine();
        }
Example #10
0
        static void Main(string[] args)
        {
            BTree<float> tree = new BTree<float>();

               tree.Add(5.0f);
               tree.Add(3.1f);
               tree.Add(4.3f);
               tree.Add(1.0f);
               tree.Add(6.8f);
               //tree.Add("zelda");

               BTree<float> tree2 = new BTree<float>();

               tree2.Add(5.6f);
               tree2.Add(7.8f);
               tree2.Add(4.2f);
               tree2.Add(2.3f);

               Console.WriteLine(tree.printTest());

               foreach(float n in tree)
               {
               Console.WriteLine(n.ToString());
               }

               if (tree.Contains(10.3f))
               {
               Console.WriteLine("Contains is working!");
               }

               Console.WriteLine(tree.Count.ToString());

               ///////////////////////////////////////////////////

               float[] strArray = new float[10];
               tree.CopyTo(strArray, 0);
               foreach (float s in strArray)
               {
               Console.WriteLine(s);
               }

               ///////////////////////////////////////////////////

               tree.Remove(10.0f);
               foreach (float n in tree)
               {
               Console.WriteLine(n.ToString());
               }

               ///////////////////////////////////////////////////

               Console.WriteLine(tree.ToString());

               ///////////////////////////////////////////////////

               tree = tree + tree2;
               foreach (float n in tree)
               {
               Console.WriteLine(n.ToString());
               }
               Console.WriteLine(tree.ToString());

               ///////////////////////////////////////////////////

               BTree<float> newTree = tree.Clone();
               Console.WriteLine(newTree.ToString());

               //newTree.Remove("Hockey");

               Console.WriteLine(newTree.ToString());
               Console.WriteLine(tree.ToString());

               Console.Read();
        }
Example #11
0
        private static void CreateAndFillBTree()
        {
            BTree btr = new BTree();

            btr.Add(6);
            btr.Add(2);
            btr.Add(3);
            btr.Add(11);
            btr.Add(30);
            btr.Add(9);
            btr.Add(13);
            btr.Add(18);
            btr.Add(1);
            btr.Add(6);
            btr.Add(7);
            btr.Add(17);
            btr.Print();
            BTreePrinterSimple.Print(btr.Root);
            BTreePrinterPretty.Print(btr.Root);

            //btr.DeleteNode(6);
            btr._root = btr.RotateLeft(btr.Root);
            Console.WriteLine("space!");
            BTreePrinterPretty.Print(btr.Root);
            //btr.DeleteNode(13);
            //BTreePrinterPretty.Print(btr.Root);
            //btr.DeleteNode(11);
            btr._root = btr.RotateRight(btr.Root);
            btr._root = btr.RotateRight(btr.Root);
            BTreePrinterPretty.Print(btr.Root);

            btr.InsertInRoot(5);
            BTreePrinterPretty.Print(btr.Root);
            //BTreePrinterPretty.Print(btr.Root);
            //btr.DeleteNode(2);
            //BTreePrinterPretty.Print(btr.Root);
        }
Example #12
0
        public void Add()
        {
            BTree <int> tree = new BTree <int>(4);

            tree.Add(0);
            tree.Add(2);
            tree.Add(4);
            tree.Add(6);
            tree.Add(8);
            tree.Add(10);
            tree.Add(12);
            tree.Add(-1);
            tree.Add(1);
            tree.Add(10);
            tree.Add(13);
        }
Example #13
0
        public void Remove()
        {
            BTree <int> tree = new BTree <int>(3);

            tree.Add(0);
            tree.Add(2);
            tree.Add(4);
            tree.Add(6);
            tree.Add(8);
            tree.Add(10);
            tree.Add(12);
            tree.Add(-1);
            tree.Add(1);
            tree.Add(10);
            tree.Add(13);

            Assert.IsTrue(tree.Contains(-1));
            tree.Remove(-1);
            Assert.IsFalse(tree.Contains(1));

            Assert.IsTrue(tree.Contains(13));
            tree.Remove(13);
            Assert.IsFalse(tree.Contains(13));

            Assert.IsTrue(tree.Contains(8));
            tree.Remove(8);
            Assert.IsFalse(tree.Contains(8));
        }
Example #14
0
        public void Get()
        {
            BTree <int> tree = new BTree <int>(5);

            tree.Add(0);
            tree.Add(2);
            tree.Add(4);
            tree.Add(6);
            tree.Add(8);
            tree.Add(10);
            tree.Add(12);
            tree.Add(-1);
            tree.Add(1);
            tree.Add(10);
            tree.Add(13);


            Assert.IsTrue(tree.Contains(2));
            Assert.IsFalse(tree.Contains(3));
            Assert.IsTrue(tree.Contains(2));
            Assert.IsFalse(tree.Contains(225));
            Assert.IsTrue(tree.Contains(-1));
            Assert.IsFalse(tree.Contains(9));
            Assert.IsTrue(tree.Contains(13));
        }