Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/weakTopological.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,28 @@ let fold_left = List.fold_left

module Make (G : G) = struct

module HT = Hashtbl.Make(G.V)

let recursive_scc g root_g =
(* Straight OCaml implementation of the Section 4.3,
fig. 4 algorithm in Bourdoncle's paper *)
let stack = Stack.create () in
let dfn = Hashtbl.create 1024 in
let dfn = HT.create 1024 in
let num = ref 0 in
let partition = ref [] in

G.iter_vertex (fun v -> Hashtbl.add dfn v 0) g;
G.iter_vertex (fun v -> HT.add dfn v 0) g;

let rec visit vertex partition =
let head = ref 0 in
let loop = ref false in
Stack.push vertex stack;
incr num;
Hashtbl.replace dfn vertex !num;
HT.replace dfn vertex !num;
head := !num;
G.iter_succ
(fun succ ->
let dfn_succ = Hashtbl.find dfn succ in
let dfn_succ = HT.find dfn succ in
let min =
if dfn_succ = 0
then visit succ partition
Expand All @@ -72,13 +74,13 @@ module Make (G : G) = struct
loop := true
end)
g vertex;
if !head = Hashtbl.find dfn vertex
if !head = HT.find dfn vertex
then begin
Hashtbl.replace dfn vertex max_int;
HT.replace dfn vertex max_int;
let element = ref (Stack.pop stack) in
if !loop then begin
while G.V.compare !element vertex <> 0 do
Hashtbl.replace dfn !element 0;
HT.replace dfn !element 0;
element := Stack.pop stack;
done;
partition := component vertex :: !partition;
Expand All @@ -91,7 +93,7 @@ module Make (G : G) = struct
let partition = ref [] in
G.iter_succ
(fun succ ->
if Hashtbl.find dfn succ = 0
if HT.find dfn succ = 0
then ignore (visit succ partition : int))
g vertex;
Component (vertex, !partition)
Expand Down