コード例 #1
0
        public void ListToTree(int[] values)
        {
            ImmutableAVL tree = new ImmutableAVL(values);

            Assert.AreEqual(values.Length, tree.Count());
            Assert.IsTrue(isAVLTreeValid(tree));
        }
コード例 #2
0
        public override Tuple <double, double> RunDeletion(int arraySize, int nbArrays)
        {
            Init(arraySize, nbArrays);
            Stopwatch watch;
            double    elapsedMsMutable   = 0;
            double    elapsedMsImmutable = 0;

            for (int i = 0; i < nbArrays; i++)
            {
                AVL tree = new AVL(arrays[i]);
                tree.Add(0);
                watch = Stopwatch.StartNew();
                tree.Delete(0);
                watch.Stop();
                double ticks        = watch.ElapsedTicks;
                double microseconds = (ticks / Stopwatch.Frequency) * 1000000;
                elapsedMsMutable += microseconds;

                ImmutableAVL immutableAvl = new ImmutableAVL(arrays[i]);
                immutableAvl.Add(0);
                watch = Stopwatch.StartNew();
                immutableAvl.Delete(0);
                watch.Stop();
                ticks               = watch.ElapsedTicks;
                microseconds        = (ticks / Stopwatch.Frequency) * 1000000;
                elapsedMsImmutable += microseconds;
            }
            elapsedMsMutable   /= nbArrays;
            elapsedMsImmutable /= nbArrays;
            return(new Tuple <double, double>(elapsedMsMutable, elapsedMsImmutable));
        }
コード例 #3
0
        public void Peek(int[] values)
        {
            ImmutableAVL tree = new ImmutableAVL(values);
            int          peek = tree.Peek();

            Assert.AreEqual(peek, values.Min());
            Assert.AreEqual(values.Length, tree.Count());
        }
コード例 #4
0
        public void Insert(int[] values)
        {
            ImmutableAVL tree = new ImmutableAVL(values);

            tree.Add(5);
            Assert.AreEqual(values.Length + 1, tree.Count());
            Assert.IsTrue(isAVLTreeValid(tree));
        }
コード例 #5
0
        public void Pop(int[] values)
        {
            ImmutableAVL tree = new ImmutableAVL(values);
            int          pop  = tree.Pop();

            Assert.AreEqual(pop, values.Min());
            Assert.AreEqual(values.Length - 1, tree.Count());
            Assert.IsTrue(isAVLTreeValid(tree));
        }
コード例 #6
0
        private void dichotomyTree(ImmutableAVL tree, int[] array, int start, int end)
        {
            double middle    = (end - start) / 2;
            int    rootIndex = (int)Math.Floor(middle);

            tree.root = tree.Add(array[start + rootIndex]);
            if (end - start > 0)
            {
                if (start + rootIndex - 1 >= 0)
                {
                    dichotomyTree(tree, array, start, start + rootIndex - 1);
                }
                if (start + rootIndex + 1 >= 0 && end >= 0)
                {
                    dichotomyTree(tree, array, start + rootIndex + 1, end);
                }
            }
        }
コード例 #7
0
 private bool isAVLTreeValid(ImmutableAVL tree)
 {
     return(recursiveCheck(tree.Head()));
 }