-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding skiplist #328
Adding skiplist #328
Conversation
Codecov Report
@@ Coverage Diff @@
## master #328 +/- ##
=============================================
- Coverage 98.557% 98.550% -0.007%
=============================================
Files 25 25
Lines 3119 3243 +124
=============================================
+ Hits 3074 3196 +122
- Misses 45 47 +2
|
@@ -581,3 +583,133 @@ def extract(self, index): | |||
elif index == 0: | |||
self.tail.next = self.head | |||
return node | |||
|
|||
class SkipList(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it doesn't inherit LinkedList
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope skip list having a linkedlist implementation will lead to another class of sorted linked list or sorting the linkedlist each insertion and maintaining the layer will obviously need the help of tree like structure, it's better to implement them in separate node which can act same.
def __repr__(self): | ||
li = self.__str__() | ||
return '->'.join(li[-1]) | ||
|
||
def __vars__(self): | ||
li = self.__str__() | ||
return ' '.join(map(lambda l: '->'.join(l), li)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these extra functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vars is dynamic if the user want to print the whole skiplist with each layer it can do so.
self.head = SkipNode(-math.inf, self.tail, self.head) | ||
|
||
|
||
def _growUp(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write as _grow_up
(snake case).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep will make the changes
@czgdp1807 can you pls take a look in that area for coverage I have added the test for the vars method too but I'm getting it as missed |
def __repr__(self): | ||
li = self.__str__() | ||
return '->'.join(li[-1]) | ||
|
||
def __vars__(self): | ||
li = self.__str__() | ||
return ' '.join(map(lambda l: '->'.join(l), li)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it would be tough to visualize what has been added and removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall I leave the repr
and remove only the vars
method
Coverage Done |
Adding SkipList
References to other Issues or PRs or Relevant literature
"Fixes #149". See
#149
Brief description of what is fixed or changed
The skiplist data structure is added in the linear data structure and the number of layer is dynamic based on the probability.
Other comments
This set of code is the best I have ever seen for skiplist, yes this is also counted under SWoC. If you have any queries ping me.