-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_lib.ml
More file actions
42 lines (32 loc) · 906 Bytes
/
graph_lib.ml
File metadata and controls
42 lines (32 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
open Types
open Printf
type vertex = {
id : string;
mutable i : int;
mutable lowlink : int;
mutable onStack : bool;
spl_decl : decl;}
type edge = {
f : vertex;
t : vertex;}
type graph = {
mutable v : vertex list;
mutable e : edge list;}
let get_v s graph =
List.find (fun x -> x.id = s) graph.v
let get_e_f s graph =
List.find_all (fun x -> x.f.id = s) graph.e;;
let get_e_t s graph =
List.find_all (fun x -> x.t.id = s) graph.e;;
let add_v s d graph =
graph.v <- {id = s; i = -1; lowlink = -1; onStack = false; spl_decl = d}::graph.v;;
let add_e src dest graph =
try
let v_f = get_v src graph in
(try
let v_t = get_v dest graph in
graph.e <- {f = v_f; t = v_t}::graph.e
with
| Not_found -> raise (Invalid_argument (sprintf "In '%s':\nNode '%s' wasn't found." src dest)))
with
| Not_found -> raise (Invalid_argument (sprintf "Function '%s' does not exist." src));;