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

Update treap.py #1358

Merged
merged 2 commits into from
Oct 18, 2019
Merged

Update treap.py #1358

merged 2 commits into from
Oct 18, 2019

Conversation

Hocnonsense
Copy link
Contributor

check merge()

check merge()
Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

I think it would be easier to understand these changes if you could create a separate PR that added doctests to the current code. Once we have test in place, we can ensure that these changes do not break things. See CONTRIBUTING.md for details.

def split(root: Node, key: int) -> Tuple[Node, Node]:
"""
We split current tree into 2 trees with key:
We split current tree into 2 trees with key:
Copy link
Member

@cclauss cclauss Oct 18, 2019

Choose a reason for hiding this comment

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

This extra indentation is not recommended by https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings

"""
root.r, r = split(root.r, key)
return (root, r)
if key < root.key:
Copy link
Member

Choose a reason for hiding this comment

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

This indentation after a return statement makes this unreachable code. If you are using TABS for indentation then please stop. If you are using four spaces for indentation then please explain why this change is useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return is deleted...

pre_print(root.l)
print(root.key, end=" ")
pre_print(root.r)
def mid_print(root: Node):
Copy link
Member

Choose a reason for hiding this comment

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

Put two blank lines between functions or better yet, reformat with black.

random() is used. its difficult to write doctests
l->left
r->right
key->value
add __repr__ and __str__ in preorder
@cclauss cclauss merged commit 179284a into TheAlgorithms:master Oct 18, 2019
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Update treap.py

check merge()

* Update treap.py

random() is used. its difficult to write doctests
l->left
r->right
key->value
add __repr__ and __str__ in preorder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants