PreviousUpNext

15.4.777  src/lib/graph/mapped-digraph-view.pkg

## mapped-digraph-view.pkg
#
# Provide a view of a graph in which we apply:
#
#   node_fn to all nodes,
#   edge_fn to all edges, and
#   info_fn to graph_info:

# Compiled by:
#     src/lib/graph/graphs.lib


stipulate
    package odg =  oop_digraph;                                         # oop_digraph   is from   src/lib/graph/oop-digraph.pkg
herein

    api Mapped_Digraph_View {
        #
        make_mapped_digraph_view
            :
            (odg::Node(N) -> N')
             -> (odg::Edge(E) -> E')
             -> (G -> G')
             -> odg::Digraph(N,E,G)                                     # Here N,E,G stand stead for the types of client-package-supplied records associated with (respectively) nodes, edges and graphs.
             -> odg::Digraph(N',E',G');
    };
end;


stipulate
    package odg =  oop_digraph;                                         # oop_digraph   is from   src/lib/graph/oop-digraph.pkg
herein

    # This package is used in:
    #
    #     src/lib/compiler/back/low/display/graph-layout.pkg
    #
    package   mapped_digraph_view
    : (weak)  Mapped_Digraph_View                                       # Mapped_Digraph_View           is from   src/lib/graph/mapped-digraph-view.pkg
    {
        # Provide a view of a graph in which we apply:
        #
        #   node_fn to all nodes,
        #   edge_fn to all edges, and
        #   info_fn to graph_info:
        #
        fun make_mapped_digraph_view
                node_fn
                edge_fn
                info_fn
                (odg::DIGRAPH graph)
            =
            {   fun rename_node f (i, n)    =  f (i, node_fn (i, n));
                fun rename_node' (i, n)     =  (i, node_fn (i, n));
                fun rename_edge f (i, j, e) =  f (i, j, edge_fn (i, j, e));
                fun rename_edge' (i, j, e)  =  (i, j, edge_fn (i, j, e));
                fun rename_edges es         =  list::map rename_edge' es;
                fun unimplemented _         =  raise exception odg::UNIMPLEMENTED;

                odg::DIGRAPH
                  {
                    name            =>  graph.name,
                    graph_info      =>  info_fn graph.graph_info,
                    allot_node_id   =>  unimplemented,
                    add_node        =>  unimplemented,
                    add_edge        =>  unimplemented,
                    remove_node     =>  unimplemented,
                    set_in_edges    =>  unimplemented,
                    set_out_edges   =>  unimplemented,
                    set_entries     =>  unimplemented,
                    set_exits       =>  unimplemented,
                    garbage_collect =>  graph.garbage_collect,
                    nodes           =>  {. list::map rename_node' (graph.nodes ()); },
                    edges           =>  {. rename_edges (graph.edges ()); },
                    order           =>  graph.order,
                    size            =>  graph.size,
                    capacity        =>  graph.capacity,
                    out_edges       =>  \\ i = rename_edges (graph.out_edges i),
                    in_edges        =>  \\ i = rename_edges (graph.in_edges i),
                    next            =>  graph.next,
                    prior            =>  graph.prior,
                    has_edge        =>  graph.has_edge,
                    has_node        =>  graph.has_node,
                    node_info       =>  \\ i = node_fn (i, graph.node_info i),
                    entries         =>  graph.entries,
                    exits           =>  graph.exits,
                    entry_edges     =>  \\ i = rename_edges (graph.entry_edges i),
                    exit_edges      =>  \\ i = rename_edges (graph.exit_edges i),
                    forall_nodes    =>  \\ f = graph.forall_nodes (rename_node f),
                    forall_edges    =>  \\ f = graph.forall_edges (rename_edge f)

               #    fold_nodes,
               #    fold_edges

                  };
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext