def _get_nodes_without_in_edges(graph):
    """Get all nodes in directed graph *graph* that don't have incoming edges.

    The graph is represented by a dict mapping nodes to incoming edges.

    Example:

    >>> graph = {'a': [], 'b': ['a'], 'c': ['a'], 'd': ['b']}
    >>> _get_nodes_without_in_edges(graph)
    ({'a'}, {'b': set(), 'c': set(), 'd': {'b'}})

    :param graph: A dict mapping nodes to incoming edges.
    :return: The set of nodes without incoming edges and the graph with these nodes removed.
    """
    nextlevel = set()
    for node, deps in graph.items():
        if not deps or deps == {node}:
            nextlevel.add(node)
    filtered_graph = {}
    for node, deps in graph.items():
        if node in nextlevel:
            continue
        filtered_graph[node] = \
            {dep for dep in deps if dep not in nextlevel}
    return nextlevel, filtered_graph