class LatentIncrementSort {

    public static Map<Vertex, Set<Vertex>> sort(Collection<? extends Vertex> vertices) {

        Map<Vertex, Set<Vertex>> dependencies = getObservedVertexLatentDependencies(vertices);
        Map<Vertex, Set<Vertex>> dependants = mapDependents(dependencies);
        LinkedHashMap<Vertex, Set<Vertex>> observedVertexOrder = new LinkedHashMap<>();
        List<Vertex<?, ?>> verticesWithFewestDependencies;

        while (!(verticesWithFewestDependencies = getVerticesWithFewestDependencies(dependencies)).isEmpty()) {
            Vertex vertex = verticesWithFewestDependencies.get(0);
            Set<Vertex> vertexDependencies = dependencies.remove(vertex);
            observedVertexOrder.put(vertex, vertexDependencies);

            for (Vertex<?, ?> upstreamVertex : vertexDependencies) {
                removeDependencyFromOtherVertices(upstreamVertex, dependants, dependencies);
            }
        }

        return observedVertexOrder;
    }

    private  LatentIncrementSort();

}