Exemplo n.º 1
0
        public void SortTest()
        {
            int length = list1.Count;

            WriteLine($"Sort  * {length}");

            DisplayTypeName(list1);

            InitializeTime();

            List <long> vs1 = this.list1 as List <long>;

            vs1.Sort();

            TimeMark(0);

            DisplayTypeName(list2);

            InitializeTime();

            LinkedArray <long> vs2 = this.list2 as LinkedArray <long>;

            vs2.Sort();

            TimeMark(1);

            this.IListMatching();

            WriteLine();
        }
Exemplo n.º 2
0
        public void RemoveAtLastTest()
        {
            int length = list1.Count / 2;

            WriteLine($"remove at last method * {length}");

            DisplayTypeName(list1);

            InitializeTime();

            for (int i = length - 1; 0 < i; i--)
            {
                list1.RemoveAt(list1.Count - 1);
            }
            TimeMark(0);


            DisplayTypeName(list2);

            InitializeTime();
            LinkedArray <long> vs = list2 as LinkedArray <long>;

            for (int i = length - 1; 0 < i; i--)
            {
                vs.LastOut(out long dummy);
                //list2.RemoveAt(list2.Count - 1);
            }
            TimeMark(1);

            WriteLine();
        }
Exemplo n.º 3
0
        public void FindAllTest()
        {
            int length = list1.Count;

            WriteLine($"FindAll  * {length}");

            DisplayTypeName(list1);

            InitializeTime();

            List <long> vs1 = this.list1 as List <long>;

            List <long> ret1 = vs1.FindAll(x =>
            {
                String s = x.ToString();

                return(s.IndexOf('1') >= 0);
            });

            TimeMark(0);

            DisplayTypeName(list2);

            InitializeTime();

            LinkedArray <long> vs2 = this.list2 as LinkedArray <long>;

            List <long> ret2 = vs2.FindAll(x =>
            {
                String s = x.ToString();

                return(s.IndexOf('1') >= 0);
            });

            TimeMark(1);

            long f1 = 0;

            ret1.ForEach(x =>
            {
                f1 += x;
            });

            long f2 = 0;

            ret2.ForEach(x =>
            {
                f2 += x;
            });

            if (f1 != f2)
            {
                throw new Exception();
            }

            WriteLine();
        }
Exemplo n.º 4
0
        public void SortedAddTest()
        {
            int length = 1000;

            WriteLine($"SortedAddTest  * {length}");

            DisplayTypeName(list1);

            InitializeTime();

            List <long> vs1 = this.list1 as List <long>;

            long h1 = vs1[vs1.Count / 2];

            for (int i = 0; length > i; i++)
            {
                int idx1 = 0;
                foreach (long l in vs1)
                {
                    int cmp = l > h1 + i ? 1 : 0;

                    if (cmp == 1)
                    {
                        vs1.Insert(idx1, h1 + i);
                        break;
                    }
                    else
                    {
                        idx1++;
                    }
                }
            }

            TimeMark(0);

            DisplayTypeName(list2);

            InitializeTime();

            LinkedArray <long> vs2 = this.list2 as LinkedArray <long>;
            long h2 = vs2[vs2.Count / 2];

            for (int i = 0; length > i; i++)
            {
                vs2.SortedAdd(h2 + i, (x, y) =>
                {
                    return(x > y ? 1 : -1);
                });
            }

            TimeMark(1);

            this.IListMatching();

            WriteLine();
        }
Exemplo n.º 5
0
        public void ExtForEachTest()
        {
            int length = list1.Count;

            WriteLine($"ExtForEachTest  * {length}");

            DisplayTypeName(list1);

            InitializeTime();

            List <long> vs1 = this.list1 as List <long>;

            double d1 = 0;

            vs1.ForEach(x =>
            {
                d1 += x;
            });

            TimeMark(0);

            DisplayTypeName(list2);

            InitializeTime();

            LinkedArray <long> vs2 = this.list2 as LinkedArray <long>;

            double d2 = 0;

            vs2.ForEach(x =>
            {
                d2 += x;
            });
            TimeMark(1);

            if (d1 != d2)
            {
                ;
            }

            WriteLine();
        }
Exemplo n.º 6
0
        public void InsertRangeTest()
        {
            int length = 10;
            int index  = 20000;

            WriteLine($"insert range [index: +={index}] * {length}");

            long[] buf = new long[length];
            for (int i = 0; buf.Length > i; i++)
            {
                buf[i] = i;
            }

            DisplayTypeName(list1);

            InitializeTime();

            List <long> vs1 = this.list1 as List <long>;

            for (int i = 0; length > i; i++)
            {
                vs1.InsertRange(index * i, buf);
            }
            TimeMark(0);

            DisplayTypeName(list2);

            InitializeTime();

            LinkedArray <long> vs2 = this.list2 as LinkedArray <long>;

            for (int i = 0; length > i; i++)
            {
                vs2.InsertRange(index * i, buf);
            }
            TimeMark(1);

            WriteLine();
        }
Exemplo n.º 7
0
        public void AddRangeTest()
        {
            int length = this.testLength / 2000;

            WriteLine($"addrange [index: -] * {length}");

            long[] buf = new long[length];
            for (int i = 0; buf.Length > i; i++)
            {
                buf[i] = i;
            }

            DisplayTypeName(list1);

            InitializeTime();

            List <long> vs1 = this.list1 as List <long>;

            for (int i = 0; length > i; i++)
            {
                vs1.AddRange(buf);
            }
            TimeMark(0);

            DisplayTypeName(list2);

            InitializeTime();

            LinkedArray <long> vs2 = this.list2 as LinkedArray <long>;

            for (int i = 0; length > i; i++)
            {
                vs2.AddRange(buf);
            }
            TimeMark(1);

            WriteLine();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Constractor
 /// </summary>
 /// <param name="prev">prev Node</param>
 /// <param name="next">next Node</param>
 /// <param name="outerInstance">outer Instance</param>
 public Node(Node prev, Node next, LinkedArray <T> outerInstance)
 {
     this.PrevNode      = prev;
     this.NextNode      = next;
     this.outerInstance = outerInstance;
 }