module NetSpider.Snapshot.Internal
( SnapshotGraph,
SnapshotLink(..),
linkNodeTuple,
linkNodePair,
SnapshotNode(..)
) where
import Data.Bifunctor (Bifunctor(..))
import NetSpider.Pair (Pair(..))
import NetSpider.Timestamp (Timestamp)
type SnapshotGraph n na la = ([SnapshotNode n na], [SnapshotLink n la])
data SnapshotLink n la =
SnapshotLink
{ _sourceNode :: n,
_destinationNode :: n,
_isDirected :: Bool,
_linkTimestamp :: Timestamp,
_linkAttributes :: la
}
deriving (Show,Eq)
instance (Ord n, Eq la) => Ord (SnapshotLink n la) where
compare l r = compare (linkNodeTuple l) (linkNodeTuple r)
instance Functor (SnapshotLink n) where
fmap f l = l { _linkAttributes = f $ _linkAttributes l }
instance Bifunctor SnapshotLink where
bimap fn fla l = l { _linkAttributes = fla $ _linkAttributes l,
_sourceNode = fn $ _sourceNode l,
_destinationNode = fn $ _destinationNode l
}
linkNodeTuple :: SnapshotLink n la -> (n, n)
linkNodeTuple link = (_sourceNode link, _destinationNode link)
linkNodePair :: SnapshotLink n la -> Pair n
linkNodePair = Pair . linkNodeTuple
data SnapshotNode n na =
SnapshotNode
{ _nodeId :: n,
_isOnBoundary :: Bool,
_nodeTimestamp :: Maybe Timestamp,
_nodeAttributes :: Maybe na
}
deriving (Show,Eq)
instance (Ord n, Eq na) => Ord (SnapshotNode n na) where
compare l r = compare (_nodeId l) (_nodeId r)
instance Functor (SnapshotNode n) where
fmap f n = n { _nodeAttributes = fmap f $ _nodeAttributes n }
instance Bifunctor SnapshotNode where
bimap fn fna n = n { _nodeAttributes = fmap fna $ _nodeAttributes n,
_nodeId = fn $ _nodeId n
}