Module

Transit.Data.Graph

Package
purescript-transit
Repository
m-bock/purescript-transit

General purpose graph data structure for representing directed graphs with labeled edges.

This module provides a simple graph representation where:

  • Edges are labeled (each edge has an associated label value)
  • Nodes are values themselves
  • Supports directed edges, cycles, and multiple edges between nodes

#Edge Source

type Edge edgeLabel node = { edgeLabel :: edgeLabel, fromNode :: node, toNode :: node }

An edge in the graph connecting two nodes with a label.

  • edgeLabel: The type of edge labels
  • node: The type of node values

#Graph Source

newtype Graph edgeLabel node

A directed graph that supports cycles and multiple edges.

Supports:

  • Directed edges (fromNode -> toNode)
  • Cycles (paths that return to a node, possibly through intermediate nodes)
  • Multiple edges (same nodes can be connected by different edges)

Instances

#fromEdges Source

fromEdges :: forall edgeLabel node. Set (Edge edgeLabel node) -> Graph edgeLabel node

Creates a graph from a set of edges.

#getIncomingEdges Source

getIncomingEdges :: forall edgeLabel node. Ord edgeLabel => Ord node => node -> Graph edgeLabel node -> Set (Edge edgeLabel node)

Gets all incoming edges to a given node.

#getNodes Source

getNodes :: forall edgeLabel node. Ord node => Graph edgeLabel node -> Set node

Extracts all unique nodes from the graph.

#getOutgoingEdges Source

getOutgoingEdges :: forall edgeLabel node. Ord edgeLabel => Ord node => node -> Graph edgeLabel node -> Set (Edge edgeLabel node)

Gets all outgoing edges from a given node.

#hasEdge Source

hasEdge :: forall edgeLabel node. Ord edgeLabel => Ord node => Edge edgeLabel node -> Graph edgeLabel node -> Boolean

Checks if an edge exists in the graph.

#getEdges Source

getEdges :: forall edgeLabel node. Graph edgeLabel node -> Set (Edge edgeLabel node)

Extracts all edges from a graph.

#mapGraph Source

mapGraph :: forall edgeLabel node edgeLabel' node'. Ord edgeLabel' => Ord node' => (edgeLabel -> edgeLabel') -> (node -> node') -> Graph edgeLabel node -> Graph edgeLabel' node'

Maps over both edge label and node types in the graph.

#isUndirected Source

isUndirected :: forall edgeLabel node. Ord node => Ord edgeLabel => Graph edgeLabel node -> Boolean

Checks if the graph is undirected (all edges have symmetric counterparts).

A graph is considered undirected if for every edge from A to B, there exists an edge from B to A with the same edge label.