module Data.IntGraph (
Node,
NodeSet,
Edge,
IntGraph(..),
empty,
addNode,
nodes,
removeNode)
where
import qualified Data.IntMap.Strict as I
import Data.IntMap.Strict (IntMap)
import qualified Data.Set as S
import Data.Set (Set)
type Node = Int
type NodeSet = Set Node
type Edge = (Node, Node)
newtype IntGraph
= IG (IntMap NodeSet)
addNode :: Node -> IntGraph -> IntGraph
addNode node (IG graph) = IG $ I.insertWith S.union node S.empty graph
nodes :: IntGraph -> [Node]
nodes (IG graph) = I.keys graph
removeNode :: Node -> IntGraph -> IntGraph
removeNode node (IG graph) = IG $ I.map (S.delete node) $ I.delete node graph
empty = IG I.empty