Commit 9b40b06c authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add InstallPlan.{toGraph,toMap,keys,keysSet}

At least keysSet will be useful shortly. Others are just for good
measure (though there's probably some cases where we could avoid
converting to and from lists if we used toMap or toGraph).
parent ec09376d
......@@ -74,6 +74,8 @@ module Distribution.Compat.Graph (
fromList,
toList,
keys,
-- ** Sets
keysSet,
-- ** Graphs
toGraph,
-- * Node type
......@@ -88,6 +90,7 @@ import Distribution.Compat.Prelude hiding (lookup, null, empty)
import Data.Graph (SCC(..))
import qualified Data.Graph as G
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Array as Array
import Data.Array ((!))
import qualified Data.Tree as Tree
......@@ -382,6 +385,10 @@ toList g = Map.elems (toMap g)
keys :: Graph a -> [Key a]
keys g = Map.keys (toMap g)
-- | /O(V)/. Convert a graph into a set of keys.
keysSet :: Graph a -> Set.Set (Key a)
keysSet g = Map.keysSet (toMap g)
-- | /O(1)/. Convert a graph into a map from keys to nodes.
-- The resulting map @m@ is guaranteed to have the property that
-- @'Prelude.all' (\(k,n) -> k == 'nodeKey' n) ('Data.Map.toList' m)@.
......
......@@ -26,7 +26,11 @@ module Distribution.Client.InstallPlan (
-- * Operations on 'InstallPlan's
new,
toGraph,
toList,
toMap,
keys,
keysSet,
planIndepGoals,
depends,
......@@ -268,10 +272,24 @@ new :: IndependentGoals
-> GenericInstallPlan ipkg srcpkg
new indepGoals index = mkInstallPlan index indepGoals
toGraph :: GenericInstallPlan ipkg srcpkg
-> Graph (GenericPlanPackage ipkg srcpkg)
toGraph = planGraph
toList :: GenericInstallPlan ipkg srcpkg
-> [GenericPlanPackage ipkg srcpkg]
toList = Graph.toList . planGraph
toMap :: GenericInstallPlan ipkg srcpkg
-> Map UnitId (GenericPlanPackage ipkg srcpkg)
toMap = Graph.toMap . planGraph
keys :: GenericInstallPlan ipkg srcpkg -> [UnitId]
keys = Graph.keys . planGraph
keysSet :: GenericInstallPlan ipkg srcpkg -> Set UnitId
keysSet = Graph.keysSet . planGraph
-- | Remove packages from the install plan. This will result in an
-- error if there are remaining packages that depend on any matching
-- package. This is primarily useful for obtaining an install plan for
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment