summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-01-11 19:55:34 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-01-11 19:55:34 +0100
commit607b1d7d6303f59bcd6a45473287a36721652162 (patch)
tree8058df1631e0f0b627ee50d6fd09d28d2a812dfd
parentc6710ac09a5ae0155b83a30497af65be17a44b00 (diff)
downloadhakyll-607b1d7d6303f59bcd6a45473287a36721652162.tar.gz
sanitize function for DirectedGraph
-rw-r--r--src/Hakyll/Core/DirectedGraph.hs15
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