SI_InteligentnyWozekWidlowy/util/PriorityQueue.py

19 lines
405 B
Python
Raw Normal View History

2022-04-08 00:43:25 +02:00
import heapq
from typing import List, Tuple, TypeVar
T = TypeVar("T")
class PriorityQueue:
def __init__(self):
self.elements: List[Tuple[float, T]] = []
def empty(self) -> bool:
return not self.elements
def put(self, item: T, priority: float):
heapq.heappush(self.elements, (priority, item))
def get(self) -> T:
return heapq.heappop(self.elements)[1]