from typing import Set


def _possible_edges(n1: Set, n2: Set, directed: bool, self_loops: bool = False):
    """Compute the number of possible edges between two sets."""
    a = n1.intersection(n2)
    e = (len(n1) - len(a)) * (len(n2) - len(a))
    if directed:
        e *= 2
    if self_loops:
        e += len(n1) + len(n2) - len(a)
    return e