Exemplo n.º 1
0
        public void TwoLevels_Erase()
        {
            var list = new Skiplist();

            list.Add(1);
            list.Add(2);
            list.Add(5);
            list.Add(7);
            //next add should trigger new level
            list.Add(10);
            list.Add(12);

            //add random order
            list.Add(9);
            list.Add(4);
            list.Add(19);
            list.Add(17);

            Assert.True(list.Erase(5));
            Assert.False(list.Search(5));

            Assert.True(list.Erase(1));
            Assert.False(list.Search(1));

            Assert.True(list.Search(10));
        }
Exemplo n.º 2
0
        public void Many_levels()
        {
            var sList = new Skiplist();
            var size  = 32;

            for (int i = 0; i < size; i += 2)
            {
                sList.Add(i);
            }
            for (int i = 1; i < size; i += 2)
            {
                sList.Add(i);
            }

            for (int i = 0; i < size; i++)
            {
                Assert.True(sList.Search(i));
            }

            // removing every 3rd element
            for (int i = 0; i < size; i += 3)
            {
                Assert.True(sList.Erase(i));
            }
            // make sure the remaining elements are there
            for (int i = 0; i < size; i++)
            {
                if (i % 3 == 0)
                {
                    continue;
                }
                Assert.True(sList.Search(i));
            }
        }
Exemplo n.º 3
0
        public void OneLevel()
        {
            var list = new Skiplist();

            list.Add(1);
            list.Add(5);
            list.Add(10);

            Assert.True(list.Search(1));
            Assert.True(list.Search(5));
            Assert.True(list.Search(10));

            Assert.True(list.Erase(5));
            Assert.False(list.Search(5));

            list.Add(4);
            list.Add(4);
            Assert.True(list.Erase(4));
            Assert.True(list.Search(4));
        }
Exemplo n.º 4
0
        public void SkipList_Erases()
        {
            var list = new Skiplist <int>(4, 0.5);

            list.Add(1);
            list.Add(2);
            list.Add(1);
            list.Add(1);
            list.Add(1);
            list.Add(2);
            list.Add(3);

            // not in list
            Assert.False(list.Erase(4));

            Assert.True(list.Erase(1));
            Assert.True(list.Erase(2));
            Assert.True(list.Erase(1));
            Assert.True(list.Erase(1));
            Assert.True(list.Erase(1));
            Assert.True(list.Erase(2));
            Assert.True(list.Erase(3));

            // list should be empty
            Assert.False(list.Erase(1));
            Assert.False(list.Erase(2));
            Assert.False(list.Erase(3));

            // not in list
            Assert.False(list.Erase(4));
        }