-
-
Notifications
You must be signed in to change notification settings - Fork 46.5k
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
Update treap.py #1358
Conversation
check merge()
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 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.
data_structures/binary_tree/treap.py
Outdated
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: |
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.
This extra indentation is not recommended by https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings
data_structures/binary_tree/treap.py
Outdated
""" | ||
root.r, r = split(root.r, key) | ||
return (root, r) | ||
if key < root.key: |
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.
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.
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.
return is deleted...
data_structures/binary_tree/treap.py
Outdated
pre_print(root.l) | ||
print(root.key, end=" ") | ||
pre_print(root.r) | ||
def mid_print(root: Node): |
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.
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
* 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
check merge()