Topological sort: Difference between revisions

Line 514:
#define NIL list_nil ()
#define :: list_cons
 
(* A shorthand for list reversal. This could also have been written as
a macro, and less verbosely, but a template function usually is
better than a macro. *)
fn {a : t@ype}
rev {n : int}
(lst : list (INV(a), n))
:<!wrt> list (a, n) =
(* The list_reverse template function returns a linear list. Convert
that result to a "regular" list. *)
list_vt2t (list_reverse<a> lst)
 
(*------------------------------------------------------------------*)
Line 523 ⟶ 534:
typedef _marksvec_t (n : int) = arrayref (_mark_t, n)
 
(* Some type casts that seem not to be implemented in the
prelude. *)
implement g1int2uint<intknd, uint8knd> i = $UN.cast i
implement g1uint2int<uint8knd, intknd> i = $UN.cast i
Line 656 ⟶ 669:
in
if i = n then
@(list_vt2t (reverserev row), i)
else if is_end_of_list text[i] then
@(list_vt2t (reverserev row), succ i)
else
let
Line 694 ⟶ 707:
in
if i = n then
@(list_vt2t (reverserev desc), i)
else if is_end_of_list text[i] then
@(list_vt2t (reverserev desc), succ i)
else
let
Line 754 ⟶ 767:
typedef nodenum (n : int) = [num : nat | num <= n - 1] size_t num
 
(* A collection of directed edges. *)Edges go from the nodenum that is
represented by the array index, to each of the nodenums listed in
the corresponding array entry. *)
typedef edges (n : int) = arrayref (List0 (nodenum n), n)
 
Line 820 ⟶ 835:
in
collect (desc, names, n);
@(list_vt2t (reverserev names), n)
end
 
Line 1,112 ⟶ 1,127:
nodenames_array[i]
 
(* A shorthand. See also the shorthand "rev" for list reversal,
macdef map = list_map<nodenum n><String1>
defined above as a template function instead of a macro. *)
macdef map (lst) =
macdef map =list_vt2t (list_map<nodenum n><String1> ,(lst))
in
case+ topological_sort topo of
| Topo_SUCCESS valid_order => Topo_SUCCESS (map valid_order)
| Topo_CYCLE Topo_SUCCESScycle (list_vt2t=> Topo_CYCLE (map valid_order)cycle)
| Topo_CYCLE cycle =>
Topo_CYCLE (list_vt2t (map cycle))
end
 
Line 1,134 ⟶ 1,150:
let
val last = list_last cycle
val cycl = list_vt2t (reverserev (last :: cycle))
in
println! ("COMPILATION CYCLE: ", cycl : List0 string)
1,448

edits