Describe the bug
When attempting to add an item to the SkipList, it is not always added. This seems to be caused by the fact that the _getNextLevel() method may return 0, in which case the for loop on line 138 that adds elements to the SkipList is not entered because lvl is 0.
To Reproduce
It is a bit difficult to reproduce, since a SkipList is a probabilistic data structure, so the behaviour will not be the same every time it is used. However, the following should work:
Create a unit test
Create a SkipList in that test
Add a random number to the list and call list.Contains(number)
Assert that this is true because you just added the number
Run that test 1000 times
Expected behavior
I expect that after adding a number to a list of integers, the list will contain that number
Environmnet:
OS: Windows 10
.NET Version: .NET Core v3.1.101
IDE: Visual Studio Enterprise 2019
Additional context
If the Random object in the SkipList is initialized with seed 123, the first call to Add will not insert the element
Describe the bug When attempting to add an item to the SkipList, it is not always added. This seems to be caused by the fact that the _getNextLevel() method may return 0, in which case the for loop on line 138 that adds elements to the SkipList is not entered because lvl is 0.
To Reproduce It is a bit difficult to reproduce, since a SkipList is a probabilistic data structure, so the behaviour will not be the same every time it is used. However, the following should work:
Expected behavior I expect that after adding a number to a list of integers, the list will contain that number
Environmnet:
Additional context If the Random object in the SkipList is initialized with seed 123, the first call to Add will not insert the element