-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Implement Fibonacci Heap data structure #9239
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
This commit introduces the Fibonacci Heap data structure along with its relevant 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.
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
self.min_node: FibonacciNode[T] | None = None | ||
self.num_nodes: int = 0 | ||
|
||
def insert(self, key: T) -> 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.
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 insert
self.min_node = new_node | ||
self.num_nodes += 1 | ||
|
||
def _link_nodes(self, min_node: FibonacciNode[T], new_node: FibonacciNode[T]) -> 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.
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 _link_nodes
new_node.prev = min_node | ||
new_node.next.prev = new_node | ||
|
||
def _consolidate(self) -> 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.
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 _consolidate
if self.min_node is None or node.key < self.min_node.key: | ||
self.min_node = node | ||
|
||
def extract_min(self) -> T | 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.
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 extract_min
self.num_nodes -= 1 | ||
return min_node.key if min_node else None | ||
|
||
def _remove_node(self, node: FibonacciNode[T]) -> 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.
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_node
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…otential issues with accessing attributes on None objects.
for more information, see https://pre-commit.ci
…ort statements as they are not supported in newer Python versions.
for more information, see https://pre-commit.ci
Addressed AttributeError and NoneType errors.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
self.children = [] | ||
self.order = 0 | ||
|
||
def add_at_end(self, child_node: 'FibonacciTree') -> 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.
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_at_end
if (self.least is None or k.key < self.least.key): | ||
self.least = k | ||
|
||
def floor_log2(x: int) -> int: |
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 floor_log2
Please provide descriptive name for the parameter: x
for more information, see https://pre-commit.ci
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
self.children: List[FibonacciTree] = [] | ||
self.order = 0 | ||
|
||
def add_at_end(self, child_node: 'FibonacciTree') -> 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.
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_at_end
if (self.least is None or k.key < self.least.key): | ||
self.least = k | ||
|
||
def floor_log2(x: int) -> int: |
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 floor_log2
Please provide descriptive name for the parameter: x
for more information, see https://pre-commit.ci
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
self.children: list['FibonacciTree'] = [] | ||
self.order = 0 | ||
|
||
def add_at_end(self, child_node: 'FibonacciTree') -> 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.
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_at_end
if (self.least is None or k.key < self.least.key): | ||
self.least = k | ||
|
||
def floor_log2(x: int) -> int: |
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 floor_log2
Please provide descriptive name for the parameter: x
for more information, see https://pre-commit.ci
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
self.children: list['FibonacciTree'] = [] | ||
self.order = 0 | ||
|
||
def add_at_end(self, child_node: 'FibonacciTree') -> 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.
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_at_end
if (self.least is None or k.key < self.least.key): | ||
self.least = k | ||
|
||
def floor_log2(x: int) -> int: |
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 floor_log2
Please provide descriptive name for the parameter: x
for more information, see https://pre-commit.ci
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
self.children: list['FibonacciTree'] = [] | ||
self.order = 0 | ||
|
||
def add_at_end(self, child_node: 'FibonacciTree') -> 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.
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_at_end
if (self.least is None or k.key < self.least.key): | ||
self.least = k | ||
|
||
def floor_log2(x: int) -> int: |
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 floor_log2
Please provide descriptive name for the parameter: x
for more information, see https://pre-commit.ci
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
self.children: list['FibonacciTree'] = [] | ||
self.order = 0 | ||
|
||
def add_at_end(self, child_node: 'FibonacciTree') -> 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.
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_at_end
if (self.least is None or k.key < self.least.key): | ||
self.least = k | ||
|
||
def floor_log2(x: int) -> int: |
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 floor_log2
Please provide descriptive name for the parameter: x
for more information, see https://pre-commit.ci
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
self.children: list['FibonacciTree'] = [] | ||
self.order = 0 | ||
|
||
def add_at_end(self, child_node: 'FibonacciTree') -> 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.
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_at_end
self.least=k | ||
continue | ||
|
||
def floor_log2(x: int) -> int: |
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 floor_log2
Please provide descriptive name for the parameter: x
for more information, see https://pre-commit.ci
mypy.....................................................................Failed
data_structures/heap/fibonacci_heap.py:70: error: Incompatible types in assignment (expression has type "FibonacciTree", variable has type "None") [assignment] |
Closing require_descriptive_names PRs to prepare for Hacktoberfest 2024 |
Fixes: #9095
This commit introduces the Fibonacci Heap data structure along with its relevant methods.
Describe your change:
"Implemented Fibonacci Heap data structure
Checklist: