Module Data.Graph

Module
Data.Graph
Copyright
(c) The University of Glasgow 2002
License
BSD-style (see the file libraries/base/LICENSE)

A version of the graph algorithms described in:

Lazy Depth-First Search and Linear Graph Algorithms in Haskell, by David King and John Launchbury.

Ported to Frege from the Haskell library source.

Imports

Table of Content

Definitions

data SCC vertex

Strongly connected component.

Constructors

AcyclicSCC vertex

A single vertex that is not in any cycle.

CyclicSCC [vertex]

A maximal set of mutually reachable vertices.

flattenSCCs ∷ [SCC a] → [a]

The vertices of a list of strongly connected components.

flattenSCCSCC vertex → [vertex]

The vertices of a strongly connected component.

edgeFromTuple(𝖆, 𝖇) → (𝖆, 𝖆, 𝖇)

Make a (key, [key]) list into one that is accepted by stronglyConnComp

stronglyConnectedComponentsOrd key ⇒ [(key, [key])] → [[key]]

Convenience function to compute topologically sorted strongly connected components of an adjacency list of the form:

  [(key, [key])]

The result will be a list of lists of keys, where a singleton indicates no mutual dependency with other keys and a list consisting of several keys means that those are mutually dependent on each other.

In addition, earlier elements will not depend on later ones.

If the result contains only singletons, then the input was an acyclic graph.

stronglyConnCompOrd key ⇒ [(node, key, [key])] → [SCC node]

The strongly connected components of a directed graph, topologically sorted.

The graph is a list of nodes uniquely identified by keys, with a list of keys of nodes this node has edges to. The latter one may contain keys that don't correspond to nodes of the graph; such edges are ignored.

stronglyConnCompROrd key ⇒ [(node, key, [key])] → [SCC (node, key, [key])]

The strongly connected components of a directed graph, topologically sorted. The function is the same as stronglyConnComp, except that all the information about each node retained.

This interface is used when you expect to apply SCC to (some of) the result of SCC, so you don't want to lose the dependency information.

data Edge

An edge from the first vertex to the second.

Constructors

Edge {from ∷ Int, to ∷ Int}

Member Functions

fromEdgeInt

access field from

toEdgeInt

access field to

size(Int, Int)Int
boundsJArray a → (Int, Int)
verticesJArray [Int] → [Int]

All vertices of a graph.

edgesJArray [Int] → [Edge]

All edges of a graph.

mapT ∷ (ArrayElement a, ArrayElement b) ⇒ (Int → a → b) → JArray a → JArray b
mapTIArrayElement a ⇒ (Int → a → Int) → JArray aJArray Int
buildG(Int, Int) → [Edge] → JArray [Int]

Build a graph from a list of edges.

transposeGJArray [Int] → JArray [Int]

The graph obtained by reversing all edges.

reverseEJArray [Int] → [Edge]
outdegreeJArray [Int]JArray Int

A table of the count of edges from each node.

indegreeJArray [Int] → JArray Int

A table of the count of edges into each node.

graphFromEdges'Ord key ⇒ [(node, key, [key])] → (JArray [Int], Int→(node, key, [key]))

Identical to graphFromEdges, except that the return value does not include the function which maps keys to vertices. This version of graphFromEdges is for backwards compatibility.

graphFromEdgesOrd key ⇒ [(node, key, [key])] → (JArray [Int], Int→(node, key, [key]), key→Maybe Int)

Build a graph from a list of nodes uniquely identified by keys, with a list of keys of nodes this node should have edges to. The out-list may contain keys that don't correspond to nodes of the graph; they are ignored.

dffJArray [Int] → Forest Int

A spanning forest of the graph, obtained from a depth-first search of the graph starting from each vertex in an unspecified order.

dfsJArray [Int] → [Int] → Forest Int

A spanning forest of the part of the graph reachable from the listed vertices, obtained from a depth-first search of the graph starting at each of the listed vertices in order.

generateJArray [Int] → IntTree Int
prune(Int, Int)Forest IntForest Int
chopForest IntArrayOf s BoolST s (Forest Int)
preorderTree a → [a]
preorderFForest a → [a]
tabulate ∷ (Int, Int) → [Int]JArray Int
preArr ∷ (Int, Int) → Forest IntJArray Int
postorderTree a → [a]
postorderFForest a → [a]
postOrdJArray [Int] → [Int]
topSortJArray [Int] → [Int]

A topological sort of the graph.

The order is partially specified by the condition that a vertex i precedes j whenever j is reachable from i but not vice versa.

componentsJArray [Int] → Forest Int

The connected components of a graph.

Two vertices are connected if there is a path between them, traversing edges in either direction.

undirectedJArray [Int] → JArray [Int]
sccJArray [Int] → Forest Int

The strongly connected components of a graph.

reachableJArray [Int] → Int → [Int]

A list of vertices reachable from a given vertex.

pathJArray [Int] → IntIntBool

Is the second vertex reachable from the first?

bccJArray [Int] → Forest [Int]

The biconnected components of a graph.

An undirected graph is biconnected if the deletion of any vertex leaves it connected.

do_labelJArray [Int] → JArray IntTree IntTree (Int, Int, Int)
bicompsTree (Int, Int, Int)Forest [Int]
collectTree (Int, Int, Int) → (Int, Tree [Int])

Functions and Values by Type

(Int, Int) → Forest IntJArray Int

preArr

(Int, Int) → Forest IntForest Int

prune

(Int, Int) → [Edge] → JArray [Int]

buildG

(Int, Int) → [Int] → JArray Int

tabulate

(Int, Int) → Int

size

Tree (Int, Int, Int) → (Int, Tree [Int])

collect

Tree (Int, Int, Int) → Forest [Int]

bicomps

JArray [Int] → JArray IntTree IntTree (Int, Int, Int)

do_label

JArray [Int] → [Int] → Forest Int

dfs

JArray [Int] → IntIntBool

path

JArray [Int] → IntTree Int

generate

JArray [Int] → Int → [Int]

reachable

JArray [Int] → JArray [Int]

transposeG, undirected

JArray [Int] → JArray Int

indegree, outdegree

JArray [Int] → Forest [Int]

bcc

JArray [Int] → Forest Int

components, dff, scc

JArray [Int] → [Edge]

edges, reverseE

JArray [Int] → [Int]

postOrd, topSort, vertices

Edge → (IntInt) → Edge

Edge.chg$from, Edge.chg$to

EdgeIntEdge

Edge.upd$to, Edge.upd$from

EdgeInt

Edge.to, Edge.from

IntIntEdge

Edge.Edge

SCC vertex → [vertex]

flattenSCC

Tree a → [a]

postorder, preorder

JArray a → (Int, Int)

bounds

[SCC a] → [a]

flattenSCCs

Forest IntArrayOf s BoolST s (Forest Int)

chop

Forest a → [a]

postorderF, preorderF

[vertex] → SCC vertex

SCC.CyclicSCC

vertex → SCC vertex

SCC.AcyclicSCC

𝖆 → Bool

Edge.has$from, Edge.has$to

ArrayElement a ⇒ (Int → a → Int) → JArray a → JArray Int

mapTI

Ord key ⇒ [(key, [key])] → [[key]]

stronglyConnectedComponents

(𝖆, 𝖇) → (𝖆, 𝖆, 𝖇)

edgeFromTuple

(ArrayElement a, ArrayElement b) ⇒ (Int → a → b) → JArray a → JArray b

mapT

Ord key ⇒ [(node, key, [key])] → (JArray [Int], Int→(node, key, [key]), key→Maybe Int)

graphFromEdges

Ord key ⇒ [(node, key, [key])] → (JArray [Int], Int→(node, key, [key]))

graphFromEdges'

Ord key ⇒ [(node, key, [key])] → [SCC (node, key, [key])]

stronglyConnCompR

Ord key ⇒ [(node, key, [key])] → [SCC node]

stronglyConnComp

Valid HTML 4.01 Strict