def dijkstra_iterator(nodes: list[Node], src_id: int, hf=(lambda x: 0.0)):
    '\n    Internal loop of the Dijkstra algorithm\n    as a step by step iterator\n    hf is an optional heuristic\n    '
    visited_nodes = set()
    h: list[tuple[(float, Node)]] = []
    previous = dict()
    distances = defaultdict((lambda : sys.maxsize))
    distances[src_id] = hf(nodes[src_id])
    ctx: Context = Context(previous=previous, distances=distances, node=None, visited_nodes=visited_nodes)
    heappush(h, (0.0, nodes[src_id]))
    while h:
        (_, node) = heappop(h)
        if (node.id in visited_nodes):
            continue
        dist = distances[node.id]
        for (n, d) in ((nodes[k], v) for (k, v) in node.neighbours.items() if (k not in visited_nodes)):
            new_dist = (dist + d)
            cost = ((new_dist + hf(n)) - hf(node))
            if (cost <= distances[n.id]):
                distances[n.id] = cost
                previous[n.id] = node.id
                heappush(h, (cost, n))
        visited_nodes.add(node.id)
        ctx.node = node
        (yield ctx)
    ctx.node = None
    (yield ctx)
Internal loop of the Dijkstra algorithm
as a step by step iterator
hf is an optional heuristic
def dijkstra_iterator(nodes: list[Node], src_id: int, hf=(lambda x: 0.0)):
    '\n    Internal loop of the Dijkstra algorithm\n    as a step by step iterator\n    hf is an optional heuristic\n    '
    visited_nodes = set()
    h: list[tuple[(float, Node)]] = []
    previous = dict()
    distances = defaultdict((lambda : sys.maxsize))
    distances[src_id] = hf(nodes[src_id])
    ctx: Context = Context(previous=previous, distances=distances, node=None, visited_nodes=visited_nodes)
    heappush(h, (0.0, nodes[src_id]))
    while h:
        (_, node) = heappop(h)
        if (node.id in visited_nodes):
            continue
        dist = distances[node.id]
        for (n, d) in ((nodes[k], v) for (k, v) in node.neighbours.items() if (k not in visited_nodes)):
            new_dist = (dist + d)
            cost = ((new_dist + hf(n)) - hf(node))
            if (cost <= distances[n.id]):
                distances[n.id] = cost
                previous[n.id] = node.id
                heappush(h, (cost, n))
        visited_nodes.add(node.id)
        ctx.node = node
        (yield ctx)
    ctx.node = None
    (yield ctx)