SI_InteligentnyWozekWidlowy/util/PriorityQueue.py
Aleksander Szamałek 59676e176a Pathfinder
2022-04-08 00:43:25 +02:00

19 lines
405 B
Python

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]