From 607b1d7d6303f59bcd6a45473287a36721652162 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Tue, 11 Jan 2011 19:55:34 +0100 Subject: sanitize function for DirectedGraph --- src/Hakyll/Core/DirectedGraph.hs | 15 ++++++++++++--- 1 file 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 -- cgit v1.2.3