algraph-0.7.0.0: Graph library using adjacency list representation
CopyrightThodoris Papakonstantinou 2017-2026
LicenseLGPL-3
Maintainerdev@tpapak.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Graph.AdjacencyList

Description

Core types and constructors for directed graphs using adjacency list representation.

A Graph stores its vertex set, an EdgeMap for edge-attribute lookup, and a closure-based Neighbors function for O(log V) neighbor access. Undirected graphs are represented by including both directions of each edge.

Synopsis

Documentation

type Vertex = Int Source #

A vertex identifier (non-negative integer).

data Edge Source #

A directed edge from one vertex to another.

Constructors

Edge Vertex Vertex 

Instances

Instances details
Generic Edge Source # 
Instance details

Defined in Data.Graph.AdjacencyList

Associated Types

type Rep Edge :: Type -> Type #

Methods

from :: Edge -> Rep Edge x #

to :: Rep Edge x -> Edge #

Show Edge Source # 
Instance details

Defined in Data.Graph.AdjacencyList

Methods

showsPrec :: Int -> Edge -> ShowS #

show :: Edge -> String #

showList :: [Edge] -> ShowS #

Binary Edge Source # 
Instance details

Defined in Data.Graph.AdjacencyList

Methods

put :: Edge -> Put #

get :: Get Edge #

putList :: [Edge] -> Put #

Eq Edge Source # 
Instance details

Defined in Data.Graph.AdjacencyList

Methods

(==) :: Edge -> Edge -> Bool #

(/=) :: Edge -> Edge -> Bool #

Ord Edge Source # 
Instance details

Defined in Data.Graph.AdjacencyList

Methods

compare :: Edge -> Edge -> Ordering #

(<) :: Edge -> Edge -> Bool #

(<=) :: Edge -> Edge -> Bool #

(>) :: Edge -> Edge -> Bool #

(>=) :: Edge -> Edge -> Bool #

max :: Edge -> Edge -> Edge #

min :: Edge -> Edge -> Edge #

type Rep Edge Source # 
Instance details

Defined in Data.Graph.AdjacencyList

type Neighbors = Vertex -> [Vertex] Source #

Takes vertex and outputs neighboring vertices. The Neighbors type is the function from a vertex to its neighbors

type EdgeMap = Map Edge Int Source #

Map from edges to their sequential index (1-based). Used for edge-attribute lookup.

Graph definition

data Graph Source #

Graph definition of directed Graphs undirected graphs should include reverse edges.

Constructors

Graph 

Fields

Instances

Instances details
Show Graph Source # 
Instance details

Defined in Data.Graph.AdjacencyList

Methods

showsPrec :: Int -> Graph -> ShowS #

show :: Graph -> String #

showList :: [Graph] -> ShowS #

Eq Graph Source # 
Instance details

Defined in Data.Graph.AdjacencyList

Methods

(==) :: Graph -> Graph -> Bool #

(/=) :: Graph -> Graph -> Bool #

fromTuple :: (Vertex, Vertex) -> Edge Source #

Construct an Edge from a (source, target) tuple.

toTuple :: Edge -> (Vertex, Vertex) Source #

Convert an Edge to a (source, target) tuple.

createGraph: Graph constructor

createGraph :: [Vertex] -> Neighbors -> Graph Source #

Graph constructor given a neighbors function

graph from list of Edges

graphFromEdges :: [Edge] -> Graph Source #

Graph constructor given a list of edges.

Builds the adjacency map in a single O(E) pass using fromListWith, then wraps it in a closure for O(log V) neighbor lookup.

edges :: Graph -> [Edge] Source #

All edges of the graph, in EdgeMap key order.

reverseEdge :: Edge -> Edge Source #

Reverse the direction of an edge.

reverseEdges :: Graph -> [Edge] Source #

All edges of the graph with reversed direction.

reverseGraph :: Graph -> Graph Source #

Reverse all edges in the graph.

filterVertices

filterVertices Source #

Arguments

:: (Vertex -> Bool)

filter predicate

-> Graph 
-> Graph 

Get the subgraph of a graph by including vertices satisfying given predicate.

filterEdges

filterEdges :: (Edge -> Bool) -> Graph -> Graph Source #

Get the subgraph of a graph by including edges satisfying given predicate.

makeUndirected

makeUndirected Source #

Arguments

:: Graph

directed graph

-> Graph

undirected graph

Make a graph undirected by adding all missing reverse edges.

adjacentEdges :: Graph -> Vertex -> [Edge] Source #

All outgoing edges from a vertex.

edgesFromNeighbors :: Neighbors -> [Vertex] -> [Edge] Source #

Enumerate all edges implied by a Neighbors function over a vertex set.

adjacencyMap :: Graph -> IntMap [Vertex] Source #

Build an explicit adjacency map from the graph's Neighbors closure.

edgeExists :: Graph -> Edge -> Bool Source #

Check whether an edge exists in the graph.

edgeIndex :: Graph -> Edge -> Maybe Int Source #

Gives the position of the edge to the edges list

from :: Edge -> Vertex Source #

Source vertex of an edge.

to :: Edge -> Vertex Source #

Target vertex of an edge.

numVertices :: Graph -> Int Source #

Number of vertices in the graph.

numEdges :: Graph -> Int Source #

Number of edges in the graph.

removeReverseEdges Source #

Arguments

:: Graph

Graph with reverse edges

-> Graph

Directected graph

Make a graph directed by removing randomly reverse edges

completeGraph :: Int -> Graph Source #

Complete undirected graph from number of vertices