PreviousUpNext

15.4.788  src/lib/graph/singleton.pkg

#  A singleton graph view (i.e. graph with one node.)
#
# -- Allen Leung

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

###           "Alone, alone, all, all alone,
###            Alone on a wide wide sea!"
###
###                       -- Coleridge


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

    api Singleton_Graph_View {
        #
        singleton_view:  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::Node_Id
                           ->
                           odg::Digraph(N,E,G);

    };
end;


###           "He travels fastest who travels alone."
###
###                                -- Kipling  



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

    package   singleton_graph_view
    : (weak)  Singleton_Graph_View                                      # Singleton_Graph_View  is from   src/lib/graph/singleton.pkg
    {
        fun singleton_view (odg::DIGRAPH graph) n
            =
            {   fun unimplemented _
                    =
                    raise exception odg::READ_ONLY;

                fun none _
                    =
                    [];

                fun entries () =  case (graph.in_edges  n)      [] => [];   _ => [n];   esac;
                fun exits ()   =  case (graph.out_edges n)      [] => [];   _ => [n];   esac;

                odg::DIGRAPH
                  { name            => graph.name,
                    graph_info      => graph.graph_info,
                    allot_node_id   => graph.allot_node_id,
                    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 => unimplemented,
                    nodes           => \\ _ =  [(n, graph.node_info n)],
                    edges           => none,
                    order           => \\ _ =  1,
                    size            => \\ _ =  0,
                    capacity        => graph.capacity,
                    out_edges       => none,
                    in_edges        => none,
                    next            => none,
                    prior            => none,
                    has_edge        => \\ _ =  FALSE,
                    has_node        => \\ i =  i == n,
                    node_info       => graph.node_info,
                    entries,
                    exits,
                    entry_edges     => \\ i =  if  (i == n)  graph.in_edges  i;  else  [];  fi,
                    exit_edges      => \\ i =  if  (i == n)  graph.out_edges i;  else  [];  fi,
                    forall_nodes    => \\ f =  f (n, graph.node_info n),
                    forall_edges    => \\ f =  ()
                  };
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext