| Copyright | Thodoris Papakonstantinou 2017-2026 |
|---|---|
| License | LGPL-3 |
| Maintainer | dev@tpapak.com |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Data.Graph.AdjacencyList
Description
Synopsis
- type Vertex = Int
- data Edge = Edge Vertex Vertex
- type Neighbors = Vertex -> [Vertex]
- type EdgeMap = Map Edge Int
- data Graph = Graph {}
- fromTuple :: (Vertex, Vertex) -> Edge
- toTuple :: Edge -> (Vertex, Vertex)
- createGraph :: [Vertex] -> Neighbors -> Graph
- graphFromEdges :: [Edge] -> Graph
- edges :: Graph -> [Edge]
- reverseEdge :: Edge -> Edge
- reverseEdges :: Graph -> [Edge]
- reverseGraph :: Graph -> Graph
- filterVertices :: (Vertex -> Bool) -> Graph -> Graph
- filterEdges :: (Edge -> Bool) -> Graph -> Graph
- makeUndirected :: Graph -> Graph
- adjacentEdges :: Graph -> Vertex -> [Edge]
- edgesFromNeighbors :: Neighbors -> [Vertex] -> [Edge]
- adjacencyMap :: Graph -> IntMap [Vertex]
- edgeExists :: Graph -> Edge -> Bool
- edgeIndex :: Graph -> Edge -> Maybe Int
- from :: Edge -> Vertex
- to :: Edge -> Vertex
- numVertices :: Graph -> Int
- numEdges :: Graph -> Int
- removeReverseEdges :: Graph -> Graph
- completeGraph :: Int -> Graph
Documentation
A directed edge from one vertex to another.
Instances
| Generic Edge Source # | |
| Show Edge Source # | |
| Binary Edge Source # | |
| Eq Edge Source # | |
| Ord Edge Source # | |
| type Rep Edge Source # | |
Defined in Data.Graph.AdjacencyList type Rep Edge = D1 ('MetaData "Edge" "Data.Graph.AdjacencyList" "algraph-0.7.0.0-inplace" 'False) (C1 ('MetaCons "Edge" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Vertex) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Vertex))) | |
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
Graph definition of directed Graphs undirected graphs should include reverse edges.
Constructors
| Graph | |
createGraph: Graph constructor
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.
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
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
Make a graph undirected by adding all missing reverse edges.
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.
numVertices :: Graph -> Int Source #
Number of vertices in the graph.
Make a graph directed by removing randomly reverse edges
completeGraph :: Int -> Graph Source #
Complete undirected graph from number of vertices