Skip to content
Newer
Older
100644 101 lines (79 sloc) 2.48 KB
fccc685 Initial open-source release
MLstate authored Jun 21, 2011
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
19 (**
20 Stable Topologic Sort, based on string indexation.
21 @author Mathieu Barbin
22 *)
23
24 (** {6 Argument} *)
25
26 (** A module for manipulating nodes of your graph *)
27 module type ItemType =
28 sig
29 (** The type of a node of your graph. *)
30 type t
31
32 (**
33 Indexing nodes of your graph.
34 The function [index] should be injective.
35 *)
36 val index : t -> string
37
38 (**
39 Given a node of the graph, return the list of index
40 of the direct parents.
41 *)
42 val depends : t -> string list
43 end
44
45 (** {6 Functor} *)
46
47 (** The module you'll get for proceding to the topologic sort *)
48 module type S =
49 sig
50
51 (**
52 The type of the nodes. This is the same type as
53 defined in the module in argument of [Make].
54 *)
55 type t
56
57 (**
58 raised if one of the [t] is in a cyclic dependency loop.
59 *)
60 exception CyclicDep of t
61
62 (**
63 raised if 2 [t] of the input list of [sort] have
64 the same index.
65 *)
66 exception IndexConflict of t * t
67
68 (**
69 raised by computing the transitive_dependencies, in case
70 the given [t] in not previously in the list given for
71 computing the env
72 *)
73 exception Not_found_index of string
74
75 (**
76 Stable topologic sort.
77 The function return a sorted list wrt a topologic order of elements of [t].
78 The second elt returned is the list of [not_referenced] nodes.
79 For each non referenced node [index] (we have only the index), we give the list
80 of [nodes] which have declared index as a depends.
81 *)
82 val sort : t list -> t list * (string * t list) list
83
84 type env
85 val compute : t list -> env
86
87 (**
88 Like sort, in case you do not want to recompute everything
89 e.g. from a previous env.
90 *)
91 val get_order : env -> t list * (string * t list) list
92
93 (**
94 Not reflexive.
95 *)
96 val transitive_dependencies : env -> t -> t list
97
98 end
99
100 module Make : functor (Elemt : ItemType) -> S with type t = Elemt.t
Something went wrong with that request. Please try again.