Пример #1
0
        static void Main(string[] args)
        {
            double[] array = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            ST st = new ST(array);
            values(st, "CREATE");

            ST st1 = st.MassUpdate(3, 8, DO.UPDATE, 6);
            values(st1, "UPDATE", 3, 8, 6);

            ST st2 = st1.MassUpdate(2, 9, DO.ADD, 7);
            values(st2, "ADD", 2, 9, 7);

            ST st3 = st2.PointedUpdate(0, DO.ADD, 5);
            values(st3, "ADD", 0, 0, 5);

            ST st4 = st3.MassUpdate(2, 2, DO.ADD, 7);
            values(st4, "ADD", 2, 2, 7);

            values(st, "SHOW");
            values(st1, "SHOW");
            values(st2, "SHOW");
            values(st3, "SHOW");
            values(st4, "SHOW");
        }
Пример #2
0
        public static void values(ST st, string action, int left = 0, int right = 0, int value = 0)
        {
            double value0 = st.Get(0, 10);
            double value1 = st.Get(0, 5);
            double value2 = st.Get(6, 10);
            double value3 = st.Get(4, 9);
            double value4 = st.Get(2, 6);

            StringBuilder sb = new StringBuilder("");
            if (action.CompareTo("CREATE") == 0 || action.CompareTo("SHOW") == 0)
                sb.Append(action);
            else
                sb.AppendFormat("{0} ({1}, {2}) to {3}", action, left, right, value);

            Console.WriteLine(sb.ToString());
            Console.WriteLine("(0, 10) -> {0}\n(0, 5) -> {1}\n(6, 10) -> {2}\n(4, 9) -> {3}\n(2, 6) -> {4}\n",
                                value0, value1, value2, value3, value4);
        }
Пример #3
0
        public void test_pointed_update1()
        {
            ST st = new ST(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            st = st.PointedUpdate(5, DO.UPDATE, 8);

            double value0 = st.Get(0, 10);
            double value1 = st.Get(0, 5);
            double value2 = st.Get(6, 10);
            double value3 = st.Get(4, 9);
            double value4 = st.Get(2, 6);

            Assert.AreEqual(value0, 58);
            Assert.AreEqual(value1, 18);
            Assert.AreEqual(value2, 40);
            Assert.AreEqual(value3, 42);
            Assert.AreEqual(value4, 23);
        }
Пример #4
0
        public void test_pointed_update2()
        {
            ST st = new ST(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            st = st.PointedUpdate(7, DO.ADD, 8);

            double value0 = st.Get(0, 10);
            double value1 = st.Get(0, 5);
            double value2 = st.Get(6, 10);
            double value3 = st.Get(4, 9);
            double value4 = st.Get(2, 6);

            Assert.AreEqual(value0, 63);
            Assert.AreEqual(value1, 15);
            Assert.AreEqual(value2, 48);
            Assert.AreEqual(value3, 47);
            Assert.AreEqual(value4, 20);
        }
Пример #5
0
        public void test_mass_update2()
        {
            ST st = new ST(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            st = st.MassUpdate(0, 10, DO.ADD, 1);

            double value0 = st.Get(0, 10);
            double value1 = st.Get(0, 5);
            double value2 = st.Get(6, 10);
            double value3 = st.Get(4, 9);
            double value4 = st.Get(2, 6);

            Assert.AreEqual(value0, 67);
            Assert.AreEqual(value1, 21);
            Assert.AreEqual(value2, 46);
            Assert.AreEqual(value3, 45);
            Assert.AreEqual(value4, 25);
        }
Пример #6
0
        public void test_mass_update1()
        {
            ST st = new ST(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            st = st.MassUpdate(0, 10, DO.UPDATE, 6);

            double value0 = st.Get(0, 10);
            double value1 = st.Get(0, 5);
            double value2 = st.Get(6, 10);
            double value3 = st.Get(4, 9);
            double value4 = st.Get(2, 6);

            Assert.AreEqual(value0, 72);
            Assert.AreEqual(value1, 36);
            Assert.AreEqual(value2, 36);
            Assert.AreEqual(value3, 36);
            Assert.AreEqual(value4, 30);
        }
Пример #7
0
        public void test_init()
        {
            ST st = new ST(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            double value0 = st.Get(0, 10);
            double value1 = st.Get(0, 5);
            double value2 = st.Get(6, 10);
            double value3 = st.Get(4, 9);
            double value4 = st.Get(2, 6);

            Assert.AreEqual(value0, 55);
            Assert.AreEqual(value1, 15);
            Assert.AreEqual(value2, 40);
            Assert.AreEqual(value3, 39);
            Assert.AreEqual(value4, 20);
        }
Пример #8
0
        public ST PointedUpdate(int position, DO action, double value)
        {
            ST st = new ST();
            st.root = st.Copy(root);
            st.length = length;

            if (action == DO.ADD)
                pointed_update(ref st.root, 0, length - 1, position, ACTION.ADD, value);
            else
                pointed_update(ref st.root, 0, length - 1, position, ACTION.UPDATE, value);

            return st;
        }
Пример #9
0
        public ST MassUpdate(int left, int right, DO action, double value)
        {
            if (left == right)
                return PointedUpdate(left, action, value);
            else
            {
                ST st = new ST();
                st.root = st.Copy(root);
                st.length = length;

                if (action == DO.ADD)
                    mass_update(ref st.root, 0, length - 1, left, right, ACTION.ADD, value);
                else
                    mass_update(ref st.root, 0, length - 1, left, right, ACTION.UPDATE, value);

                return st;
            }
        }