def _contains_edge(edges_set, vertex1, vertex2):
    """
    Check if the container has an edge between the given vertices.
    The edge can be (vertex1, vertex2) or (vertex2, vertex1).
    """
    return (vertex1, vertex2) in edges_set or (vertex2, vertex1) in edges_set