module Data.Graph.Haggle.Internal.Basic (
Vertex(..),
Edge(..),
vertexId,
edgeId,
edgeSource,
edgeDest
) where
import Control.DeepSeq
import Data.Hashable
newtype Vertex = V Int
deriving (Eq, Ord, Show)
instance Hashable Vertex where
hashWithSalt = hashVertex
instance NFData Vertex where
rnf (V i) = i `seq` ()
hashVertex :: Int -> Vertex -> Int
hashVertex s (V i) = hashWithSalt s i
{-# INLINE hashVertex #-}
data Edge = E {-# UNPACK #-}!Int {-# UNPACK #-}!Int {-# UNPACK #-}!Int
deriving (Eq, Ord, Show)
instance Hashable Edge where
hashWithSalt = hashEdge
instance NFData Edge where
rnf e = e `seq` ()
hashEdge :: Int -> Edge -> Int
hashEdge s (E eid src dst) = s `hashWithSalt` eid `hashWithSalt` src `hashWithSalt` dst
{-# INLINE hashEdge #-}
vertexId :: Vertex -> Int
vertexId (V vid) = vid
{-# INLINE vertexId #-}
edgeId :: Edge -> Int
edgeId (E eid _ _) = eid
{-# INLINE edgeId #-}
edgeSource :: Edge -> Vertex
edgeSource (E _ s _) = V s
{-# INLINE edgeSource #-}
edgeDest :: Edge -> Vertex
edgeDest (E _ _ d) = V d
{-# INLINE edgeDest #-}