1 open list
2 open pool
3 open queue
4
5 val traverse
6 [unvisited, visiting, visited, p : perm]
7 exclusive visited =>
8 (
9
10 nodes: pool unvisited,
11
12 roots: list dynamic,
13
14 pre: (consumes node: unvisited | p) -> (| node @ visiting),
15
16
17 post: (consumes node: visiting | p) -> (list dynamic | node @ visited)
18
19 | p
20 )
21 :
22
23 pool visited
24 =
25
26
27 let completed = Pool in
28
29
30 let waiting = queue::create () in
31
32
33
34 let examine (node: dynamic |
35 nodes @ pool unvisited *
36 waiting @ fifo visiting *
37 completed @ pool visited *
38 p
39 ) : () =
40
41 if nodes owns node then begin
42
43 take node from nodes;
44
45 pre node;
46
47 queue::insert (node, waiting)
48 end
49 in
50
51
52 let rec loop (|
53 nodes @ pool unvisited *
54 waiting @ queue::fifo visiting *
55 completed @ pool visited *
56 p
57 ) : () =
58
59 match queue::retrieve waiting with
60 | None ->
61 ()
62 | Some { contents = node } ->
63
64 let successors = post node in
65
66 give node to completed;
67
68 list::iter (successors, examine);
69
70 loop()
71 end
72 in
73
74
75 list::iter (roots, examine);
76 loop();
77
78
79 completed