def update_delta(delta, graph, A, B, u, v, weight):
    """
    Helper to update swap deltas during single pass.

    :param delta:
    :param graph: graph
    :param A: partition A
    :param B: partition B
    :param u:
    :param v:
    :param weight: Edge data key to use as weight. If None, the weights are all set to one.
    :return:
    """
    for _, nbr, d in graph.edges(u, data=True):
        w = d.get(weight, 1)
        if nbr in A:
            delta[nbr] += 2 * w
        if nbr in B:
            delta[nbr] -= 2 * w
    for _, nbr, d in graph.edges(v, data=True):
        w = d.get(weight, 1)
        if nbr in A:
            delta[nbr] -= 2 * w
        if nbr in B:
            delta[nbr] += 2 * w
    return delta