X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=components%2Fmetadata%2FmetadataDeps.ml;h=f2b1d049644cb72e589e5f86a6a8d4e2c9c74c80;hb=fae6f153d6dad76b6ccfce17a6b3d997db338d2e;hp=c6dcd1e9062e74eb4d2d000edea89f816ae94713;hpb=e0084c5ce13f5a2ab9622adbcaa5b3b41202d17e;p=helm.git diff --git a/components/metadata/metadataDeps.ml b/components/metadata/metadataDeps.ml index c6dcd1e90..f2b1d0496 100644 --- a/components/metadata/metadataDeps.ml +++ b/components/metadata/metadataDeps.ml @@ -91,6 +91,16 @@ let inverse_deps ~dbd uri = do_query (MetadataTypes.obj_tbl ()) @ do_query MetadataTypes.library_obj_tbl +let topological_sort ~dbd uris = + let module OrderedUri = + struct + type t = UriManager.uri + let compare = UriManager.compare + end in + let module Topo = HTopoSort.Make(OrderedUri) in + Topo.topological_sort uris + (fun uri -> fst (List.split (direct_deps ~dbd uri))) + module DepGraph = struct module UriTbl = UriManager.UriHashtbl @@ -98,7 +108,10 @@ struct let fat_value = 20 let fat_increment = fat_value let incomplete_attrs = ["style", "dashed"] - let global_node_attrs = ["fontsize", "9"; "width", ".4"; "height", ".4"] + let global_node_attrs = ["fontsize", "12"; "width", ".4"; "height", ".4"] + + let label_of_uri uri = UriManager.name_of_uri uri + (*let label_of_uri uri = UriManager.string_of_uri uri*) type neighborhood = { adjacency: UriManager.uri list lazy_t; (* all outgoing edges *) @@ -129,7 +142,7 @@ struct (*eprintf "Node '%s' not found.\n" (UriManager.string_of_uri uri);*) assert false in - Pp.header ~graph_attrs:["rankdir", "LR"] ~node_attrs:global_node_attrs fmt; + Pp.header ~graph_type:"strict digraph" ~graph_attrs:["rankdir", "LR"] ~node_attrs:global_node_attrs fmt; let rec aux = function | [] -> () @@ -137,7 +150,7 @@ struct let suri = UriManager.string_of_uri uri in Pp.node suri ~attrs:([ "href", UriManager.string_of_uri uri; - (*"label", UriManager.name_of_uri uri*) + "label", label_of_uri uri ] @ (if is_complete uri then [] else incomplete_attrs)) fmt; let new_nodes = ref [] in @@ -188,25 +201,33 @@ struct adjacency; neighbs.shown <- weight; fst (HExtlib.split_nth weight adjacency), weight - else (* nodes has been expanded at least once *) + else begin (* nodes has been expanded at least once *) let adjacency = Lazy.force neighbs.adjacency in let total_nodes = List.length adjacency in if neighbs.shown < total_nodes then begin (* some more children to show ... *) let shown_before = neighbs.shown in neighbs.shown <- min (neighbs.shown + fat_increment) total_nodes; - let new_shown = shown_before - neighbs.shown in + let new_shown = neighbs.shown - shown_before in (fst (HExtlib.split_nth new_shown (List.rev adjacency))), new_shown end else [], 0 (* all children are already shown *) + end with Not_found -> (*eprintf "uri not found: %s\n%!" (UriManager.string_of_uri uri);*) [], 0 let collapse uri (adjlist, _root, f, _invert) = + try + let neighbs = UriTbl.find adjlist uri in + if Lazy.lazy_is_val neighbs.adjacency then + (* do not collapse already collapsed nodes *) + if Lazy.force neighbs.adjacency <> [] then + (* do not collapse nodes with no outgoing edges *) + UriTbl.replace adjlist uri { adjacency = lazy (f uri); shown = 0 } + with Not_found -> (* do not add a collapsed node if it was not part of the graph *) - if UriTbl.mem adjlist uri then - UriTbl.replace adjlist uri { adjacency = lazy (f uri); shown = 0 } + () let graph_of_fun ?(invert = false) f ~dbd uri = let f ~dbd uri =