Skip to content

Commit 071ce71

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a92936b commit 071ce71

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

data_structures/heap/fibonacci_heap.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Merge: O(1)
1313
"""
1414

15+
1516
class Node:
1617
"""
1718
A node in a Fibonacci heap.
@@ -28,6 +29,7 @@ class Node:
2829
degree: Number of children.
2930
mark: Boolean indicating if node has lost a child.
3031
"""
32+
3133
def __init__(self, val):
3234
self.val = val
3335
self.parent = None
@@ -231,7 +233,7 @@ def __consolidate(self):
231233
232234
This is an internal method that maintains the heap's structure.
233235
"""
234-
max_degree = int(self.size ** 0.5) + 1
236+
max_degree = int(self.size**0.5) + 1
235237
degree_table = [None] * max_degree
236238

237239
# Collect all roots
@@ -271,11 +273,11 @@ def __consolidate(self):
271273
def decrease_key(self, node, new_val):
272274
"""
273275
Decreases the value of a node.
274-
276+
275277
Args:
276278
node: The node whose value should be decreased.
277279
new_val: The new value for the node.
278-
280+
279281
Raises:
280282
ValueError: If new value is greater than current value.
281283
"""
@@ -299,9 +301,9 @@ def __cut(self, node, parent):
299301
Args:
300302
node: Node to be cut.
301303
parent: Parent of the node to be cut.
302-
""""""
304+
""" """
303305
Performs cascading cut operation.
304-
306+
305307
Args:
306308
node: Starting node for cascading cut.
307309
"""
@@ -324,8 +326,7 @@ def __cascading_cut(self, node):
324326
node: Starting node for cascading cut.
325327
"""
326328

327-
parent = node.parent
328-
if parent:
329+
if parent := node.parent:
329330
if not node.mark:
330331
node.mark = True
331332
else:
@@ -359,4 +360,5 @@ def print_tree(node, level=0):
359360

360361
if __name__ == "__main__":
361362
import doctest
363+
362364
doctest.testmod()

0 commit comments

Comments
 (0)