Skip to content

Commit be9ff5b

Browse files
authored
Update skew_heap.py
1 parent fb07e07 commit be9ff5b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

data_structures/heap/skew_heap.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
#!/usr/bin/env python3
2+
13
from __future__ import annotations
24

35
from collections.abc import Iterable, Iterator
4-
from typing import Any, TypeVar
6+
from typing import Any, Protocol, TypeVar, runtime_checkable
7+
8+
@runtime_checkable
9+
class SupportsLessThan(Protocol):
10+
def __lt__(self, other: Any) -> bool: ...
511

6-
T = TypeVar("T")
12+
T = TypeVar("T", bound=SupportsLessThan)
713

814

9-
class SkewNode[T]:
15+
class SkewNode(Generic[T]):
1016
"""
1117
One node of the skew heap. Contains the value and references to
1218
two children.
@@ -85,7 +91,7 @@ def merge(
8591
return result
8692

8793

88-
class SkewHeap[T]:
94+
class SkewHeap(Generic[T]):
8995
"""
9096
A data structure that allows inserting a new value and to pop the smallest
9197
values. Both operations take O(logN) time where N is the size of the
@@ -192,7 +198,6 @@ def pop(self) -> T | None:
192198
)
193199

194200
return result
195-
196201
def top(self) -> T:
197202
"""
198203
Return the smallest value from the heap.

0 commit comments

Comments
 (0)