Skip to content
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

Merged
merged 11 commits into from
Feb 23, 2021
Merged

Adding skiplist #328

merged 11 commits into from
Feb 23, 2021

Conversation

Arvind-raj06
Copy link
Member

@Arvind-raj06 Arvind-raj06 commented Feb 11, 2021

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.

@codecov
Copy link

codecov bot commented Feb 11, 2021

Codecov Report

Merging #328 (5929621) into master (250ed6f) will decrease coverage by 0.006%.
The diff coverage is 100.000%.

@@              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     
Impacted Files Coverage Δ
pydatastructs/linear_data_structures/__init__.py 100.000% <ø> (ø)
pydatastructs/utils/__init__.py 100.000% <ø> (ø)
...datastructs/linear_data_structures/linked_lists.py 99.173% <100.000%> (-0.424%) ⬇️
pydatastructs/utils/misc_util.py 98.830% <100.000%> (+0.064%) ⬆️

Impacted file tree graph

@@ -581,3 +583,133 @@ def extract(self, index):
elif index == 0:
self.tail.next = self.head
return node

class SkipList(object):
Copy link
Member

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?

Copy link
Member Author

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.

Comment on lines 620 to 626
def __repr__(self):
li = self.__str__()
return '->'.join(li[-1])

def __vars__(self):
li = self.__str__()
return ' '.join(map(lambda l: '->'.join(l), li))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these extra functions?

Copy link
Member Author

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):
Copy link
Member

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).

Copy link
Member Author

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

@Arvind-raj06
Copy link
Member Author

@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
https://github.com/codezonediitj/pydatastructs/pull/328/files/b2e084325239a7f9d4ecb69785d82185ae94f1a7#diff-ce49dc37653769c592b712516c715500230e11637657f4039f28e179835d6fa4

Comment on lines 620 to 626
def __repr__(self):
li = self.__str__()
return '->'.join(li[-1])

def __vars__(self):
li = self.__str__()
return ' '.join(map(lambda l: '->'.join(l), li))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this methods.

Copy link
Member Author

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

Copy link
Member Author

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

@Arvind-raj06
Copy link
Member Author

Coverage Done

@czgdp1807 czgdp1807 merged commit bcf9753 into codezonediitj:master Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a Skip List Data Structure
2 participants