PreviousUpNext

15.4.767  src/lib/graph/graph-combination.pkg

# This module implements some combinators that joins two graphs
# into a single view.

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



###            "Life is the art of
###             drawing sufficient conclusions
###             from insufficient premises."
###
###                          -- Samuel Butler 1900



stipulate
    package odg =  oop_digraph;                                         # oop_digraph   is from   src/lib/graph/oop-digraph.pkg
    package ugv =  union_graph_view;                                    # union_graph_view      is from   src/lib/graph/uniongraph.pkg
    package rgv =  renamed_graph_view;                                  # renamed_graph_view    is from   src/lib/graph/renamed-graph-view.pkg
#   package rev =  reversed_graph_view;                                 # reversed_graph_view   is from   src/lib/graph/revgraph.pkg
herein

    package graph_combination: (weak)  Graph_Combination                # Graph_Combination     is from   src/lib/graph/graph-combination.api
    {


        # Disjoint union
        #
        fun my_union (a, b)
            =
            ugv::union_view (\\ (x, y) => x; end ) (a, b);


        fun sum (graph_a as odg::DIGRAPH a,
                 graph_b as odg::DIGRAPH b
                )
            =
            my_union (graph_a, rgv::rename_view (a.capacity ()) graph_b);

        fun union []      => raise exception odg::BAD_GRAPH "union";
            union [a]     => a;
            union [a, b]  => my_union (a, b);
            union (a ! b) => my_union (a, union b);
        end;

        fun sums []      => raise exception odg::BAD_GRAPH "sums";
            sums [a]     => a;
            sums [a, b]  => sum (a, b);
            sums (a ! b) => sum (a, sums b);
        end;
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext