ghc-lib-parser-9.10.1.20250103: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Data.Graph.Directed

Synopsis

- data Graph node
- graphFromEdgedVerticesOrd :: Ord key => [Node key payload] -> Graph (Node key payload)
- graphFromEdgedVerticesUniq :: Uniquable key => [Node key payload] -> Graph (Node key payload)
- graphFromVerticesAndAdjacency :: Ord key => [Node key payload] -> [(key, key)] -> Graph (Node key payload)
- data SCC vertex where
  - AcyclicSCC vertex
  - NECyclicSCC !(NonEmpty vertex)
  - pattern CyclicSCC :: [vertex] -> SCC vertex
- data Node key payload = DigraphNode {
  - node_payload :: payload
  - node_key :: key
  - node_dependencies :: [key]
  }
- flattenSCC :: SCC vertex -> [vertex]
- flattenSCCs :: [SCC a] -> [a]
- stronglyConnCompG :: Graph node -> [SCC node]
- topologicalSortG :: Graph node -> [node]
- verticesG :: Graph node -> [node]
- edgesG :: Graph node -> [Edge node]
- hasVertexG :: Graph node -> node -> Bool
- reachableG :: Graph node -> node -> [node]
- reachablesG :: Graph node -> [node] -> [node]
- transposeG :: Graph node -> Graph node
- allReachable :: Ord key => Graph node -> (node -> key) -> Map key (Set key)
- allReachableCyclic :: Ord key => Graph node -> (node -> key) -> Map key (Set key)
- outgoingG :: Graph node -> node -> [node]
- emptyG :: Graph node -> Bool
- findCycle :: forall payload key. Ord key => [Node key payload] -> Maybe [payload]
- stronglyConnCompFromEdgedVerticesOrd :: Ord key => [Node key payload] -> [SCC payload]
- stronglyConnCompFromEdgedVerticesOrdR :: Ord key => [Node key payload] -> [SCC (Node key payload)]
- stronglyConnCompFromEdgedVerticesUniq :: Uniquable key => [Node key payload] -> [SCC payload]
- stronglyConnCompFromEdgedVerticesUniqR :: Uniquable key => [Node key payload] -> [SCC (Node key payload)]
- data EdgeType
  - = Forward
  - | Cross
  - | Backward
  - | SelfLoop
- classifyEdges :: Uniquable key => key -> (key -> [key]) -> [(key, key)] -> [((key, key), EdgeType)]

# Documentation

data Graph node #

#### Instances

Instances details

Outputable node => Outputable (Graph node) # |
Instance details Defined in GHC.Data.Graph.Directed Methods ppr :: Graph node -> SDoc #

graphFromEdgedVerticesOrd :: Ord key => [Node key payload] -> Graph (Node key payload) #

graphFromEdgedVerticesUniq :: Uniquable key => [Node key payload] -> Graph (Node key payload) #

graphFromVerticesAndAdjacency :: Ord key => [Node key payload] -> [(key, key)] -> Graph (Node key payload) #

data SCC vertex #

Strongly connected component.

Constructors

AcyclicSCC vertex | A single vertex that is not in any cycle.
NECyclicSCC !(NonEmpty vertex) | A maximal set of mutually reachable vertices. Since: containers-0.7.0

Bundled Patterns

pattern CyclicSCC :: [vertex] -> SCC vertex | Partial pattern synonym for backward compatibility with `containers < 0.7`.

#### Instances

Instances details

Foldable1 SCC | Since: containers-0.7.0

Instance details

Defined in Data.Graph

Methods

fold1 :: Semigroup m => SCC m -> m #

foldMap1 :: Semigroup m => (a -> m) -> SCC a -> m #

foldMap1' :: Semigroup m => (a -> m) -> SCC a -> m #

toNonEmpty :: SCC a -> NonEmpty a #

maximum :: Ord a => SCC a -> a #

minimum :: Ord a => SCC a -> a #

head :: SCC a -> a #

last :: SCC a -> a #

foldrMap1 :: (a -> b) -> (a -> b -> b) -> SCC a -> b #

foldlMap1' :: (a -> b) -> (b -> a -> b) -> SCC a -> b #

foldlMap1 :: (a -> b) -> (b -> a -> b) -> SCC a -> b #

foldrMap1' :: (a -> b) -> (a -> b -> b) -> SCC a -> b #

Eq1 SCC | Since: containers-0.5.9
Instance details Defined in Data.Graph Methods liftEq :: (a -> b -> Bool) -> SCC a -> SCC b -> Bool #
Read1 SCC | Since: containers-0.5.9
Instance details Defined in Data.Graph Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (SCC a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [SCC a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (SCC a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [SCC a] #
Show1 SCC | Since: containers-0.5.9
Instance details Defined in Data.Graph Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> SCC a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [SCC a] -> ShowS #
Functor SCC | Since: containers-0.5.4
Instance details Defined in Data.Graph Methods fmap :: (a -> b) -> SCC a -> SCC b # (<$) :: a -> SCC b -> SCC a #
Foldable SCC | Since: containers-0.5.9

Instance details

Defined in Data.Graph

Methods

fold :: Monoid m => SCC m -> m #

foldMap :: Monoid m => (a -> m) -> SCC a -> m #

foldMap' :: Monoid m => (a -> m) -> SCC a -> m #

foldr :: (a -> b -> b) -> b -> SCC a -> b #

foldr' :: (a -> b -> b) -> b -> SCC a -> b #

foldl :: (b -> a -> b) -> b -> SCC a -> b #

foldl' :: (b -> a -> b) -> b -> SCC a -> b #

foldr1 :: (a -> a -> a) -> SCC a -> a #

foldl1 :: (a -> a -> a) -> SCC a -> a #

toList :: SCC a -> [a] #

null :: SCC a -> Bool #

length :: SCC a -> Int #

elem :: Eq a => a -> SCC a -> Bool #

maximum :: Ord a => SCC a -> a #

minimum :: Ord a => SCC a -> a #

sum :: Num a => SCC a -> a #

product :: Num a => SCC a -> a #

Traversable SCC | Since: containers-0.5.9
Instance details Defined in Data.Graph Methods traverse :: Applicative f => (a -> f b) -> SCC a -> f (SCC b) # sequenceA :: Applicative f => SCC (f a) -> f (SCC a) # mapM :: Monad m => (a -> m b) -> SCC a -> m (SCC b) # sequence :: Monad m => SCC (m a) -> m (SCC a) #
Generic1 SCC |

Instance details

Defined in Data.Graph

Associated Types

type Rep1 SCC | Since: containers-0.5.9

Instance details

Defined in Data.Graph

type Rep1 SCC = D1 ('MetaData "SCC" "Data.Graph" "containers-0.7-inplace" 'False) (C1 ('MetaCons "AcyclicSCC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1) :+: C1 ('MetaCons "NECyclicSCC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedUnpack) (Rec1 NonEmpty)))

Methods

from1 :: SCC a -> Rep1 SCC a #

to1 :: Rep1 SCC a -> SCC a #

OutputableP env a => OutputableP env (SCC a) # |
Instance details Defined in GHC.Utils.Outputable Methods pdoc :: env -> SCC a -> SDoc #
Lift vertex => Lift (SCC vertex :: Type) | Since: containers-0.6.6
Instance details Defined in Data.Graph Methods lift :: Quote m => SCC vertex -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => SCC vertex -> Code m (SCC vertex) #
NFData a => NFData (SCC a) |
Instance details Defined in Data.Graph Methods rnf :: SCC a -> () #
Data vertex => Data (SCC vertex) | Since: containers-0.5.9

Instance details

Defined in Data.Graph

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SCC vertex -> c (SCC vertex) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (SCC vertex) #

toConstr :: SCC vertex -> Constr #

dataTypeOf :: SCC vertex -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (SCC vertex)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (SCC vertex)) #

gmapT :: (forall b. Data b => b -> b) -> SCC vertex -> SCC vertex #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SCC vertex -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SCC vertex -> r #

gmapQ :: (forall d. Data d => d -> u) -> SCC vertex -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> SCC vertex -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> SCC vertex -> m (SCC vertex) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SCC vertex -> m (SCC vertex) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SCC vertex -> m (SCC vertex) #

Generic (SCC vertex) |

Instance details

Defined in Data.Graph

Associated Types

type Rep (SCC vertex) | Since: containers-0.5.9

Instance details

Defined in Data.Graph

type Rep (SCC vertex) = D1 ('MetaData "SCC" "Data.Graph" "containers-0.7-inplace" 'False) (C1 ('MetaCons "AcyclicSCC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 vertex)) :+: C1 ('MetaCons "NECyclicSCC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedUnpack) (Rec0 (NonEmpty vertex))))

Methods

from :: SCC vertex -> Rep (SCC vertex) x #

to :: Rep (SCC vertex) x -> SCC vertex #

Read vertex => Read (SCC vertex) | Since: containers-0.5.9
Instance details Defined in Data.Graph Methods readsPrec :: Int -> ReadS (SCC vertex) # readList :: ReadS [SCC vertex] # readPrec :: ReadPrec (SCC vertex) # readListPrec :: ReadPrec [SCC vertex] #
Show vertex => Show (SCC vertex) | Since: containers-0.5.9
Instance details Defined in Data.Graph Methods showsPrec :: Int -> SCC vertex -> ShowS # show :: SCC vertex -> String # showList :: [SCC vertex] -> ShowS #
Outputable a => Outputable (SCC a) # |
Instance details Defined in GHC.Utils.Outputable Methods ppr :: SCC a -> SDoc #
Eq vertex => Eq (SCC vertex) | Since: containers-0.5.9
Instance details Defined in Data.Graph Methods (==) :: SCC vertex -> SCC vertex -> Bool # (/=) :: SCC vertex -> SCC vertex -> Bool #
type Rep1 SCC | Since: containers-0.5.9

Instance details

Defined in Data.Graph

type Rep1 SCC = D1 ('MetaData "SCC" "Data.Graph" "containers-0.7-inplace" 'False) (C1 ('MetaCons "AcyclicSCC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1) :+: C1 ('MetaCons "NECyclicSCC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedUnpack) (Rec1 NonEmpty)))

type Rep (SCC vertex) | Since: containers-0.5.9

Instance details

Defined in Data.Graph

type Rep (SCC vertex) = D1 ('MetaData "SCC" "Data.Graph" "containers-0.7-inplace" 'False) (C1 ('MetaCons "AcyclicSCC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 vertex)) :+: C1 ('MetaCons "NECyclicSCC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedUnpack) (Rec0 (NonEmpty vertex))))

data Node key payload #

Representation for nodes of the Graph.

- The `payload` is user data, just carried around in this module
- The `key` is the node identifier. Key has an Ord instance for performance reasons.
- The `[key]` are the dependencies of the node; it's ok to have extra keys in the dependencies that are not the key of any Node in the graph

Constructors

DigraphNode |

Fields

- node_payload :: payload

  User data

- node_key :: key

  User defined node id

- node_dependencies :: [key]

  Dependencies/successors of the node

#### Instances

Instances details

Functor (Node key) # |
Instance details Defined in GHC.Data.Graph.Directed Methods fmap :: (a -> b) -> Node key a -> Node key b # (<$) :: a -> Node key b -> Node key a #
(Outputable a, Outputable b) => Outputable (Node a b) # |
Instance details Defined in GHC.Data.Graph.Directed Methods ppr :: Node a b -> SDoc #

flattenSCC :: SCC vertex -> [vertex] #

The vertices of a strongly connected component.

flattenSCCs :: [SCC a] -> [a] #

The vertices of a list of strongly connected components.

stronglyConnCompG :: Graph node -> [SCC node] #

topologicalSortG :: Graph node -> [node] #

verticesG :: Graph node -> [node] #

edgesG :: Graph node -> [Edge node] #

hasVertexG :: Graph node -> node -> Bool #

reachableG :: Graph node -> node -> [node] #

reachablesG :: Graph node -> [node] -> [node] #

Given a list of roots return all reachable nodes.

transposeG :: Graph node -> Graph node #

allReachable :: Ord key => Graph node -> (node -> key) -> Map key (Set key) #

Efficiently construct a map which maps each key to it's set of transitive dependencies. Only works on acyclic input.

allReachableCyclic :: Ord key => Graph node -> (node -> key) -> Map key (Set key) #

Efficiently construct a map which maps each key to it's set of transitive dependencies. Less efficient than `allReachable`, but works on cyclic input as well.

outgoingG :: Graph node -> node -> [node] #

emptyG :: Graph node -> Bool #

findCycle :: forall payload key. Ord key => [Node key payload] -> Maybe [payload] #

Find a reasonably short cycle a->b->c->a, in a graph The graph might not necessarily be strongly connected.

stronglyConnCompFromEdgedVerticesOrd :: Ord key => [Node key payload] -> [SCC payload] #

stronglyConnCompFromEdgedVerticesOrdR :: Ord key => [Node key payload] -> [SCC (Node key payload)] #

stronglyConnCompFromEdgedVerticesUniq :: Uniquable key => [Node key payload] -> [SCC payload] #

stronglyConnCompFromEdgedVerticesUniqR :: Uniquable key => [Node key payload] -> [SCC (Node key payload)] #

data EdgeType #

Edge direction based on DFS Classification

Constructors

Forward |
Cross |
Backward | Loop back towards the root node. Eg backjumps in loops
SelfLoop | v -> v

#### Instances

Instances details

Outputable EdgeType # |
Instance details Defined in GHC.Data.Graph.Directed Methods ppr :: EdgeType -> SDoc #
Eq EdgeType # |
Instance details Defined in GHC.Data.Graph.Directed Methods (==) :: EdgeType -> EdgeType -> Bool # (/=) :: EdgeType -> EdgeType -> Bool #
Ord EdgeType # |
Instance details Defined in GHC.Data.Graph.Directed Methods compare :: EdgeType -> EdgeType -> Ordering # (<) :: EdgeType -> EdgeType -> Bool # (<=) :: EdgeType -> EdgeType -> Bool # (>) :: EdgeType -> EdgeType -> Bool # (>=) :: EdgeType -> EdgeType -> Bool # max :: EdgeType -> EdgeType -> EdgeType # min :: EdgeType -> EdgeType -> EdgeType #

classifyEdges :: Uniquable key => key -> (key -> [key]) -> [(key, key)] -> [((key, key), EdgeType)] #

Given a start vertex, a way to get successors from a node and a list of (directed) edges classify the types of edges.