예제 #1
0
        public void CanReadWriteProtoBufToFile()
        {
            var obj = new MyObj
            {
                PropA = 8,
                PropB = "some value"
            };

            obj.ToProtoBufFile("test.bin");

            var newObj = "test.bin".FromProtoBufFile<MyObj>();

            Assert.Equal(obj.PropA, newObj.PropA);
            Assert.Equal(obj.PropB, newObj.PropB);
        }
예제 #2
0
        public void CanSerializeAndDeserializeObjWithOrderAttributes()
        {
            var obj = new MyObj
            {
                PropA = 8,
                PropB = "some value"
            };

            var bytes = obj.ToProtoBufByteArray();

            Assert.NotNull(bytes);

            var newObj = bytes.FromProtoBufByteArray<MyObj>();

            Assert.Equal(obj.PropA, newObj.PropA);
            Assert.Equal(obj.PropB, newObj.PropB);
        }
예제 #3
0
        static public void Main()
        {
            // create MyObjs containing key and string data
            MyObj obj1  = new MyObj("MyObj 1");
            MyObj obj2  = new MyObj("MyObj 2");
            MyObj obj3  = new MyObj("MyObj 3");
            MyObj obj4  = new MyObj("MyObj 4");
            MyObj obj5  = new MyObj("MyObj 5");
            MyObj obj6  = new MyObj("MyObj 6");
            MyObj obj7  = new MyObj("MyObj 7");
            MyObj obj8  = new MyObj("MyObj 8");
            MyObj obj9  = new MyObj("MyObj 9");
            MyObj obj10 = new MyObj("MyObj 10");
            MyObj obj11 = new MyObj("MyObj 11");
            MyObj obj12 = new MyObj("MyObj 12");
            MyObj obj13 = new MyObj("MyObj 13");

            try
            {
                // format: Add(key, value)
                RedBlackTree.Add(obj1.Data, obj1);
                RedBlackTree.Add(obj2.Data, obj2);
                RedBlackTree.Add(obj3.Data, obj3);
                RedBlackTree.Add(obj4.Data, obj4);
                RedBlackTree.Add(obj5.Data, obj5);
                RedBlackTree.Add(obj6.Data, obj6);
                RedBlackTree.Add(obj7.Data, obj7);
                RedBlackTree.Add(obj8.Data, obj8);
                RedBlackTree.Add(obj9.Data, obj9);
                RedBlackTree.Add(obj10.Data, obj10);
                RedBlackTree.Add(obj11.Data, obj11);
                RedBlackTree.Add(obj12.Data, obj12);
                RedBlackTree.Add(obj13.Data, obj13);

                Console.WriteLine(Environment.NewLine);

                IEnumerator <MyObj> items = RedBlackTree.GetEnumerator();

                Enumerate(items);

                Console.WriteLine(Environment.NewLine);

                DumpMinMaxValue();
                Console.WriteLine(Environment.NewLine);

                string tObjKey = RedBlackTree.GetMinKey();
                MyObj  tObj    = RedBlackTree.GetData(tObjKey);
                Console.WriteLine(@"Remove Min Key: " + tObj.Data);
                Console.WriteLine(Environment.NewLine);
                RedBlackTree.Remove(tObjKey);

                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(@"Remove Max Value:" + RedBlackTree.GetMaxValue());
                RedBlackTree.RemoveMax();
                Console.WriteLine(@"Remove Min Value:" + RedBlackTree.GetMinValue());
                RedBlackTree.RemoveMin();
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(@"Remove Min Key:" + RedBlackTree.GetMinKey());
                RedBlackTree.RemoveMin();
                Console.WriteLine(@"Remove Max Key:" + RedBlackTree.GetMaxKey());
                RedBlackTree.RemoveMax();

                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(@"** Clearing Tree **");
                RedBlackTree.Clear();
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(@"Press enter to terminate");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(@"Press enter to terminate");
                Console.ReadLine();
            }
        }
예제 #4
0
        public static void Main()
        {
            // create MyObjs containing key and string data
            MyObj obj1 = new MyObj("MyObj 1");
            MyObj obj2 = new MyObj("MyObj 2");
            MyObj obj3 = new MyObj("MyObj 3");
            MyObj obj4 = new MyObj("MyObj 4");
            MyObj obj5 = new MyObj("MyObj 5");
            MyObj obj6 = new MyObj("MyObj 6");
            MyObj obj7 = new MyObj("MyObj 7");
            MyObj obj8 = new MyObj("MyObj 8");
            MyObj obj9 = new MyObj("MyObj 9");
            MyObj obj10 = new MyObj("MyObj 10");
            MyObj obj11 = new MyObj("MyObj 11");
            MyObj obj12 = new MyObj("MyObj 12");
            MyObj obj13 = new MyObj("MyObj 13");

            try
            {
                // format: Add(key, value)
                RedBlackTree.Add(obj1.Data, obj1);
                RedBlackTree.Add(obj2.Data, obj2);
                RedBlackTree.Add(obj3.Data, obj3);
                RedBlackTree.Add(obj4.Data, obj4);
                RedBlackTree.Add(obj5.Data, obj5);
                RedBlackTree.Add(obj6.Data, obj6);
                RedBlackTree.Add(obj7.Data, obj7);
                RedBlackTree.Add(obj8.Data, obj8);
                RedBlackTree.Add(obj9.Data, obj9);
                RedBlackTree.Add(obj10.Data, obj10);
                RedBlackTree.Add(obj11.Data, obj11);
                RedBlackTree.Add(obj12.Data, obj12);
                RedBlackTree.Add(obj13.Data, obj13);

                Console.WriteLine(Environment.NewLine);

                IEnumerator<MyObj> items = RedBlackTree.GetEnumerator();

                Enumerate(items);

                Console.WriteLine(Environment.NewLine);

                DumpMinMaxValue();
                Console.WriteLine(Environment.NewLine);

                string tObjKey = RedBlackTree.GetMinKey();
                MyObj tObj = RedBlackTree.GetData(tObjKey);
                Console.WriteLine(@"Remove Min Key: " + tObj.Data);
                Console.WriteLine(Environment.NewLine);
                RedBlackTree.Remove(tObjKey);

                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(@"Remove Max Value:" + RedBlackTree.GetMaxValue());
                RedBlackTree.RemoveMax();
                Console.WriteLine(@"Remove Min Value:" + RedBlackTree.GetMinValue());
                RedBlackTree.RemoveMin();
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(@"Remove Min Key:" + RedBlackTree.GetMinKey());
                RedBlackTree.RemoveMin();
                Console.WriteLine(@"Remove Max Key:" + RedBlackTree.GetMaxKey());
                RedBlackTree.RemoveMax();

                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(@"** Clearing Tree **");
                RedBlackTree.Clear();
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(@"Press enter to terminate");
                Console.ReadLine();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(@"Press enter to terminate");
                Console.ReadLine();
            }
        }
예제 #5
0
        public static void Main()
        {
            // create MyObjs containing key and string data
            MyObj obj1 = new MyObj(0003, "MyObj C");
            MyObj obj2 = new MyObj(0001, "MyObj A");
            MyObj obj3 = new MyObj(0002, "MyObj B");
            MyObj obj4 = new MyObj(0004, "MyObj D");
            MyObj obj5 = new MyObj(0005, "MyObj E");

            try
            {
                // format: Add(key, value)
                treap.Add(new MyKey(obj1.Key), obj1);
                Console.WriteLine("Added to Treap, key: " + obj1.ToString());
                treap.Add(new MyKey(obj2.Key), obj2);
                Console.WriteLine("Added to Treap, key: " + obj2.ToString());
                treap.Add(new MyKey(obj3.Key), obj3);
                Console.WriteLine("Added to Treap, key: " + obj3.ToString());
                treap.Add(new MyKey(obj4.Key), obj4);
                Console.WriteLine("Added to Treap, key: " + obj4.ToString());
                treap.Add(new MyKey(obj5.Key), obj5);
                Console.WriteLine("Added to Treap, key: " + obj5.ToString());
                Console.WriteLine(Environment.NewLine);

                DumpTreap(true);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("- Treap Values -");
                TreapEnumerator t = treap.Values();
                while (t.MoveNext())
                    Console.WriteLine(((MyObj)(t.Value)).Data);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("- Treap Keys -");
                TreapEnumerator k = treap.Keys();
                while (k.MoveNext())
                    Console.WriteLine(k.Key);
                Console.WriteLine(Environment.NewLine);

                DumpMinMaxValue();
                Console.WriteLine(Environment.NewLine);

                // test Remove
                MyKey tObjKey   = (MyKey) treap.GetMinKey();
                MyObj tObj      = (MyObj) treap.GetData(tObjKey);
                Console.WriteLine("Remove Min Key: " + tObj.ToString());
                Console.WriteLine(Environment.NewLine);
                treap.Remove(tObjKey);
                DumpTreap(false);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("Remove Max Value:" + treap.GetMaxValue().ToString());
                treap.RemoveMax();
                Console.WriteLine("Remove Min Value:" + treap.GetMinValue().ToString());
                treap.RemoveMin();
                Console.WriteLine(Environment.NewLine);

                DumpTreap(true);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("Remove Min Key:" +((MyKey)(treap.GetMinKey())).ToString());
                treap.RemoveMin();
                Console.WriteLine("Remove Max Key:" +((MyKey)(treap.GetMaxKey())).ToString());
                treap.RemoveMax();

                Console.WriteLine(Environment.NewLine);
                DumpTreap(true);
                Console.WriteLine(Environment.NewLine);

                // add some more and clear the treap
                Console.WriteLine("- Adding MyKeyObjs - ");
                Console.WriteLine(Environment.NewLine);

                MyKeyObj myKeyObj1 = new MyKeyObj(0025, "MyKeyObj W");
                MyKeyObj myKeyObj2 = new MyKeyObj(0023, "MyKeyObj X");
                MyKeyObj myKeyObj3 = new MyKeyObj(0026, "MyKeyObj Y");
                MyKeyObj myKeyObj4 = new MyKeyObj(0024, "MyKeyObj Z");
                treap.Add(myKeyObj1.Key, myKeyObj1);
                Console.WriteLine("Added to Treap, key: " + myKeyObj1.ToString());
                treap.Add(myKeyObj2.Key, myKeyObj2);
                Console.WriteLine("Added to Treap, key: " + myKeyObj2.ToString());
                treap.Add(myKeyObj3.Key, myKeyObj3);
                Console.WriteLine("Added to Treap, key: " + myKeyObj3.ToString());
                treap.Add(myKeyObj4.Key, myKeyObj4);
                Console.WriteLine("Added to Treap, key: " + myKeyObj4.ToString());
                Console.WriteLine(Environment.NewLine);

                TraverseEnumerator();
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("- Clearing Treap -");
                Console.WriteLine(Environment.NewLine);
                treap.Clear();
                DumpTreap(true);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("Press enter to terminate");
                Console.ReadLine();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Press enter to terminate");
                Console.ReadLine();
            }
        }
예제 #6
0
        static public void Main()
        {
            // create MyObjs containing key and string data
            MyObj obj1 = new MyObj(0003, "MyObj C");
            MyObj obj2 = new MyObj(0001, "MyObj A");
            MyObj obj3 = new MyObj(0002, "MyObj B");
            MyObj obj4 = new MyObj(0004, "MyObj D");
            MyObj obj5 = new MyObj(0005, "MyObj E");

            try
            {
                // format: Add(key, value)
                treap.Add(new MyKey(obj1.Key), obj1);
                Console.WriteLine("Added to Treap, key: " + obj1.ToString());
                treap.Add(new MyKey(obj2.Key), obj2);
                Console.WriteLine("Added to Treap, key: " + obj2.ToString());
                treap.Add(new MyKey(obj3.Key), obj3);
                Console.WriteLine("Added to Treap, key: " + obj3.ToString());
                treap.Add(new MyKey(obj4.Key), obj4);
                Console.WriteLine("Added to Treap, key: " + obj4.ToString());
                treap.Add(new MyKey(obj5.Key), obj5);
                Console.WriteLine("Added to Treap, key: " + obj5.ToString());
                Console.WriteLine(Environment.NewLine);

                DumpTreap(true);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("- Treap Values -");
                TreapEnumerator t = treap.Values();
                while (t.MoveNext())
                {
                    Console.WriteLine(((MyObj)(t.Value)).Data);
                }
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("- Treap Keys -");
                TreapEnumerator k = treap.Keys();
                while (k.MoveNext())
                {
                    Console.WriteLine(k.Key);
                }
                Console.WriteLine(Environment.NewLine);

                DumpMinMaxValue();
                Console.WriteLine(Environment.NewLine);

                // test Remove
                MyKey tObjKey = (MyKey)treap.GetMinKey();
                MyObj tObj    = (MyObj)treap.GetData(tObjKey);
                Console.WriteLine("Remove Min Key: " + tObj.ToString());
                Console.WriteLine(Environment.NewLine);
                treap.Remove(tObjKey);
                DumpTreap(false);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("Remove Max Value:" + treap.GetMaxValue().ToString());
                treap.RemoveMax();
                Console.WriteLine("Remove Min Value:" + treap.GetMinValue().ToString());
                treap.RemoveMin();
                Console.WriteLine(Environment.NewLine);

                DumpTreap(true);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("Remove Min Key:" + ((MyKey)(treap.GetMinKey())).ToString());
                treap.RemoveMin();
                Console.WriteLine("Remove Max Key:" + ((MyKey)(treap.GetMaxKey())).ToString());
                treap.RemoveMax();

                Console.WriteLine(Environment.NewLine);
                DumpTreap(true);
                Console.WriteLine(Environment.NewLine);

                // add some more and clear the treap
                Console.WriteLine("- Adding MyKeyObjs - ");
                Console.WriteLine(Environment.NewLine);

                MyKeyObj myKeyObj1 = new MyKeyObj(0025, "MyKeyObj W");
                MyKeyObj myKeyObj2 = new MyKeyObj(0023, "MyKeyObj X");
                MyKeyObj myKeyObj3 = new MyKeyObj(0026, "MyKeyObj Y");
                MyKeyObj myKeyObj4 = new MyKeyObj(0024, "MyKeyObj Z");
                treap.Add(myKeyObj1.Key, myKeyObj1);
                Console.WriteLine("Added to Treap, key: " + myKeyObj1.ToString());
                treap.Add(myKeyObj2.Key, myKeyObj2);
                Console.WriteLine("Added to Treap, key: " + myKeyObj2.ToString());
                treap.Add(myKeyObj3.Key, myKeyObj3);
                Console.WriteLine("Added to Treap, key: " + myKeyObj3.ToString());
                treap.Add(myKeyObj4.Key, myKeyObj4);
                Console.WriteLine("Added to Treap, key: " + myKeyObj4.ToString());
                Console.WriteLine(Environment.NewLine);

                TraverseEnumerator();
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("- Clearing Treap -");
                Console.WriteLine(Environment.NewLine);
                treap.Clear();
                DumpTreap(true);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("Press enter to terminate");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Press enter to terminate");
                Console.ReadLine();
            }
        }