diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-01-11 19:55:34 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-01-11 19:55:34 +0100 |
commit | 607b1d7d6303f59bcd6a45473287a36721652162 (patch) | |
tree | 8058df1631e0f0b627ee50d6fd09d28d2a812dfd /src/Hakyll | |
parent | c6710ac09a5ae0155b83a30497af65be17a44b00 (diff) | |
download | hakyll-607b1d7d6303f59bcd6a45473287a36721652162.tar.gz |
sanitize function for DirectedGraph
Diffstat (limited to 'src/Hakyll')
-rw-r--r-- | src/Hakyll/Core/DirectedGraph.hs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/Hakyll/Core/DirectedGraph.hs b/src/Hakyll/Core/DirectedGraph.hs index bf52277..66905f7 100644 --- a/src/Hakyll/Core/DirectedGraph.hs +++ b/src/Hakyll/Core/DirectedGraph.hs @@ -8,6 +8,7 @@ module Hakyll.Core.DirectedGraph , neighbours , reverse , reachableNodes + , sanitize ) where import Prelude hiding (reverse) @@ -59,9 +60,17 @@ reachableNodes set graph = reachable (setNeighbours set) set where reachable next visited | S.null next = visited - | otherwise = reachable (sanitize neighbours') (next `S.union` visited) + | otherwise = reachable (sanitize' neighbours') (next `S.union` visited) where - sanitize = S.filter (`S.notMember` visited) - neighbours' = setNeighbours (sanitize next) + sanitize' = S.filter (`S.notMember` visited) + neighbours' = setNeighbours (sanitize' next) setNeighbours = S.unions . map (flip neighbours graph) . S.toList + +-- | Remove all dangling pointers, i.e. references to notes that do +-- not actually exist in the graph. +-- +sanitize :: Ord a => DirectedGraph a -> DirectedGraph a +sanitize (DirectedGraph graph) = DirectedGraph $ M.map sanitize' $ graph + where + sanitize' (Node t n) = Node t $ S.filter (`M.member` graph) n |