Exemplo n.º 1
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();

            var pairs = new KeyValuePair<int, string>[5];

            for (var i = 0; i < pairs.Length; i++)
            {
                pairs[i] = new KeyValuePair<int, string>(i, i.ToString());
                skipList.Add(pairs[i]);
            }

            var array = new KeyValuePair<int, string>[50];

            skipList.CopyTo(array, 0);

            var list = new List<KeyValuePair<int, string>>
                           {
                               array[0],
                               array[1],
                               array[2],
                               array[3],
                               array[4],
                               array[5]
                           };

            foreach (var keyValuePair in pairs)
            {
                Assert.IsTrue(list.Contains(keyValuePair));
            }
        }
Exemplo n.º 2
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(new KeyValuePair<int, string>(i, i.ToString()));
            }

            var newSkipList = SerializeUtil.BinarySerializeDeserialize(skipList);

            Assert.AreNotSame(skipList, newSkipList);
            Assert.AreEqual(skipList.Count, newSkipList.Count);

            var sEnumerator = skipList.GetEnumerator();
            var newSkipListEnumerator = newSkipList.GetEnumerator();

            while (sEnumerator.MoveNext())
            {
                Assert.IsTrue(newSkipListEnumerator.MoveNext());

                Assert.AreEqual(sEnumerator.Current.Key, newSkipListEnumerator.Current.Key);
                Assert.AreEqual(sEnumerator.Current.Value, newSkipListEnumerator.Current.Value);
            }

            Assert.IsFalse(newSkipListEnumerator.MoveNext());
        }
Exemplo n.º 3
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();

            var originalList = new List<KeyValuePair<int, string>>();

            for (var i = 0; i < 100; i++)
            {
                originalList.Add(new KeyValuePair<int, string>(i, i.ToString()));
                skipList.Add(originalList[i]);
            }

            var list = new List<KeyValuePair<int, string>>();

            using (var enumerator = skipList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    list.Add(enumerator.Current);
                }
            }

            Assert.AreEqual(list.Count, 100);

            for (var i = 0; i < 100; i++)
            {
                Assert.IsTrue(list.Contains(originalList[i]));
            }
        }
Exemplo n.º 4
0
        public void NonIComparable()
        {
            var skipList = new SkipList<NonComparableTClass, string>();

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(new KeyValuePair<NonComparableTClass, string>(new NonComparableTClass(i), i.ToString()));
            }

            var newSkipList = SerializeUtil.BinarySerializeDeserialize(skipList);

            Assert.AreNotSame(skipList, newSkipList);
            Assert.AreEqual(skipList.Count, newSkipList.Count);

            var sEnumerator = skipList.GetEnumerator();
            var newSkipListEnumerator = newSkipList.GetEnumerator();

            while (sEnumerator.MoveNext())
            {
                Assert.IsTrue(newSkipListEnumerator.MoveNext());

                Assert.AreEqual(sEnumerator.Current.Key.Number, newSkipListEnumerator.Current.Key.Number);
                Assert.AreEqual(sEnumerator.Current.Value, newSkipListEnumerator.Current.Value);
            }

            Assert.IsFalse(newSkipListEnumerator.MoveNext());
        }
Exemplo n.º 5
0
        public void RunTest() {
            var rnd = new Random((int)DateTime.Now.Ticks);
            var tempSL = new SkipList<int>();

            for(int i = 0; i < 512; i++) {
                int adding = rnd.Next(512);
                tempSL.Add(adding);
            }

            for(int i = 0; i < 512; i++) {
                int val = rnd.Next(512);

                switch(rnd.Next(3)) {
                    case 0:
                        tempSL.Add(val);
                        break;
                    case 1:
                        tempSL.Remove(val);
                        break;
                    case 2:
                        tempSL.Contains(val);
                        break;
                }
            }

            Console.WriteLine("SkipList : " + tempSL);
        }
Exemplo n.º 6
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();
            Assert.IsFalse(skipList.IsReadOnly);

            skipList.Add(4, "a");
            Assert.IsFalse(skipList.IsReadOnly);
        }
Exemplo n.º 7
0
		public MemTable(int writeBatchSize, InternalKeyComparator internalKeyComparator, BufferPool bufferPool)
		{
			CreatedAt = DateTime.UtcNow;
			_bufferPool = bufferPool;
			_memoryAccessor = new UnamangedMemoryAccessor(writeBatchSize);

			_internalKeyComparator = internalKeyComparator;
			_table = new SkipList<InternalKey, UnamangedMemoryAccessor.MemoryHandle>(_internalKeyComparator);
		}
Exemplo n.º 8
0
        public void Simple2()
        {
            var skipList = new SkipList<int, string>(Comparer<int>.Default);

            Assert.AreEqual(0, skipList.Count);
            Assert.AreEqual(Comparer<int>.Default, skipList.Comparer);
            Assert.AreEqual(.5, skipList.Probability);
            Assert.AreEqual(16, skipList.MaximumListLevel);
        }
Exemplo n.º 9
0
        private static void Main(string[] args)
        {
            var skipList = new SkipList<int, int>();
            var sortedList = new SortedList<int, int>();

            Mesaure(skipList);
            Mesaure(sortedList);

            Console.ReadKey();
        }
Exemplo n.º 10
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();
            string val;
            Assert.IsFalse(skipList.TryGetValue(5, out val));

            skipList.Add(3, "4");
            Assert.IsFalse(skipList.TryGetValue(5, out val));
            Assert.IsTrue(skipList.TryGetValue(3, out val));
            Assert.AreEqual(val, "4");
        }
Exemplo n.º 11
0
        public void ExceptionDuplicate3()
        {
            var skipList = new SkipList<int, string>();

            for (var i = 0; i < 20; i++)
            {
                skipList.Add(i, i.ToString());
            }

            skipList.Add(19, "19");
        }
Exemplo n.º 12
0
        public void ExcetpionDuplicate4()
        {
            var skipList = new SkipList<int, string>();

            for (var i = 0; i < 20; i++)
            {
                skipList.Add(i, i.ToString());
            }

            skipList.Add(10, "15");
        }
        public void RemoveIsHookedUpToDelete()
        {
            using (ShimsContext.Create())
            {
                int deletedValue = int.MinValue;
                ShimSkipList<int>.AllInstances.DeleteT0 = (skipList, value) => { deletedValue = value; return true; };

                ICollection<int> collection = new SkipList<int>();
                Assert.IsTrue(collection.Remove(50));
                Assert.AreEqual<int>(50, deletedValue);
            }
        }
Exemplo n.º 14
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();
            Assert.AreEqual(skipList.CurrentListLevel, 0);

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(new KeyValuePair<int, string>(i, i.ToString()));
            }

            Assert.Greater(skipList.CurrentListLevel, 0);
        }
        public void AddIsHookedUpToInsert()
        {
            using (ShimsContext.Create())
            {
                int insertedValue = int.MinValue;
                ShimSkipList<int>.AllInstances.InsertT0 = (skipList, value) => { insertedValue = value; };

                ICollection<int> collection = new SkipList<int>();
                collection.Add(50);
                Assert.AreEqual<int>(50, insertedValue);
            }
        }
Exemplo n.º 16
0
        public void CreateSkipListNode()
        {
            using (ShimsContext.Create())
            {
                ShimSkipList<int>.AllInstances.RandomLevel = (sl) => { return 33; };
                SkipList<int> skipList = new SkipList<int>();

                SkipListNode<int> node = skipList.CreateSkipListNode(50);
                Assert.AreEqual(50, node.Value);
                Assert.AreEqual(33, node.Next.Length);
            }
        }
Exemplo n.º 17
0
        public void DoneVisitor()
        {
            var skipList = new SkipList<int, string>();

            for (var i = 0; i < 20; i++)
            {
                skipList.Add(i, i.ToString());
            }

            var completedTrackingVisitor = new CompletedTrackingVisitor<KeyValuePair<int, string>>();

            skipList.AcceptVisitor(completedTrackingVisitor);
        }
Exemplo n.º 18
0
 public static SkipList<int> InsertIntoSkipList(List<int> list)
 {
     var skipList = new SkipList<int>(new RandomWrapper());
       var comparisons = 0;
       foreach (var n in list)
       {
     comparisons += skipList.Insert(n);
       }
       System.Console.Out.WriteLine("SkipList");
       System.Console.Out.WriteLine("Insert");
       System.Console.Out.WriteLine("Comparisons: {0}", comparisons);
       return skipList;
 }
Exemplo n.º 19
0
		public void Empty()
		{
			var skiplist = new SkipList<string>(StringComparer.InvariantCultureIgnoreCase);
			Assert.False(skiplist.Contains("10"));

			var iterator = skiplist.NewIterator();
			Assert.False(iterator.IsValid);
			iterator.SeekToFirst();
			Assert.False(iterator.IsValid);
			iterator.Seek("100");
			Assert.False(iterator.IsValid);
			iterator.SeekToLast();
			Assert.False(iterator.IsValid);
		}
Exemplo n.º 20
0
        public void ExceptionInvalid3()
        {
            var skipList = new SkipList<int, string>();

            var pairs = new KeyValuePair<int, string>[5];

            for (var i = 0; i < pairs.Length; i++)
            {
                pairs[i] = new KeyValuePair<int, string>(i, i.ToString());
                skipList.Add(pairs[i]);
            }

            skipList.CopyTo(null, 0);
        }
Exemplo n.º 21
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(i, i.ToString());
                Assert.IsTrue(skipList.ContainsKey(i));
            }

            for (var i = 100; i < 150; i++)
            {
                Assert.IsFalse(skipList.ContainsKey(i));
            }
        }
Exemplo n.º 22
0
        public void KeyValuePair()
        {
            var skipList = new SkipList<int, string>();

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(i, i.ToString());
            }

            Assert.IsTrue(skipList.Contains(new KeyValuePair<int, string>(5, "5")));
            Assert.IsTrue(skipList.Contains(new KeyValuePair<int, string>(6, "6")));

            Assert.IsFalse(skipList.Contains(new KeyValuePair<int, string>(5, "6")));
            Assert.IsFalse(skipList.Contains(new KeyValuePair<int, string>(100, "100")));
        }
Exemplo n.º 23
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();
            Assert.AreEqual(skipList.Count, 0);

            skipList.Add(4, "a");
            Assert.AreEqual(skipList.Count, 1);

            skipList.Clear();
            Assert.AreEqual(skipList.Count, 0);

            skipList.Add(5, "a");
            skipList.Add(6, "a");
            Assert.AreEqual(skipList.Count, 2);

            skipList.Clear();
            Assert.AreEqual(skipList.Count, 0);
        }
Exemplo n.º 24
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(i, i.ToString());
            }

            var list = new List<string>();
            list.AddRange(skipList.Values);

            Assert.AreEqual(list.Count, 100);

            for (var i = 0; i < 100; i++)
            {
                Assert.IsTrue(list.Contains(i.ToString()));
            }
        }
Exemplo n.º 25
0
 public void IndexWord(string word, int index)
 {
     if (word.Length != _wordLength)
         throw new Exception("Invalid word length");
     for (int i = 0; i < word.Length; i++)
     {
         var dict = _index[i];
         SkipList list;
         if (dict.TryGetValue(word[i], out list))
         {
             list.Add(index);
         }
         else
         {
             list = new SkipList();
             dict.Add(word[i], list);
             list.Add(index);
         }
     }
 }
Exemplo n.º 26
0
     static void Main(string[] args)
     {
         string text = "Clustering and Segmentation. Clustering is a data mining technique that is directed towards the goals of identification and classification. Clustering tries to identify a finite set of categories or clusters to which each data object (tuple) can be mapped. The categories may be disjoint or overlapping and may sometimes be organized into trees. For example, one might form categories of customers into the form of a tree and then map each customer to one or more of the categories. A closely related problem is that of estimating multivariate probability density functions of all variables that could be attributes in a relation or from different relations.";
         var words = text.Split(new char[] { ' ', '\t', '\n' });
         var skipList = new SkipList<wordInfo>();
         var sdict = new SortedDictionary<string, int>();
         int index = 0;
         foreach (var word in words)
         {
             var canon = word.Trim(new char[] { '.', ',', ';', ':', '-' });
             index = text.IndexOf(word, index);
             if (sdict.ContainsKey(word))
             {
                 sdict[word]++;
             }
             else
             {
                 skipList.Add(new wordInfo(){ 
             }
         }
     }
 }
Exemplo n.º 27
0
        public void SkipList_Test()
        {
            var skipList = new SkipList <int>();

            for (int i = 1; i < 100; i++)
            {
                skipList.Insert(i);
            }

            for (int i = 1; i < 100; i++)
            {
                Assert.AreEqual(i, skipList.Find(i));
            }

            Assert.AreEqual(0, skipList.Find(101));


            for (int i = 1; i < 100; i++)
            {
                skipList.Delete(i);
                Assert.AreEqual(0, skipList.Find(i));
            }

            for (int i = 1; i < 50; i++)
            {
                skipList.Insert(i);
            }

            for (int i = 1; i < 50; i++)
            {
                Assert.AreEqual(i, skipList.Find(i));
            }

            for (int i = 1; i < 50; i++)
            {
                skipList.Delete(i);
                Assert.AreEqual(0, skipList.Find(i));
            }
        }
Exemplo n.º 28
0
        [Test] public void Test_Lots_Random()
        {
            SkipList sl = new SkipList();
            Random   r  = new Random();

            int[] nums = new int[4096];

            for (int i = 0; i < 4096; i++)
            {
                nums[i] = r.Next(10000);
                while (sl.Contains(nums[i]))
                {
                    nums[i] = r.Next(10000);
                }
                sl[nums[i]] = i.ToString();
            }
            Assert.AreEqual(4096, sl.Count);
            for (int i = 0; i < 4096; i++)
            {
                Assert.AreEqual(i.ToString(), sl[nums[i]]);
            }
        }
Exemplo n.º 29
0
        public void SortedElementsAfterAdding()
        {
            var list = new SkipList <int>();

            int elementsCount = 100000;

            //Adding every seventh number, then every fifth number,
            //every third and at last all numbers
            for (int i = 7; i > 0; i -= 2)
            {
                int el = 0;
                while (el < elementsCount)
                {
                    if (!list.Contains(el))
                    {
                        list.Add(el);
                    }
                    el += i;
                }
            }

            int  last              = -1;
            int  count             = 0;
            bool elementsAreSorted = true;

            foreach (var item in list)
            {
                if (last > item)
                {
                    elementsAreSorted = false;
                }
                last = item;
                count++;
            }

            Assert.IsTrue(list.Count == elementsCount &&
                          elementsAreSorted &&
                          count == elementsCount);
        }
Exemplo n.º 30
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(i, i.ToString());
            }

            var visitor = new TrackingVisitor<KeyValuePair<int, string>>();

            skipList.AcceptVisitor(visitor);

            Assert.AreEqual(visitor.TrackingList.Count, 100);

            using (var enumerator = skipList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Assert.IsTrue(visitor.TrackingList.Contains(enumerator.Current));
                }
            }
        }
Exemplo n.º 31
0
        public void Simple()
        {
            var skipList = new SkipList <int, string>();

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(i, i.ToString());
            }

            var visitor = new TrackingVisitor <KeyValuePair <int, string> >();

            skipList.AcceptVisitor(visitor);

            Assert.AreEqual(visitor.TrackingList.Count, 100);

            using (var enumerator = skipList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Assert.IsTrue(visitor.TrackingList.Contains(enumerator.Current));
                }
            }
        }
Exemplo n.º 32
0
        public void Reverse()
        {
            var skipList = new SkipList <int, string>();

            var counter = 0;

            for (var i = 499; i >= 0; i--)
            {
                if ((i % 2) == 0)
                {
                    skipList.Add(i, i.ToString());
                }
                else
                {
                    skipList.Add(new KeyValuePair <int, string>(i, i.ToString()));
                }

                counter++;

                Assert.AreEqual(skipList.Count, counter);
                Assert.AreEqual(skipList[i], i.ToString());
            }
        }
Exemplo n.º 33
0
        public void ConstructorComparerExample()
        {
            var ignoreCaseSkipList = new SkipList <string, int>(StringComparer.OrdinalIgnoreCase)
            {
                { "cat", 1 },
                { "dog", 2 },
                { "canary", 3 }
            };

            // "CAT" will be in the SkipList because case is ignored
            Assert.IsTrue(ignoreCaseSkipList.ContainsKey("CAT"));


            var useCaseSkipList = new SkipList <string, int>(StringComparer.Ordinal)
            {
                { "cat", 1 },
                { "dog", 2 },
                { "canary", 3 }
            };

            // "CAT" will not be in the SkipList because case is not ignored
            Assert.IsFalse(useCaseSkipList.ContainsKey("CAT"));
        }
Exemplo n.º 34
0
        public void TestReverseAdd()
        {
            SkipList <int, string> s = new SkipList <int, string>();

            int counter = 0;

            for (int i = 499; i >= 0; i--)
            {
                if ((i % 2) == 0)
                {
                    s.Add(i, i.ToString());
                }
                else
                {
                    s.Add(new KeyValuePair <int, string>(i, i.ToString()));
                }

                counter++;

                Assert.AreEqual(s.Count, counter);
                Assert.AreEqual(s[i], i.ToString());
            }
        }
Exemplo n.º 35
0
        public void NewSkipListInstance()
        {
            // When skip list is initialized
            var skipList = new SkipList();

            // Then it should create the head node
            skipList.Head.Should().NotBeNull();

            // And it should initialize head node with maximum number of levels
            skipList.Head.Levels.Count.Should().Be(SkipList.SkipListMaxLevel);

            // And it should set the back link on the head node to null
            skipList.Head.Backward.Should().BeNull();

            // And it should set the tail node to null
            skipList.Tail.Should().BeNull();

            // And it should set the length to 0
            skipList.Length.Should().Be(0);

            // And it should set the levels to 1
            skipList.Levels.Should().Be(1);
        }
Exemplo n.º 36
0
        public void UpdatingTheOnlyNodeInTheSkipList()
        {
            // Given
            const int    Score    = 1;
            const int    NewScore = 2;
            const string Element  = "one";

            var nodeLevelGeneratorMock = new Mock <ISkipListNodeLevelGenerator>();

            nodeLevelGeneratorMock.Setup(mock => mock.Generate(Moq.It.IsAny <int>()))
            .Returns(1);

            var skipList = new SkipList(nodeLevelGeneratorMock.Object);

            skipList.Insert(Score, Element);

            // When skip list node is updated
            var updatedNode = skipList.Update(Score, Element, NewScore);

            // Then it should successfully update node
            updatedNode.Should().NotBeNull();
            updatedNode.Score.Should().Be(NewScore);
        }
Exemplo n.º 37
0
        public void TestAccept()
        {
            SkipList <int, string> s = new SkipList <int, string>();

            for (int i = 0; i < 100; i++)
            {
                s.Add(i, i.ToString());
            }

            TrackingVisitor <KeyValuePair <int, string> > visitor = new TrackingVisitor <KeyValuePair <int, string> >();

            s.Accept(visitor);

            Assert.AreEqual(visitor.TrackingList.Count, 100);

            using (IEnumerator <KeyValuePair <int, string> > e = s.GetEnumerator())
            {
                while (e.MoveNext())
                {
                    Assert.AreEqual(visitor.TrackingList.Contains(e.Current), true);
                }
            }
        }
Exemplo n.º 38
0
        public void TestRemove()
        {
            SkipList <int, string> s = new SkipList <int, string>();

            for (int i = 0; i < 100; i++)
            {
                s.Add(i, i.ToString());
            }

            for (int i = 0; i < 100; i++)
            {
                if ((i % 2) == 0)
                {
                    Assert.AreEqual(s.Remove(i), true);
                }
                else
                {
                    Assert.AreEqual(s.Remove(new KeyValuePair <int, string>(i, "a")), true);
                }

                Assert.AreEqual(s.Count, 99 - i);
                Assert.AreEqual(s.ContainsKey(i), false);
            }
        }
Exemplo n.º 39
0
        public void RemoveExample()
        {
            var skipList = new SkipList<string, int> {{"cat", 1}, {"dog", 2}, {"canary", 3}};

            // There are three items in the SkipList
            Assert.AreEqual(3, skipList.Count);

            // Let's remove the dog
            var success = skipList.Remove("dog");

            // The dog should be removed
            Assert.IsTrue(success);

            // Now the SkipList contains only two items, and dog isn't 
            // in the SkipList.
            Assert.AreEqual(2, skipList.Count);

            if (skipList.ContainsKey("dog"))
            {
                Debugger.Break();
            }

            Assert.IsFalse(skipList.ContainsKey("dog"));
        }
Exemplo n.º 40
0
        public void InsertingFirstNodeAtLevel1()
        {
            // Given
            const int    Score   = 1;
            const string Element = "one";

            var nodeLevelGeneratorMock = new Mock <ISkipListNodeLevelGenerator>();

            nodeLevelGeneratorMock.Setup(mock => mock.Generate(Moq.It.IsAny <int>()))
            .Returns(1);

            var skipList = new SkipList(nodeLevelGeneratorMock.Object);

            // When a node is inserted at level 1
            var newNode = skipList.Insert(Score, Element);

            // Then it should return the inserted node
            newNode.Should().NotBeNull();
            newNode.Score.Should().Be(Score);
            newNode.Element.Should().Be(Element);
            newNode.Backward.Should().BeNull();
            newNode.Levels.Count.Should().Be(1);

            // And it should make new node the tail node
            skipList.Tail.Should().Be(newNode);

            // And it should link head node at level 1 to new node
            skipList.Head.Levels[0].Forward.Should().Be(newNode);
            skipList.Head.Levels[0].Span.Should().Be(1);

            // And it should update length of the skip list to 1
            skipList.Length.Should().Be(1);

            // And it should update the level count to 1
            skipList.Levels.Should().Be(1);
        }
Exemplo n.º 41
0
        internal void Show(int lengthEntered, SkipList list, bool dontSplit)
        {
            //	We may have the auto-detect of lengthEntered. In which case
            //	look for the last word character as the start
            int le = lengthEntered;

            if (le < 0)
            {
                le = getLengthEntered();
            }

            // We need to make sure we aren't affecting the main list later on.
            // and so we create a new SkipList from the one we're given.
            SkipList      usableList = new SkipList(list.GetList());
            StringBuilder strb       = new StringBuilder();
            int           cop        = 1;

            while (le > (cop - 1))
            {
                strb.Append(NativeScintilla.GetCharAt(NativeScintilla.GetCurrentPos() - cop));
                cop++;
            }
            SkipList srList = usableList.RemoveNonMatchingStartString(strb.ToString());
            String   rList  = getListString(srList);

            NativeScintilla.AutoCShow(le, rList);

            //	Now it may have been that the auto-detect lengthEntered
            //	caused to AutoCShow call to fail becuase no words matched
            //	the letters we autodetected. In this case just show the
            //	list with a 0 lengthEntered to make sure it will show
            if (!IsActive && lengthEntered < 0)
            {
                NativeScintilla.AutoCShow(0, rList);
            }
        }
Exemplo n.º 42
0
        public void Simple()
        {
            var skipList = new SkipList <int, string>();

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(i, i.ToString());
            }

            for (var i = 0; i < 100; i++)
            {
                if ((i % 2) == 0)
                {
                    Assert.IsTrue(skipList.Remove(i));
                }
                else
                {
                    Assert.IsTrue(skipList.Remove(new KeyValuePair <int, string>(i, "a")));
                }

                Assert.AreEqual(skipList.Count, 99 - i);
                Assert.IsFalse(skipList.ContainsKey(i));
            }
        }
Exemplo n.º 43
0
        public void Simple()
        {
            var skipList = new SkipList<int, string>();

            for (var i = 0; i < 100; i++)
            {
                skipList.Add(i, i.ToString());
            }

            for (var i = 0; i < 100; i++)
            {
                if ((i % 2) == 0)
                {
                    Assert.IsTrue(skipList.Remove(i));
                }
                else
                {
                    Assert.IsTrue(skipList.Remove(new KeyValuePair<int, string>(i, "a")));
                }

                Assert.AreEqual(skipList.Count, 99 - i);
                Assert.IsFalse(skipList.ContainsKey(i));
            }
        }
Exemplo n.º 44
0
 public void Simple5()
 {
     var skipList = new SkipList<int, string>(14, 0.7, Comparer<int>.Default);
     Assert.AreEqual(skipList.Count, 0);
     Assert.AreEqual(Comparer<int>.Default, skipList.Comparer);
     Assert.AreEqual(0.7, skipList.Probability);
     Assert.AreEqual(14, skipList.MaximumListLevel);
 }
Exemplo n.º 45
0
        [Test] public void Test_Null_Key()
        {
            SkipList sl = new SkipList();

            sl.Add(null, "one");
        }
Exemplo n.º 46
0
 private void InitEmptyListForTests()
 {
     this.Empty = new SkipList <int>();
 }
Exemplo n.º 47
0
        public void add_lots()
        {
            Random r = new Random(1001);
            int    n = 1000000;

            int[]  keys = new int[n];
            long[] vals = new long[n];
            for (int i = 0; i < n; i++)
            {
                keys[i] = r.Next();
                vals[i] = (long)r.Next();
            }

            long x;
            int  ok    = 0;
            int  clash = 0;
            SkipList <int, long> skippy = new SkipList <int, long>(-1, int.MaxValue, n, 2003);

            Stopwatch sp = new Stopwatch();

            sp.Start();
            for (int i = 0; i < n; i++)
            {
                x = skippy.insert(keys[i], vals[i]);
                if (x != vals[i])
                {
                    clash++;
                }
                else
                {
                    ok++;
                }
            }
            sp.Stop();
            long inserttime = sp.ElapsedMilliseconds;

            long[] times = new long[n];

            int  match    = 0;
            int  mismatch = 0;
            int  missing  = 0;
            bool there    = false;

            for (int i = 0; i < n; i++)
            {
                sp.Reset();
                sp.Start();
                var opt = skippy.search(keys[i]);
                sp.Stop();
                times[i] = sp.ElapsedMilliseconds;
                there    = false;
                foreach (var ox in opt)
                {
                    there = true;
                    if (ox == vals[i])
                    {
                        match++;
                    }
                    else
                    {
                        mismatch++;
                    }
                }
                if (!there)
                {
                    missing++;
                }
            }

            long tot = 0;

            for (int i = 0; i < n; i++)
            {
                tot += times[i];
            }
            double avg = tot / n;

            Assert.AreEqual(clash, mismatch);
            Assert.AreEqual(ok, match);
            Assert.AreEqual(0, missing);
        }
Exemplo n.º 48
0
 public void GivenANewListIsCreated()
 {
     _list = new SkipList <int>();
 }
Exemplo n.º 49
0
        public void Remove_WhenValueNotFound_ShouldReturnFalse()
        {
            var list = new SkipList <int>();

            Assert.False(list.Remove(42));
        }
Exemplo n.º 50
0
        public void ItemNotInList1()
        {
            var skipList = new SkipList <int, string>();

            Assert.IsFalse(skipList.Remove(4));
        }
Exemplo n.º 51
0
        public void ContainsReturnsFalseIfItemDoesNotExist()
        {
            var lib = new SkipList <int, int>();

            Assert.AreEqual(false, lib.Contains(15));
        }
Exemplo n.º 52
0
 protected void Setup()
 {
     sl  = new SkipList <String, String>();
     sl2 = new SkipList <String, int>();
 }
Exemplo n.º 53
0
        private void btnStressTest_Click(object sender, System.EventArgs e)
        {
            // prompt the user to select a place to save the log file
            if (this.saveLogFile.ShowDialog() == DialogResult.OK)
            {
                // the user has opted to save the file, run tests!
                Random   rnd;
                SkipList tempSL;
                int      totalComps = 0;

                if (rndSeed.Text.Length > 0)
                {
                    rnd    = new Random(Convert.ToInt32(rndSeed.Text));
                    tempSL = new SkipList(Convert.ToInt32(rndSeed.Text));
                }
                else
                {
                    rnd    = new Random();
                    tempSL = new SkipList();
                }



                // start by running some inserts
                StreamWriter sw = File.CreateText(saveLogFile.FileName);
                for (int i = 0; i < this.opsNum.Value / 2; i++)
                {
                    int adding = rnd.Next(Convert.ToInt32(opsNum.Value));
                    sw.Write("Adding " + adding.ToString());

                    tempSL.ResetComparisons();
                    tempSL.Add(adding);
                    totalComps += tempSL.Comparisons;
                    sw.WriteLine(" (" + tempSL.Comparisons + " comps, " + tempSL.Count.ToString() + " items, height " + tempSL.Height.ToString() + ")");
                }

                // now, do a mix of inserts/deletes/lookups
                for (int i = 0; i < this.opsNum.Value / 2; i++)
                {
                    int val = rnd.Next(Convert.ToInt32(opsNum.Value));

                    switch (rnd.Next(3))
                    {
                    case 0:                             // insert
                        sw.Write("Adding " + val.ToString());

                        tempSL.ResetComparisons();
                        tempSL.Add(val);
                        sw.WriteLine(" (" + tempSL.Comparisons + " comps, " + tempSL.Count.ToString() + " items, height " + tempSL.Height.ToString() + ")");
                        totalComps += tempSL.Comparisons;
                        break;

                    case 1:                             // delete
                        sw.Write("Removing " + val.ToString());

                        tempSL.ResetComparisons();
                        tempSL.Remove(val);
                        sw.WriteLine(" (" + tempSL.Comparisons + " comps, " + tempSL.Count.ToString() + " items, height " + tempSL.Height.ToString() + ")");
                        totalComps += tempSL.Comparisons;
                        break;

                    case 2:                             // lookup
                        sw.Write("Contains " + val.ToString());

                        tempSL.ResetComparisons();
                        if (tempSL.Contains(val))
                        {
                            sw.Write(" FOUND ");
                        }
                        else
                        {
                            sw.Write(" NOT FOUND ");
                        }

                        sw.WriteLine(" (" + tempSL.Comparisons + " comps, " + tempSL.Count.ToString() + " items, height " + tempSL.Height.ToString() + ")");
                        totalComps += tempSL.Comparisons;
                        break;
                    }
                }

                double avgComps = Convert.ToDouble(totalComps) / Convert.ToDouble(opsNum.Value);

                sw.WriteLine("");
                sw.WriteLine("TOTAL NODES IN SKIPLIST: " + tempSL.Count.ToString());
                sw.WriteLine("HEIGHT OF SKIPLIST: " + tempSL.Height.ToString());
                sw.WriteLine("TOTAL # OF COMPARISONS: " + totalComps.ToString());
                sw.WriteLine("AVERAGE # OF COMPARISONS PER OPERATION: " + avgComps.ToString());

                sw.Close();
                tempSL = null;

                MessageBox.Show("Test Complete... " + totalComps.ToString() +
                                " total comparisons with an average of " + avgComps.ToString() +
                                " comparisons per operation...");
            }
        }
Exemplo n.º 54
0
        public void ExceptionNullVisitor()
        {
            var skipList = new SkipList <int, string>();

            skipList.AcceptVisitor(null);
        }
Exemplo n.º 55
0
 /// <summary>
 /// Shows the autocomplete window
 /// </summary>
 /// <param name="list">Sets the <see cref="List"/> property. </param>
 /// In this overload the lengthEntered is automatically detected by the editor.
 public void Show(IEnumerable <string> list)
 {
     _list = new SkipList(list);
     Show(-1);
 }
Exemplo n.º 56
0
        public void ItemNotInList2()
        {
            var skipList = new SkipList <int, string>();

            Assert.IsFalse(skipList.Remove(new KeyValuePair <int, string>(3, "3")));
        }
Exemplo n.º 57
0
 public override void Init()
 {
     m_Dictionary        = new SkipList <int, int>();
     referenceDictionary = new SkipList <CloneableInt, CloneableInt>();
 }
Exemplo n.º 58
0
        private SkipList <int> CreateSkipList()
        {
            SkipList <int> list = new SkipList <int>();

            SkipList <int> .SkipListNode node1 = new SkipList <int> .SkipListNode()
            {
                item = 1
            };
            SkipList <int> .SkipListNode node2 = new SkipList <int> .SkipListNode()
            {
                item = 2
            };
            SkipList <int> .SkipListNode node3 = new SkipList <int> .SkipListNode()
            {
                item = 3
            };
            SkipList <int> .SkipListNode node4 = new SkipList <int> .SkipListNode()
            {
                item = 4
            };
            SkipList <int> .SkipListNode node5 = new SkipList <int> .SkipListNode()
            {
                item = 5
            };


            list.Head.levels = new SkipList <int> .SkipLevel[] {
                new SkipList <int> .SkipLevel()
                {
                    forward = node1
                },
                new SkipList <int> .SkipLevel()
                {
                    forward = node1
                },
                new SkipList <int> .SkipLevel()
                {
                    forward = node1
                }
            };

            node1.levels = new SkipList <int> .SkipLevel[] {
                new SkipList <int> .SkipLevel()
                {
                    forward = node2
                },
                new SkipList <int> .SkipLevel()
                {
                    forward = node3
                },
                new SkipList <int> .SkipLevel()
                {
                    forward = node5
                }
            };

            node2.levels = new SkipList <int> .SkipLevel[] {
                new SkipList <int> .SkipLevel()
                {
                    forward = node3
                },
            };

            node3.levels = new SkipList <int> .SkipLevel[] {
                new SkipList <int> .SkipLevel()
                {
                    forward = node4
                },
                new SkipList <int> .SkipLevel()
                {
                    forward = node5
                }
            };

            node4.levels = new SkipList <int> .SkipLevel[] {
                new SkipList <int> .SkipLevel()
                {
                    forward = node5
                }
            };

            list.CalculateLevelCount();

            return(list);
        }
Exemplo n.º 59
0
        private static void TestSkipList()
        {
            Console.WriteLine("TestSkipList");

            SkipList<int, string> skipList = new SkipList<int, string>();
            Random rnd = new Random(0);

            Console.WriteLine("Add");
            Stopwatch swAdd = Stopwatch.StartNew();
            for (int i = 0; i < MAX; ++i)
            {
                Console.Write("{0}\r", i);

                int next = rnd.Next();
                skipList.Add(next, next.ToString());
            }
            swAdd.Stop();

            rnd = new Random(0);
            Console.WriteLine("Remove");
            Stopwatch swRemove = Stopwatch.StartNew();
            for (int i = 0; i < MAX; ++i)
            {
                Console.Write("{0}\r", i);

                int next = rnd.Next();
                skipList.Remove(next);
            }
            swRemove.Stop();

            rnd = new Random(0);
            Console.WriteLine("ContainsKey");
            Stopwatch swContainsKey = Stopwatch.StartNew();
            for (int i = 0; i < MAX; ++i)
            {
                Console.Write("{0}\r", i);

                int next = rnd.Next();
                bool res = skipList.ContainsKey(next);
                if (res)
                {
                    Console.WriteLine("Bug");
                }
            }
            swContainsKey.Stop();

            Console.WriteLine("Add = {0}", swAdd.ElapsedMilliseconds);
            Console.WriteLine("Remove = {0}", swRemove.ElapsedMilliseconds);
            Console.WriteLine("ContainsKey = {0}", swContainsKey.ElapsedMilliseconds);

            //skipList.Add(10, "tralala");
            //skipList.Add(20, "tutu");
            //skipList.Add(20, "pouet");
            //Console.WriteLine("Contains 10 = {0}", skipList.ContainsKey(10));
            //Console.WriteLine("Contains 20 = {0}", skipList.ContainsKey(20));
            //Console.WriteLine("Remove 20 = {0}", skipList.Remove(20));
            //Console.WriteLine("Remove 10 = {0}", skipList.Remove(10));
            //Console.WriteLine("Remove 20 = {0}", skipList.Remove(20));
            //Console.WriteLine("Contains 20 = {0}", skipList.ContainsKey(20));
            //Console.WriteLine("Contains 10 = {0}", skipList.ContainsKey(10));
        }
Exemplo n.º 60
0
 /// <summary>
 /// Shows the autocomplete window
 /// </summary>
 /// <param name="lengthEntered">Number of characters of the current word already entered in the editor </param>
 /// <param name="list">Sets the <see cref="List"/> property. </param>
 public void Show(int lengthEntered, IEnumerable <string> list)
 {
     _list = new SkipList(list);
     Show(-1);
 }