import run_tests from queue import PriorityQueue def a_star( graph: Graph[ T ], start: T ) -> Gen2[ T, int ]: q : PriorityQueue[ tuple[ int, T ] ] = PriorityQueue() q.put( ( 0, start ) ) while not q.empty(): prio, item = q.get() for succ in graph[ item ]: nprio = yield succ q.put( ( nprio, succ ) ) class cor_iter( Generic[ T, S ] ): def __init__( self, cor: Gen2[ T, S ] ) -> None: self.to_send : Optional[ S ] = None self.cor = cor def __iter__( self ) -> cor_iter[ T, S ]: return self def __next__( self ) -> T: if self.to_send is not None: return self.cor.send( self.to_send ) else: return next( self.cor ) def reply( self, v: S ) -> None: self.to_send = v