Skip to content

Commit bf93372

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

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

data_structures/heap/skew_heap.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def value(self) -> Any:
3939
def merge(
4040
root1: Optional[SkewNode],
4141
root2: Optional[SkewNode],
42-
comp: Callable[[Any, Any], bool]
42+
comp: Callable[[Any, Any], bool],
4343
) -> Optional[SkewNode]:
4444
"""
4545
Merge two nodes together.
@@ -75,6 +75,7 @@ def merge(
7575
result.left = SkewNode.merge(root1, temp, comp)
7676
return result
7777

78+
7879
class SkewHeap:
7980
"""
8081
A data structure that allows inserting a new value and popping the smallest
@@ -101,15 +102,15 @@ class SkewHeap:
101102
def __init__(
102103
self,
103104
data: Iterable[Any] | None = None,
104-
comp: Callable[[Any, Any], bool] = lambda a, b: a < b
105+
comp: Callable[[Any, Any], bool] = lambda a, b: a < b,
105106
) -> None:
106107
"""
107108
Initialize the skew heap with optional data and comparison function
108-
109+
109110
>>> sh = SkewHeap([3, 1, 3, 7])
110111
>>> list(sh)
111112
[1, 3, 3, 7]
112-
113+
113114
# Max-heap example
114115
>>> max_heap = SkewHeap([3, 1, 3, 7], comp=lambda a, b: a > b)
115116
>>> list(max_heap)
@@ -171,11 +172,7 @@ def insert(self, value: Any) -> None:
171172
>>> list(sh)
172173
[1, 3, 3, 7]
173174
"""
174-
self._root = SkewNode.merge(
175-
self._root,
176-
SkewNode(value),
177-
self._comp
178-
)
175+
self._root = SkewNode.merge(self._root, SkewNode(value), self._comp)
179176

180177
def pop(self) -> Any:
181178
"""
@@ -197,11 +194,7 @@ def pop(self) -> Any:
197194
"""
198195
result = self.top()
199196
if self._root:
200-
self._root = SkewNode.merge(
201-
self._root.left,
202-
self._root.right,
203-
self._comp
204-
)
197+
self._root = SkewNode.merge(self._root.left, self._root.right, self._comp)
205198
return result
206199

207200
def top(self) -> Any:

0 commit comments

Comments
 (0)