Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 8a8751d

Browse files
committed
Topological sorting
1 parent b4d57fd commit 8a8751d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Data/Graph.purs.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module Data.Graph (
22
Edge(..),
33
Graph(..),
44

5-
scc
5+
scc,
6+
topSort
67
) where
78

89
import Data.Maybe
@@ -79,4 +80,10 @@ popUntil v (w : ws) popped = popUntil v ws (w : popped)
7980

8081
maybeMin :: Index -> Maybe Index -> Maybe Index
8182
maybeMin i Nothing = Just i
82-
maybeMin i (Just j) = Just $ Math.min i j
83+
maybeMin i (Just j) = Just $ Math.min i j
84+
85+
-- |
86+
-- Topological sort
87+
--
88+
topSort :: forall v. (Eq v, Ord v) => Graph v -> [v]
89+
topSort = reverse <<< concatMap id <<< scc

0 commit comments

Comments
 (0)