HORIZON HASKELLDocslts/ghc-10.0.xaa25b892026-10-10Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · aa25b89 · 2026-10-10

Moduleghc-lib-parser-9.14.1.20251220GHC2021

GHC.Data.Graph.Directed.Reachability

An abstract interface for a fast reachability data structure constructed from a GHC.Data.Graph.Directed graph.

  • 1 type
  • 7 values
datadata ReachabilityIndex node
#

The abstract data structure for fast reachability queries

Constructing a reachability index

2 declarations

Reachability queries

4 declarations
valueallReachable
  1. :: ReachabilityIndex node
  2. -> node

    The root node

  3. -> [node]

    All nodes reachable from root

#

allReachable returns the nodes reachable from the given root node.

Properties: * The list of nodes does not include the root node! * The list of nodes is deterministically ordered, but according to an internal order determined by the indices attributed to graph nodes.

If you need a topologically sorted list, consider using the functions exposed from GHC.Data.Graph.Directed on Graph instead.

valueallReachableMany
  1. :: ReachabilityIndex node
  2. -> [node]

    The roots

  3. -> [node]

    All nodes reachable from all roots

#

allReachableMany returns all nodes reachable from the many given roots.

Properties: * The list of nodes does not include the roots node! * The list of nodes is deterministically ordered, but according to an internal order determined by the indices attributed to graph nodes. * This function has $O(n)$ complexity where $n$ is the number of roots.

If you need a topologically sorted list, consider using the functions exposed from GHC.Data.Graph.Directed on Graph instead (reachableG).

valueisReachable
  1. :: ReachabilityIndex node
    g
  2. -> node
    a
  3. -> node
    b
  4. -> Bool

    b is reachable from a

#

Fast reachability query.

On graph g with nodes a and b, isReachable g a b asks whether b can be reached through g starting from a.

Properties: * No self loops, i.e. isReachable _ a a == False

valueisReachableMany
  1. :: ReachabilityIndex node
    g
  2. -> [node]
    roots
  3. -> node

    b is reachable from any of the roots

  4. -> Bool
#

Fast reachability query with many roots.

On graph g with many nodes roots and node b, isReachableMany g as b asks whether b can be reached through g from any of the roots.

By partially applying this function to a set of roots, the resulting function can be applied many times and share the initial work.

Properties: * No self loops, i.e. isReachableMany _ [a] a == False

Debugging

1 declaration