{-# LANGUAGE ConstrainedClassMethods #-}
module Algebra.Graph.ToGraph (
ToGraph (..),
adjacencyMap, adjacencyIntMap, adjacencyMapTranspose, adjacencyIntMapTranspose
) where
import Data.IntMap (IntMap)
import Data.IntSet (IntSet)
import Data.Map (Map)
import Data.Set (Set)
import Data.Tree
import qualified Data.IntMap as IntMap
import qualified Data.IntSet as IntSet
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Algebra.Graph as G
import qualified Algebra.Graph.AdjacencyMap as AM
import qualified Algebra.Graph.AdjacencyMap.Algorithm as AM
import qualified Algebra.Graph.NonEmpty.AdjacencyMap as NAM
import qualified Algebra.Graph.AdjacencyIntMap as AIM
import qualified Algebra.Graph.AdjacencyIntMap.Algorithm as AIM
class ToGraph t where
{-# MINIMAL toGraph | foldg #-}
type ToVertex t
toGraph :: t -> G.Graph (ToVertex t)
toGraph = forall t r.
ToGraph t =>
r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg forall a. Graph a
G.Empty forall a. a -> Graph a
G.Vertex forall a. Graph a -> Graph a -> Graph a
G.Overlay forall a. Graph a -> Graph a -> Graph a
G.Connect
foldg :: r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg r
e ToVertex t -> r
v r -> r -> r
o r -> r -> r
c = forall b a.
b -> (a -> b) -> (b -> b -> b) -> (b -> b -> b) -> Graph a -> b
G.foldg r
e ToVertex t -> r
v r -> r -> r
o r -> r -> r
c forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. ToGraph t => t -> Graph (ToVertex t)
toGraph
isEmpty :: t -> Bool
isEmpty = forall t r.
ToGraph t =>
r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg Bool
True (forall a b. a -> b -> a
const Bool
False) Bool -> Bool -> Bool
(&&) Bool -> Bool -> Bool
(&&)
hasVertex :: Eq (ToVertex t) => ToVertex t -> t -> Bool
hasVertex ToVertex t
x = forall t r.
ToGraph t =>
r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg Bool
False (forall a. Eq a => a -> a -> Bool
==ToVertex t
x) Bool -> Bool -> Bool
(||) Bool -> Bool -> Bool
(||)
hasEdge :: Eq (ToVertex t) => ToVertex t -> ToVertex t -> t -> Bool
hasEdge ToVertex t
x ToVertex t
y = forall a. Eq a => a -> a -> Graph a -> Bool
G.hasEdge ToVertex t
x ToVertex t
y forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. ToGraph t => t -> Graph (ToVertex t)
toGraph
vertexCount :: Ord (ToVertex t) => t -> Int
vertexCount = forall a. Set a -> Int
Set.size forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (ToGraph t, Ord (ToVertex t)) => t -> Set (ToVertex t)
vertexSet
edgeCount :: Ord (ToVertex t) => t -> Int
edgeCount = forall a. AdjacencyMap a -> Int
AM.edgeCount forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
vertexList :: Ord (ToVertex t) => t -> [ToVertex t]
vertexList = forall a. Set a -> [a]
Set.toAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (ToGraph t, Ord (ToVertex t)) => t -> Set (ToVertex t)
vertexSet
edgeList :: Ord (ToVertex t) => t -> [(ToVertex t, ToVertex t)]
edgeList = forall a. AdjacencyMap a -> [(a, a)]
AM.edgeList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
vertexSet :: Ord (ToVertex t) => t -> Set (ToVertex t)
vertexSet = forall t r.
ToGraph t =>
r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg forall a. Set a
Set.empty forall a. a -> Set a
Set.singleton forall a. Ord a => Set a -> Set a -> Set a
Set.union forall a. Ord a => Set a -> Set a -> Set a
Set.union
vertexIntSet :: ToVertex t ~ Int => t -> IntSet
vertexIntSet = forall t r.
ToGraph t =>
r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg IntSet
IntSet.empty Int -> IntSet
IntSet.singleton IntSet -> IntSet -> IntSet
IntSet.union IntSet -> IntSet -> IntSet
IntSet.union
edgeSet :: Ord (ToVertex t) => t -> Set (ToVertex t, ToVertex t)
edgeSet = forall a. Eq a => AdjacencyMap a -> Set (a, a)
AM.edgeSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
preSet :: Ord (ToVertex t) => ToVertex t -> t -> Set (ToVertex t)
preSet ToVertex t
x = forall a. Ord a => a -> AdjacencyMap a -> Set a
AM.postSet ToVertex t
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMapTranspose
preIntSet :: ToVertex t ~ Int => Int -> t -> IntSet
preIntSet Int
x = Int -> AdjacencyIntMap -> IntSet
AIM.postIntSet Int
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (ToGraph t, ToVertex t ~ Int) => t -> AdjacencyIntMap
toAdjacencyIntMapTranspose
postSet :: Ord (ToVertex t) => ToVertex t -> t -> Set (ToVertex t)
postSet ToVertex t
x = forall a. Ord a => a -> AdjacencyMap a -> Set a
AM.postSet ToVertex t
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
postIntSet :: ToVertex t ~ Int => Int -> t -> IntSet
postIntSet Int
x = Int -> AdjacencyIntMap -> IntSet
AIM.postIntSet Int
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (ToGraph t, ToVertex t ~ Int) => t -> AdjacencyIntMap
toAdjacencyIntMap
adjacencyList :: Ord (ToVertex t) => t -> [(ToVertex t, [ToVertex t])]
adjacencyList = forall a. AdjacencyMap a -> [(a, [a])]
AM.adjacencyList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
dfsForest :: Ord (ToVertex t) => t -> Forest (ToVertex t)
dfsForest = forall a. Ord a => AdjacencyMap a -> Forest a
AM.dfsForest forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
dfsForestFrom :: Ord (ToVertex t) => t -> [ToVertex t] -> Forest (ToVertex t)
dfsForestFrom = forall a. Ord a => AdjacencyMap a -> [a] -> Forest a
AM.dfsForestFrom forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
dfs :: Ord (ToVertex t) => t -> [ToVertex t] -> [ToVertex t]
dfs = forall a. Ord a => AdjacencyMap a -> [a] -> [a]
AM.dfs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
reachable :: Ord (ToVertex t) => t -> ToVertex t -> [ToVertex t]
reachable = forall a. Ord a => AdjacencyMap a -> a -> [a]
AM.reachable forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
topSort :: Ord (ToVertex t) => t -> Either (AM.Cycle (ToVertex t)) [ToVertex t]
topSort = forall a. Ord a => AdjacencyMap a -> Either (Cycle a) [a]
AM.topSort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
isAcyclic :: Ord (ToVertex t) => t -> Bool
isAcyclic = forall a. Ord a => AdjacencyMap a -> Bool
AM.isAcyclic forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
toAdjacencyMap :: Ord (ToVertex t) => t -> AM.AdjacencyMap (ToVertex t)
toAdjacencyMap = forall t r.
ToGraph t =>
r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg forall a. AdjacencyMap a
AM.empty forall a. a -> AdjacencyMap a
AM.vertex forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
AM.overlay forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
AM.connect
toAdjacencyMapTranspose :: Ord (ToVertex t) => t -> AM.AdjacencyMap (ToVertex t)
toAdjacencyMapTranspose = forall t r.
ToGraph t =>
r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg forall a. AdjacencyMap a
AM.empty forall a. a -> AdjacencyMap a
AM.vertex forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
AM.overlay (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
AM.connect)
toAdjacencyIntMap :: ToVertex t ~ Int => t -> AIM.AdjacencyIntMap
toAdjacencyIntMap = forall t r.
ToGraph t =>
r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg AdjacencyIntMap
AIM.empty Int -> AdjacencyIntMap
AIM.vertex AdjacencyIntMap -> AdjacencyIntMap -> AdjacencyIntMap
AIM.overlay AdjacencyIntMap -> AdjacencyIntMap -> AdjacencyIntMap
AIM.connect
toAdjacencyIntMapTranspose :: ToVertex t ~ Int => t -> AIM.AdjacencyIntMap
toAdjacencyIntMapTranspose = forall t r.
ToGraph t =>
r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
foldg AdjacencyIntMap
AIM.empty Int -> AdjacencyIntMap
AIM.vertex AdjacencyIntMap -> AdjacencyIntMap -> AdjacencyIntMap
AIM.overlay (forall a b c. (a -> b -> c) -> b -> a -> c
flip AdjacencyIntMap -> AdjacencyIntMap -> AdjacencyIntMap
AIM.connect)
isDfsForestOf :: Ord (ToVertex t) => Forest (ToVertex t) -> t -> Bool
isDfsForestOf Forest (ToVertex t)
f = forall a. Ord a => Forest a -> AdjacencyMap a -> Bool
AM.isDfsForestOf Forest (ToVertex t)
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
isTopSortOf :: Ord (ToVertex t) => [ToVertex t] -> t -> Bool
isTopSortOf [ToVertex t]
vs = forall a. Ord a => [a] -> AdjacencyMap a -> Bool
AM.isTopSortOf [ToVertex t]
vs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
instance Ord a => ToGraph (G.Graph a) where
type ToVertex (G.Graph a) = a
toGraph :: Graph a -> Graph (ToVertex (Graph a))
toGraph = forall a. a -> a
id
foldg :: forall r.
r
-> (ToVertex (Graph a) -> r)
-> (r -> r -> r)
-> (r -> r -> r)
-> Graph a
-> r
foldg = forall b a.
b -> (a -> b) -> (b -> b -> b) -> (b -> b -> b) -> Graph a -> b
G.foldg
hasEdge :: Eq (ToVertex (Graph a)) =>
ToVertex (Graph a) -> ToVertex (Graph a) -> Graph a -> Bool
hasEdge = forall a. Eq a => a -> a -> Graph a -> Bool
G.hasEdge
instance Ord a => ToGraph (AM.AdjacencyMap a) where
type ToVertex (AM.AdjacencyMap a) = a
toGraph :: AdjacencyMap a -> Graph (ToVertex (AdjacencyMap a))
toGraph = forall a. [(a, [a])] -> Graph a
G.stars
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Set a -> [a]
Set.toList)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [(k, a)]
Map.toList
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. AdjacencyMap a -> Map a (Set a)
AM.adjacencyMap
isEmpty :: AdjacencyMap a -> Bool
isEmpty = forall a. AdjacencyMap a -> Bool
AM.isEmpty
hasVertex :: Eq (ToVertex (AdjacencyMap a)) =>
ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Bool
hasVertex = forall a. Ord a => a -> AdjacencyMap a -> Bool
AM.hasVertex
hasEdge :: Eq (ToVertex (AdjacencyMap a)) =>
ToVertex (AdjacencyMap a)
-> ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Bool
hasEdge = forall a. Ord a => a -> a -> AdjacencyMap a -> Bool
AM.hasEdge
vertexCount :: Ord (ToVertex (AdjacencyMap a)) => AdjacencyMap a -> Int
vertexCount = forall a. AdjacencyMap a -> Int
AM.vertexCount
edgeCount :: Ord (ToVertex (AdjacencyMap a)) => AdjacencyMap a -> Int
edgeCount = forall a. AdjacencyMap a -> Int
AM.edgeCount
vertexList :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> [ToVertex (AdjacencyMap a)]
vertexList = forall a. AdjacencyMap a -> [a]
AM.vertexList
vertexSet :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> Set (ToVertex (AdjacencyMap a))
vertexSet = forall a. AdjacencyMap a -> Set a
AM.vertexSet
vertexIntSet :: (ToVertex (AdjacencyMap a) ~ Int) => AdjacencyMap a -> IntSet
vertexIntSet = [Int] -> IntSet
IntSet.fromAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. AdjacencyMap a -> [a]
AM.vertexList
edgeList :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> [(ToVertex (AdjacencyMap a), ToVertex (AdjacencyMap a))]
edgeList = forall a. AdjacencyMap a -> [(a, a)]
AM.edgeList
edgeSet :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> Set (ToVertex (AdjacencyMap a), ToVertex (AdjacencyMap a))
edgeSet = forall a. Eq a => AdjacencyMap a -> Set (a, a)
AM.edgeSet
adjacencyList :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> [(ToVertex (AdjacencyMap a), [ToVertex (AdjacencyMap a)])]
adjacencyList = forall a. AdjacencyMap a -> [(a, [a])]
AM.adjacencyList
preSet :: Ord (ToVertex (AdjacencyMap a)) =>
ToVertex (AdjacencyMap a)
-> AdjacencyMap a -> Set (ToVertex (AdjacencyMap a))
preSet = forall a. Ord a => a -> AdjacencyMap a -> Set a
AM.preSet
postSet :: Ord (ToVertex (AdjacencyMap a)) =>
ToVertex (AdjacencyMap a)
-> AdjacencyMap a -> Set (ToVertex (AdjacencyMap a))
postSet = forall a. Ord a => a -> AdjacencyMap a -> Set a
AM.postSet
dfsForest :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> Forest (ToVertex (AdjacencyMap a))
dfsForest = forall a. Ord a => AdjacencyMap a -> Forest a
AM.dfsForest
dfsForestFrom :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> [ToVertex (AdjacencyMap a)]
-> Forest (ToVertex (AdjacencyMap a))
dfsForestFrom = forall a. Ord a => AdjacencyMap a -> [a] -> Forest a
AM.dfsForestFrom
dfs :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> [ToVertex (AdjacencyMap a)] -> [ToVertex (AdjacencyMap a)]
dfs = forall a. Ord a => AdjacencyMap a -> [a] -> [a]
AM.dfs
reachable :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> ToVertex (AdjacencyMap a) -> [ToVertex (AdjacencyMap a)]
reachable = forall a. Ord a => AdjacencyMap a -> a -> [a]
AM.reachable
topSort :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> Either
(Cycle (ToVertex (AdjacencyMap a))) [ToVertex (AdjacencyMap a)]
topSort = forall a. Ord a => AdjacencyMap a -> Either (Cycle a) [a]
AM.topSort
isAcyclic :: Ord (ToVertex (AdjacencyMap a)) => AdjacencyMap a -> Bool
isAcyclic = forall a. Ord a => AdjacencyMap a -> Bool
AM.isAcyclic
toAdjacencyMap :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> AdjacencyMap (ToVertex (AdjacencyMap a))
toAdjacencyMap = forall a. a -> a
id
toAdjacencyIntMap :: (ToVertex (AdjacencyMap a) ~ Int) =>
AdjacencyMap a -> AdjacencyIntMap
toAdjacencyIntMap = AdjacencyMap Int -> AdjacencyIntMap
AIM.fromAdjacencyMap
toAdjacencyMapTranspose :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> AdjacencyMap (ToVertex (AdjacencyMap a))
toAdjacencyMapTranspose = forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.transpose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
toAdjacencyIntMapTranspose :: (ToVertex (AdjacencyMap a) ~ Int) =>
AdjacencyMap a -> AdjacencyIntMap
toAdjacencyIntMapTranspose = AdjacencyIntMap -> AdjacencyIntMap
AIM.transpose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (ToGraph t, ToVertex t ~ Int) => t -> AdjacencyIntMap
toAdjacencyIntMap
isDfsForestOf :: Ord (ToVertex (AdjacencyMap a)) =>
Forest (ToVertex (AdjacencyMap a)) -> AdjacencyMap a -> Bool
isDfsForestOf = forall a. Ord a => Forest a -> AdjacencyMap a -> Bool
AM.isDfsForestOf
isTopSortOf :: Ord (ToVertex (AdjacencyMap a)) =>
[ToVertex (AdjacencyMap a)] -> AdjacencyMap a -> Bool
isTopSortOf = forall a. Ord a => [a] -> AdjacencyMap a -> Bool
AM.isTopSortOf
instance ToGraph AIM.AdjacencyIntMap where
type ToVertex AIM.AdjacencyIntMap = Int
toGraph :: AdjacencyIntMap -> Graph (ToVertex AdjacencyIntMap)
toGraph = forall a. [(a, [a])] -> Graph a
G.stars
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IntSet -> [Int]
IntSet.toList)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IntMap a -> [(Int, a)]
IntMap.toList
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AdjacencyIntMap -> IntMap IntSet
AIM.adjacencyIntMap
isEmpty :: AdjacencyIntMap -> Bool
isEmpty = AdjacencyIntMap -> Bool
AIM.isEmpty
hasVertex :: Eq (ToVertex AdjacencyIntMap) =>
ToVertex AdjacencyIntMap -> AdjacencyIntMap -> Bool
hasVertex = Int -> AdjacencyIntMap -> Bool
AIM.hasVertex
hasEdge :: Eq (ToVertex AdjacencyIntMap) =>
ToVertex AdjacencyIntMap
-> ToVertex AdjacencyIntMap -> AdjacencyIntMap -> Bool
hasEdge = Int -> Int -> AdjacencyIntMap -> Bool
AIM.hasEdge
vertexCount :: Ord (ToVertex AdjacencyIntMap) => AdjacencyIntMap -> Int
vertexCount = AdjacencyIntMap -> Int
AIM.vertexCount
edgeCount :: Ord (ToVertex AdjacencyIntMap) => AdjacencyIntMap -> Int
edgeCount = AdjacencyIntMap -> Int
AIM.edgeCount
vertexList :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap -> [ToVertex AdjacencyIntMap]
vertexList = AdjacencyIntMap -> [Int]
AIM.vertexList
vertexSet :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap -> Set (ToVertex AdjacencyIntMap)
vertexSet = forall a. Eq a => [a] -> Set a
Set.fromAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
IntSet.toAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. AdjacencyIntMap -> IntSet
AIM.vertexIntSet
vertexIntSet :: (ToVertex AdjacencyIntMap ~ Int) => AdjacencyIntMap -> IntSet
vertexIntSet = AdjacencyIntMap -> IntSet
AIM.vertexIntSet
edgeList :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap
-> [(ToVertex AdjacencyIntMap, ToVertex AdjacencyIntMap)]
edgeList = AdjacencyIntMap -> [(Int, Int)]
AIM.edgeList
edgeSet :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap
-> Set (ToVertex AdjacencyIntMap, ToVertex AdjacencyIntMap)
edgeSet = AdjacencyIntMap -> Set (Int, Int)
AIM.edgeSet
adjacencyList :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap
-> [(ToVertex AdjacencyIntMap, [ToVertex AdjacencyIntMap])]
adjacencyList = AdjacencyIntMap -> [(Int, [Int])]
AIM.adjacencyList
preIntSet :: (ToVertex AdjacencyIntMap ~ Int) =>
Int -> AdjacencyIntMap -> IntSet
preIntSet = Int -> AdjacencyIntMap -> IntSet
AIM.preIntSet
postIntSet :: (ToVertex AdjacencyIntMap ~ Int) =>
Int -> AdjacencyIntMap -> IntSet
postIntSet = Int -> AdjacencyIntMap -> IntSet
AIM.postIntSet
dfsForest :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap -> Forest (ToVertex AdjacencyIntMap)
dfsForest = AdjacencyIntMap -> Forest Int
AIM.dfsForest
dfsForestFrom :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap
-> [ToVertex AdjacencyIntMap] -> Forest (ToVertex AdjacencyIntMap)
dfsForestFrom = AdjacencyIntMap -> [Int] -> Forest Int
AIM.dfsForestFrom
dfs :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap
-> [ToVertex AdjacencyIntMap] -> [ToVertex AdjacencyIntMap]
dfs = AdjacencyIntMap -> [Int] -> [Int]
AIM.dfs
reachable :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap
-> ToVertex AdjacencyIntMap -> [ToVertex AdjacencyIntMap]
reachable = AdjacencyIntMap -> Int -> [Int]
AIM.reachable
topSort :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap
-> Either
(Cycle (ToVertex AdjacencyIntMap)) [ToVertex AdjacencyIntMap]
topSort = AdjacencyIntMap -> Either (Cycle Int) [Int]
AIM.topSort
isAcyclic :: Ord (ToVertex AdjacencyIntMap) => AdjacencyIntMap -> Bool
isAcyclic = AdjacencyIntMap -> Bool
AIM.isAcyclic
toAdjacencyMap :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap -> AdjacencyMap (ToVertex AdjacencyIntMap)
toAdjacencyMap = forall a. Ord a => [(a, [a])] -> AdjacencyMap a
AM.stars forall b c a. (b -> c) -> (a -> b) -> a -> c
. AdjacencyIntMap -> [(Int, [Int])]
AIM.adjacencyList
toAdjacencyIntMap :: (ToVertex AdjacencyIntMap ~ Int) =>
AdjacencyIntMap -> AdjacencyIntMap
toAdjacencyIntMap = forall a. a -> a
id
toAdjacencyMapTranspose :: Ord (ToVertex AdjacencyIntMap) =>
AdjacencyIntMap -> AdjacencyMap (ToVertex AdjacencyIntMap)
toAdjacencyMapTranspose = forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.transpose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
toAdjacencyIntMapTranspose :: (ToVertex AdjacencyIntMap ~ Int) =>
AdjacencyIntMap -> AdjacencyIntMap
toAdjacencyIntMapTranspose = AdjacencyIntMap -> AdjacencyIntMap
AIM.transpose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (ToGraph t, ToVertex t ~ Int) => t -> AdjacencyIntMap
toAdjacencyIntMap
isDfsForestOf :: Ord (ToVertex AdjacencyIntMap) =>
Forest (ToVertex AdjacencyIntMap) -> AdjacencyIntMap -> Bool
isDfsForestOf = Forest Int -> AdjacencyIntMap -> Bool
AIM.isDfsForestOf
isTopSortOf :: Ord (ToVertex AdjacencyIntMap) =>
[ToVertex AdjacencyIntMap] -> AdjacencyIntMap -> Bool
isTopSortOf = [Int] -> AdjacencyIntMap -> Bool
AIM.isTopSortOf
instance Ord a => ToGraph (NAM.AdjacencyMap a) where
type ToVertex (NAM.AdjacencyMap a) = a
toGraph :: AdjacencyMap a -> Graph (ToVertex (AdjacencyMap a))
toGraph = forall t. ToGraph t => t -> Graph (ToVertex t)
toGraph forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
isEmpty :: AdjacencyMap a -> Bool
isEmpty AdjacencyMap a
_ = Bool
False
hasVertex :: Eq (ToVertex (AdjacencyMap a)) =>
ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Bool
hasVertex = forall a. Ord a => a -> AdjacencyMap a -> Bool
NAM.hasVertex
hasEdge :: Eq (ToVertex (AdjacencyMap a)) =>
ToVertex (AdjacencyMap a)
-> ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Bool
hasEdge = forall a. Ord a => a -> a -> AdjacencyMap a -> Bool
NAM.hasEdge
vertexCount :: Ord (ToVertex (AdjacencyMap a)) => AdjacencyMap a -> Int
vertexCount = forall a. AdjacencyMap a -> Int
NAM.vertexCount
edgeCount :: Ord (ToVertex (AdjacencyMap a)) => AdjacencyMap a -> Int
edgeCount = forall a. AdjacencyMap a -> Int
NAM.edgeCount
vertexList :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> [ToVertex (AdjacencyMap a)]
vertexList = forall t. (ToGraph t, Ord (ToVertex t)) => t -> [ToVertex t]
vertexList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
vertexSet :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> Set (ToVertex (AdjacencyMap a))
vertexSet = forall a. AdjacencyMap a -> Set a
NAM.vertexSet
vertexIntSet :: (ToVertex (AdjacencyMap a) ~ Int) => AdjacencyMap a -> IntSet
vertexIntSet = forall t. (ToGraph t, ToVertex t ~ Int) => t -> IntSet
vertexIntSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
edgeList :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> [(ToVertex (AdjacencyMap a), ToVertex (AdjacencyMap a))]
edgeList = forall a. AdjacencyMap a -> [(a, a)]
NAM.edgeList
edgeSet :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> Set (ToVertex (AdjacencyMap a), ToVertex (AdjacencyMap a))
edgeSet = forall a. Ord a => AdjacencyMap a -> Set (a, a)
NAM.edgeSet
adjacencyList :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> [(ToVertex (AdjacencyMap a), [ToVertex (AdjacencyMap a)])]
adjacencyList = forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> [(ToVertex t, [ToVertex t])]
adjacencyList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
preSet :: Ord (ToVertex (AdjacencyMap a)) =>
ToVertex (AdjacencyMap a)
-> AdjacencyMap a -> Set (ToVertex (AdjacencyMap a))
preSet = forall a. Ord a => a -> AdjacencyMap a -> Set a
NAM.preSet
postSet :: Ord (ToVertex (AdjacencyMap a)) =>
ToVertex (AdjacencyMap a)
-> AdjacencyMap a -> Set (ToVertex (AdjacencyMap a))
postSet = forall a. Ord a => a -> AdjacencyMap a -> Set a
NAM.postSet
dfsForest :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> Forest (ToVertex (AdjacencyMap a))
dfsForest = forall t. (ToGraph t, Ord (ToVertex t)) => t -> Forest (ToVertex t)
dfsForest forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
dfsForestFrom :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> [ToVertex (AdjacencyMap a)]
-> Forest (ToVertex (AdjacencyMap a))
dfsForestFrom = forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> [ToVertex t] -> Forest (ToVertex t)
dfsForestFrom forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
dfs :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> [ToVertex (AdjacencyMap a)] -> [ToVertex (AdjacencyMap a)]
dfs = forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> [ToVertex t] -> [ToVertex t]
dfs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
reachable :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> ToVertex (AdjacencyMap a) -> [ToVertex (AdjacencyMap a)]
reachable = forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> ToVertex t -> [ToVertex t]
reachable forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
topSort :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a
-> Either
(Cycle (ToVertex (AdjacencyMap a))) [ToVertex (AdjacencyMap a)]
topSort = forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> Either (Cycle (ToVertex t)) [ToVertex t]
topSort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
isAcyclic :: Ord (ToVertex (AdjacencyMap a)) => AdjacencyMap a -> Bool
isAcyclic = forall t. (ToGraph t, Ord (ToVertex t)) => t -> Bool
isAcyclic forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
toAdjacencyMap :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> AdjacencyMap (ToVertex (AdjacencyMap a))
toAdjacencyMap = forall a. AdjacencyMap a -> AdjacencyMap a
NAM.fromNonEmpty
toAdjacencyIntMap :: (ToVertex (AdjacencyMap a) ~ Int) =>
AdjacencyMap a -> AdjacencyIntMap
toAdjacencyIntMap = forall t. (ToGraph t, ToVertex t ~ Int) => t -> AdjacencyIntMap
toAdjacencyIntMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
toAdjacencyMapTranspose :: Ord (ToVertex (AdjacencyMap a)) =>
AdjacencyMap a -> AdjacencyMap (ToVertex (AdjacencyMap a))
toAdjacencyMapTranspose = forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
NAM.transpose
toAdjacencyIntMapTranspose :: (ToVertex (AdjacencyMap a) ~ Int) =>
AdjacencyMap a -> AdjacencyIntMap
toAdjacencyIntMapTranspose = forall t. (ToGraph t, ToVertex t ~ Int) => t -> AdjacencyIntMap
toAdjacencyIntMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
NAM.transpose
isDfsForestOf :: Ord (ToVertex (AdjacencyMap a)) =>
Forest (ToVertex (AdjacencyMap a)) -> AdjacencyMap a -> Bool
isDfsForestOf Forest (ToVertex (AdjacencyMap a))
f = forall t.
(ToGraph t, Ord (ToVertex t)) =>
Forest (ToVertex t) -> t -> Bool
isDfsForestOf Forest (ToVertex (AdjacencyMap a))
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
isTopSortOf :: Ord (ToVertex (AdjacencyMap a)) =>
[ToVertex (AdjacencyMap a)] -> AdjacencyMap a -> Bool
isTopSortOf [ToVertex (AdjacencyMap a)]
x = forall t.
(ToGraph t, Ord (ToVertex t)) =>
[ToVertex t] -> t -> Bool
isTopSortOf [ToVertex (AdjacencyMap a)]
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
adjacencyMap :: ToGraph t => Ord (ToVertex t) => t -> Map (ToVertex t) (Set (ToVertex t))
adjacencyMap :: forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> Map (ToVertex t) (Set (ToVertex t))
adjacencyMap = forall a. AdjacencyMap a -> Map a (Set a)
AM.adjacencyMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMap
adjacencyIntMap :: (ToGraph t, ToVertex t ~ Int) => t -> IntMap IntSet
adjacencyIntMap :: forall t. (ToGraph t, ToVertex t ~ Int) => t -> IntMap IntSet
adjacencyIntMap = AdjacencyIntMap -> IntMap IntSet
AIM.adjacencyIntMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (ToGraph t, ToVertex t ~ Int) => t -> AdjacencyIntMap
toAdjacencyIntMap
adjacencyMapTranspose :: (ToGraph t, Ord (ToVertex t)) => t -> Map (ToVertex t) (Set (ToVertex t))
adjacencyMapTranspose :: forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> Map (ToVertex t) (Set (ToVertex t))
adjacencyMapTranspose = forall a. AdjacencyMap a -> Map a (Set a)
AM.adjacencyMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t.
(ToGraph t, Ord (ToVertex t)) =>
t -> AdjacencyMap (ToVertex t)
toAdjacencyMapTranspose
adjacencyIntMapTranspose :: (ToGraph t, ToVertex t ~ Int) => t -> IntMap IntSet
adjacencyIntMapTranspose :: forall t. (ToGraph t, ToVertex t ~ Int) => t -> IntMap IntSet
adjacencyIntMapTranspose = AdjacencyIntMap -> IntMap IntSet
AIM.adjacencyIntMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. (ToGraph t, ToVertex t ~ Int) => t -> AdjacencyIntMap
toAdjacencyIntMapTranspose