Skip to content

Commit

Permalink
Tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Feb 8, 2024
1 parent fc0722a commit 7f9995e
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/bopkit_topological_sort/src/bopkit_topological_sort.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,14 @@ let sort
=
let nodes_table = Hashtbl.create (module Key) in
let nodes =
let rec aux acc = function
| [] -> acc
| node :: tl ->
let acc =
let key = Node.key node in
if Hashtbl.mem nodes_table key
then acc
else (
let node = { Node_and_key.key; node } in
Hashtbl.set nodes_table ~key ~data:node;
node :: acc)
in
aux acc tl
in
aux [] (List.rev nodes)
List.fold_right nodes ~init:[] ~f:(fun node acc ->
let key = Node.key node in
if Hashtbl.mem nodes_table key
then acc
else (
let node = { Node_and_key.key; node } in
Hashtbl.set nodes_table ~key ~data:node;
node :: acc))
in
let visited = Hash_set.create (module Key) in
let ordered = Queue.create ~capacity:(List.length nodes) () in
Expand Down

0 comments on commit 7f9995e

Please sign in to comment.