File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
13from __future__ import annotations
24
35from 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.
You can’t perform that action at this time.
0 commit comments