-
-
Notifications
You must be signed in to change notification settings - Fork 49.5k
Added an implementation of fibonacci heap. #12375
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
Conversation
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| True | ||
| """ | ||
|
|
||
| def __init__(self, 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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
| 3 | ||
| """ | ||
|
|
||
| def __init__(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 provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
| self.min_node = None | ||
| self.total_nodes = 0 | ||
|
|
||
| def insert(self, 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.
Please provide return type hint for the function: insert. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
| self.total_nodes += 1 | ||
| return new_node | ||
|
|
||
| def _insert_into_circular_list(self, base_node, node_to_insert): |
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 provide return type hint for the function: _insert_into_circular_list. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: base_node
Please provide type hint for the parameter: node_to_insert
| base_node.right = node_to_insert | ||
| return base_node | ||
|
|
||
| def extract_min(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 provide return type hint for the function: extract_min. If the function does not return a value, please provide the type hint as: def function() -> None:
| child_node.parent = None | ||
| child_node.marked = False | ||
|
|
||
| def _cascading_cut(self, current_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.
Please provide return type hint for the function: _cascading_cut. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: current_node
| self._cut(current_node, parent_node) | ||
| self._cascading_cut(parent_node) | ||
|
|
||
| def delete(self, 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.
Please provide return type hint for the function: delete. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: node
| self.decrease_key(node, float("-inf")) | ||
| self.extract_min() | ||
|
|
||
| def find_min(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 provide return type hint for the function: find_min. If the function does not return a value, please provide the type hint as: def function() -> None:
| """ | ||
| return self.min_node.key if self.min_node else None | ||
|
|
||
| def is_empty(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 provide return type hint for the function: is_empty. If the function does not return a value, please provide the type hint as: def function() -> None:
| """ | ||
| return self.min_node is None | ||
|
|
||
| def merge(self, other_heap): |
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 provide return type hint for the function: merge. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: other_heap
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| True | ||
| """ | ||
|
|
||
| def __init__(self, key) -> None: |
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 provide type hint for the parameter: key
| self.min_node = Node(None) | ||
| self.total_nodes = 0 | ||
|
|
||
| def insert(self, key) -> 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.
Please provide type hint for the parameter: key
| self.total_nodes += 1 | ||
| return new_node | ||
|
|
||
| def _insert_into_circular_list(self, base_node, node_to_insert) -> 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.
Please provide type hint for the parameter: base_node
Please provide type hint for the parameter: node_to_insert
| self.total_nodes -= 1 | ||
| return min_node.key | ||
|
|
||
| def _consolidate(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 provide return type hint for the function: _consolidate. If the function does not return a value, please provide the type hint as: def function() -> None:
| ): | ||
| self.min_node = degree_table[degree] | ||
|
|
||
| def decrease_key(self, node, new_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.
Please provide return type hint for the function: decrease_key. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: node
Please provide type hint for the parameter: new_key
| if node.key < self.min_node.key: | ||
| self.min_node = node | ||
|
|
||
| def _cut(self, child_node, parent_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.
Please provide return type hint for the function: _cut. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: child_node
Please provide type hint for the parameter: parent_node
| child_node.parent = Node(None) | ||
| child_node.marked = False | ||
|
|
||
| def _cascading_cut(self, current_node) -> None: |
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 provide type hint for the parameter: current_node
| self._cut(current_node, parent_node) | ||
| self._cascading_cut(parent_node) | ||
|
|
||
| def delete(self, node) -> None: |
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 provide type hint for the parameter: node
| """ | ||
| return self.min_node.key is None | ||
|
|
||
| def merge(self, other_heap) -> None: |
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 provide type hint for the parameter: other_heap
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| True | ||
| """ | ||
|
|
||
| def __init__(self, key) -> None: |
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 provide type hint for the parameter: key
| self.min_node = Node(None) | ||
| self.total_nodes = 0 | ||
|
|
||
| def insert(self, key) -> 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.
Please provide type hint for the parameter: key
| self.total_nodes += 1 | ||
| return new_node | ||
|
|
||
| def _insert_into_circular_list(self, base_node, node_to_insert) -> 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.
Please provide type hint for the parameter: base_node
Please provide type hint for the parameter: node_to_insert
| self.total_nodes -= 1 | ||
| return min_node.key | ||
|
|
||
| def _consolidate(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 provide return type hint for the function: _consolidate. If the function does not return a value, please provide the type hint as: def function() -> None:
| ): | ||
| self.min_node = degree_table[degree] | ||
|
|
||
| def decrease_key(self, node, new_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.
Please provide return type hint for the function: decrease_key. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: node
Please provide type hint for the parameter: new_key
| if node.key < self.min_node.key: | ||
| self.min_node = node | ||
|
|
||
| def _cut(self, child_node, parent_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.
Please provide return type hint for the function: _cut. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: child_node
Please provide type hint for the parameter: parent_node
| child_node.parent = Node(None) | ||
| child_node.marked = False | ||
|
|
||
| def _cascading_cut(self, current_node) -> None: |
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 provide type hint for the parameter: current_node
| self._cut(current_node, parent_node) | ||
| self._cascading_cut(parent_node) | ||
|
|
||
| def delete(self, node) -> None: |
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 provide type hint for the parameter: node
| """ | ||
| return self.min_node.key is None | ||
|
|
||
| def merge(self, other_heap) -> None: |
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 provide type hint for the parameter: other_heap
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| becoming a child of its current parent) | ||
| """ | ||
|
|
||
| def __init__(self, val): |
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 provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: val
| self.degree = 0 | ||
| self.mark = False | ||
|
|
||
| def add_sibling(self, 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.
As there is no test file in this pull request nor any test function or class in the file data_structures/heap/fibonacci_heap.py, please provide doctest for the function add_sibling
Please provide return type hint for the function: add_sibling. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: node
| self.right.left = node | ||
| self.right = node | ||
|
|
||
| def add_child(self, 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.
As there is no test file in this pull request nor any test function or class in the file data_structures/heap/fibonacci_heap.py, please provide doctest for the function add_child
Please provide return type hint for the function: add_child. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: node
| self.child.add_sibling(node) | ||
| self.degree += 1 | ||
|
|
||
| def remove(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.
As there is no test file in this pull request nor any test function or class in the file data_structures/heap/fibonacci_heap.py, please provide doctest for the function remove
Please provide return type hint for the function: remove. If the function does not return a value, please provide the type hint as: def function() -> None:
| 3 | ||
| """ | ||
|
|
||
| def __init__(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 provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
| if degree_table[degree].val < self.min_node.val: | ||
| self.min_node = degree_table[degree] | ||
|
|
||
| def decrease_key(self, node, new_val): |
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 provide return type hint for the function: decrease_key. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: node
Please provide type hint for the parameter: new_val
| if node.val < self.min_node.val: | ||
| self.min_node = node | ||
|
|
||
| def __cut(self, node, parent): |
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 provide return type hint for the function: __cut. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: node
Please provide type hint for the parameter: parent
| node.mark = False | ||
| self.min_node.add_sibling(node) | ||
|
|
||
| def __cascading_cut(self, 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.
Please provide return type hint for the function: __cascading_cut. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: node
| self.__cut(node, parent) | ||
| self.__cascading_cut(parent) | ||
|
|
||
| def __str__(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 provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
| if not self.min_node: | ||
| return "Empty heap" | ||
|
|
||
| def print_tree(node, level=0): |
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 provide return type hint for the function: print_tree. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: node
Please provide type hint for the parameter: level
for more information, see https://pre-commit.ci
|
Re uploading in new PR |
Describe your change:
Checklist: