Owl_graphSourceGraph module supports basic operations on DAG.
type definition of a node
``set_name x s`` sets the name string of node ``x`` to ``s``.
``set_parents x parents`` set ``x`` parents to ``parents``.
``set_children x children`` sets ``x`` children to ``children``.
``num_ancestor x`` returns the number of ancestors of ``x``.
``num_descendant x`` returns the number of descendants of ``x``.
``length x`` returns the total number of ancestors and descendants of ``x``.
val node :
?id:int ->
?name:string ->
?prev:'a node array ->
?next:'a node array ->
'a ->
'a node``node ~id ~name ~prev ~next attr`` creates a node with given id and name string. The created node is also connected to parents in ``prev`` and children in ``next``. The ``attr`` will be saved in ``attr`` field.
``connect parents children`` connects a set of parents to a set of children. The created links are the Cartesian product of parents and children. In other words, they are bidirectional links between parents and children.
NOTE: this function does not eliminate any duplicates in the array.
``connect_descendants parents children`` connects parents to their children. This function creates unidirectional links from parents to children. In other words, this function save ``children`` to ``parent.next`` field.
``connect_ancestors parents children`` connects children to their parents. This function creates unidirectional links from children to parents. In other words, this function save ``parents`` to ``child.prev`` field.
``remove_node x`` removes node ``x`` from the graph by disconnecting itself from all its parent nodes and child nodes.
``remove_edge src dst`` removes a link ``src -> dst`` from the graph. Namely, the corresponding entry of ``dst`` in ``src.next`` and ``src`` in ``dst.prev`` will be removed. Note that it does not remove dst -> src if there exists one.
``replace_child x y`` replaces ``x`` with ``y`` in ``x`` parents. Namely, ``x`` parents now make link to ``y`` rather than ``x`` in ``next`` field.
NOTE: The function does NOT make link from ``y`` to ``x`` parents. Namely, the ``prev`` field of ``y`` remains intact.
``replace_parent x y`` replaces ``x`` with ``y`` in ``x`` children. Namely, ``x`` children now make link to ``y`` rather than ``x`` in ``prev`` field.
NOTE: The function does NOT make link from ``y`` to ``x`` children. Namely, the ``next`` field of ``y`` remains intact.
``copy ~dir x`` makes a copy of ``x`` and all its ancestors (if ``dir = Ancestor``) or all its descendants (if ``dir = Descendant``).
Note that this function only makes a copy of the graph structure, ``attr`` fields of the nodes in the new graph share the same memory with those in the original graph.
val iter_ancestors :
?order:order ->
?traversal:traversal ->
('a node -> unit) ->
'a node array ->
unitIterate the ancestors of a given node.
val iter_descendants :
?order:order ->
?traversal:traversal ->
('a node -> unit) ->
'a node array ->
unitIterate the descendants of a given node.
Filter the ancestors of a given node.
Iterate the descendants of a given node.
Fold the ancestors of a given node.
Fold the descendants of a given node.
Iterate all the in-edges of a given node.
Iterate all the out-edges of a given node.
Fold all the in-edges of a given node.
Fold all the out-edges of a given node.
Topological sort of a given graph using a DFS order. Assumes that the graph is acyclic.
Pretty print a given node.