Topological sort: Difference between revisions
→{{header|ATS}}
m (→{{header|ATS}}) |
|||
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
@(
else if is_end_of_list text[i] then
@(
else
let
Line 694 ⟶ 707:
in
if i = n then
@(
else if is_end_of_list text[i] then
@(
else
let
Line 754 ⟶ 767:
typedef nodenum (n : int) = [num : nat | num <= n - 1] size_t num
(* A collection of directed edges.
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);
@(
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) =
in
case+ topological_sort topo of
| Topo_SUCCESS valid_order => Topo_SUCCESS (map valid_order)
| Topo_CYCLE
end
Line 1,134 ⟶ 1,150:
let
val last = list_last cycle
val cycl =
in
println! ("COMPILATION CYCLE: ", cycl : List0 string)
|