diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-12-23 14:51:38 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-12-23 14:51:38 +0100 |
commit | d1d28b9349549297f89ade80616eb7b14083e600 (patch) | |
tree | 7736e7d00ce1368cd70ed2a7c0bd6d27d957eb2e /src/Hakyll/Core/DirectedGraph.hs | |
parent | eabc26812d5deb6ef818c20b2ed4c4d07e14feaa (diff) | |
download | hakyll-d1d28b9349549297f89ade80616eb7b14083e600.tar.gz |
Add tests for the directed graph modules
Diffstat (limited to 'src/Hakyll/Core/DirectedGraph.hs')
-rw-r--r-- | src/Hakyll/Core/DirectedGraph.hs | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/src/Hakyll/Core/DirectedGraph.hs b/src/Hakyll/Core/DirectedGraph.hs index 6dc6ae5..b24ce25 100644 --- a/src/Hakyll/Core/DirectedGraph.hs +++ b/src/Hakyll/Core/DirectedGraph.hs @@ -4,6 +4,7 @@ module Hakyll.Core.DirectedGraph ( DirectedGraph , fromList + , nodes , neighbours , reverse , filter @@ -26,6 +27,13 @@ fromList :: Ord a -> DirectedGraph a -- ^ Resulting directed graph fromList = DirectedGraph . M.fromList . map (\(t, d) -> (t, Node t d)) +-- | Get all nodes in the graph +-- +nodes :: Ord a + => DirectedGraph a -- ^ Graph to get the nodes from + -> Set a -- ^ All nodes in the graph +nodes = M.keysSet . unDirectedGraph + -- | Get a set of reachable neighbours from a directed graph -- neighbours :: Ord a @@ -66,22 +74,3 @@ reachableNodes x graph = reachable (neighbours x graph) (S.singleton x) sanitize = S.filter (`S.notMember` visited) neighbours' = S.unions $ map (flip neighbours graph) $ S.toList $ sanitize next - -{- -exampleGraph :: DirectedGraph Int -exampleGraph = fromList - [ makeNode 8 [2, 4, 6] - , makeNode 2 [4, 3] - , makeNode 4 [3] - , makeNode 6 [4] - , makeNode 3 [] - ] - where - makeNode tag deps = (tag, S.fromList deps) - -cyclic :: DirectedGraph Int -cyclic = fromList - [ (1, S.fromList [2]) - , (2, S.fromList [1, 3]) - ] --} |