Пример #1
0
 static void Main()
 {
     SkipList<String, String> sl = new SkipList<String, String>();
     Console.WriteLine("Adding foo as fie.");
     sl.add("foo", "fie");
     Console.WriteLine("Is foo fie?");
     if ("fie".CompareTo(sl.get("foo")) == 0)
         Console.WriteLine("  Yes!");
     else
         Console.WriteLine("  No! :(");
 }
Пример #2
0
        static void Main(string[] args)
        {
            //int? x = null;

            //if (x.HasValue)
            //{
            //    Console.WriteLine(x);
            //}


            //if (x != null)
            //{
            //    Console.WriteLine(x);
            //}

            //Console.WriteLine(x);
            SkipList <int> list = new SkipList <int>();

            list.Add(5);
            list.Add(10);
            list.Add(7);
            list.Add(6);
            list.Add(8);
            list.Add(13);
            list.Add(14);
            list.Add(12);

            list.Remove(7);
            list.Remove(5);
            list.Remove(14);
            list.Remove(12);

            //Node<int> node13 = list.FindPreviousNode(14);
            //Node<int> node7 = list.FindPreviousNode(8);
            //Node<int> node5 = list.FindPreviousNode(5);
            //Node<int> node11 = list.FindPreviousNode(12);
        }
Пример #3
0
        public static void Main(string[] args)
        {
            SkipList <int> skippy = new SkipList <int>();

            for (int i = 0; i <= 25; i++)
            {
                Random randy = new Random(Guid.NewGuid().GetHashCode());
                skippy.AddNode(randy.Next(0, 1001));
            }

            foreach (char c in skippy.ToString())
            {
                if (c != ' ')
                {
                    Console.BackgroundColor = ConsoleColor.Magenta;
                }
                else
                {
                    Console.BackgroundColor = ConsoleColor.DarkYellow;
                }
                Console.Write(c);
                Thread.Sleep(2);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            var random = new Random();

            var list = new SkipList();

            list.Insert(49);
            list.Print();

            for (int i = 0; i < 5; i++)
            {
                var val = random.Next(0, 99);
                Console.WriteLine($"Inserting {val}...");
                list.Insert(val);
                list.Print();
            }

            Console.WriteLine("List contains '8': " + list.Search(8));
            Console.WriteLine("List contains '49': " + list.Search(49));
            list.Delete(49);
            Console.WriteLine("List contains '49': " + list.Search(49));

            list.Print();
        }
Пример #5
0
 protected void Setup()
 {
     sl = new SkipList<String, String>();
     sl2 = new SkipList<String, int>();
 }
Пример #6
0
 public static void Main(string[] args)
 {
     var mySkipList = new SkipList <int>(Enumerable.Range(1, 5).ToList());
 }
Пример #7
0
        static void Main(string[] args)
        {
            /* We will test the skip list with many keys. */
            int n = 50000;

            /* Prepare the keys and the values. Make sure the keys are unique. */
            Console.WriteLine("Preparing {0} random unique numbers...", n);
            int[] uniqueNumbers = new int[n];
            Int32[] keys = new Int32[n];
            object[] values = new object[n];
            Random r = new Random();
            bool unique = true;
            int x = 0;
            for (int i=0; i<n; i++)
            {
                /* Each number we generate has to be unique. So after we generate a new
                 * number, we compare it with all previously generated numbers and if it is
                 * now unique then we regenerate it. */
                do
                {
                    x = r.Next();
                    unique = true;
                    for (int j=0; j<i; j++)
                    {
                        if (uniqueNumbers[j] == x)
                        {
                            unique = false;
                            break;
                        }
                    }
                } while (!unique);
                uniqueNumbers[i] = x;

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0}", x);

                keys[i] = Int32.Parse(sb.ToString());
                values[i] = sb.ToString();

                Console.Write("\r{0}", i);
            }
            Console.WriteLine("\n{0} random numbers generated.", n);

            /* ------------------------------------------------
             * Test and measure execution time for skip list.
             * ------------------------------------------------
             */
            SkipList slist = new SkipList();

            DateTime start = DateTime.Now;

            /* Make insertions. */
            for (int i=0; i<n; i++)
                slist.Insert(keys[i], values[i]);

            /* Make searches. */
            for (int i=0; i<n; i++)
            {
                object obj = slist.Find(keys[i]);
                if (obj == null)
                    throw new Exception("Null value for key ->"+keys[i]+"<-");

                string stringValue = (string)obj;
                if (!stringValue.Equals(values[i]))
                    throw new Exception("Wrong value for key ->"+keys[i]+"<-");
            }

            /* Make removals. */
            for (int i=0; i<n; i++)
                slist.Remove(keys[i]);

            DateTime stop = DateTime.Now;

            Console.WriteLine("SkipList execution time: "+ (stop-start));

            /* ------------------------------------------------
             * Test and measure execution time for standard Hashtable.
             * ------------------------------------------------
             */
            SortedList stdSortedList = new SortedList();

            start = DateTime.Now;

            /* Make insertions. */
            for (int i=0; i<n; i++)
                stdSortedList.Add(keys[i], values[i]);

            /* Make searches. */
            for (int i=0; i<n; i++)
            {
                object obj = stdSortedList[keys[i]];
                if (obj == null)
                    throw new Exception("Null value for key ->"+keys[i]+"<-");

                string stringValue = (string)obj;
                if (!stringValue.Equals(values[i]))
                    throw new Exception("Wrong value for key ->"+keys[i]+"<-");
            }

            /* Make removals. */
            for (int i=0; i<n; i++)
                stdSortedList.Remove(keys[i]);

            stop = DateTime.Now;

            Console.WriteLine("Standard SortedList execution time: "+ (stop-start));
        }