mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
bugfix: Graph.is_dag must explore every vertex
This commit is contained in:
parent
246f2949ea
commit
14ca51db92
1 changed files with 1 additions and 2 deletions
3
graph.ml
3
graph.ml
|
|
@ -213,14 +213,13 @@ let dfs graph first k =
|
||||||
(** Is the graph acyclic? *)
|
(** Is the graph acyclic? *)
|
||||||
let is_dag g =
|
let is_dag g =
|
||||||
if is_empty g then true
|
if is_empty g then true
|
||||||
else if Sequence.is_empty (roots g) then false (* DAGs have roots *)
|
|
||||||
else try
|
else try
|
||||||
let labels = mk_v_table g in
|
let labels = mk_v_table g in
|
||||||
(* do a DFS from each root; any back edge indicates a cycle *)
|
(* do a DFS from each root; any back edge indicates a cycle *)
|
||||||
Sequence.iter
|
Sequence.iter
|
||||||
(fun v ->
|
(fun v ->
|
||||||
dfs_full g ~labels ~back_edge:(fun _ -> raise Exit) v)
|
dfs_full g ~labels ~back_edge:(fun _ -> raise Exit) v)
|
||||||
(roots g);
|
(vertices g);
|
||||||
true (* complete traversal without back edge *)
|
true (* complete traversal without back edge *)
|
||||||
with Exit ->
|
with Exit ->
|
||||||
false (* back edge detected! *)
|
false (* back edge detected! *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue