packages feed

GraphHammer-examples-0.3: src/GraphHammer/VertexDegree.hs

{-# LANGUAGE TypeFamilies, TypeOperators, FlexibleInstances, MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}

-- |
-- Module    : GraphHammer.VertexDegree
-- Copyright : (C) 2013 Parallel Scientific Labs, LLC.
-- License   : GPLv2
--
--
-- Vertex degree analysis.
--
-- For each node calculate the number of vertices from that node.
module GraphHammer.VertexDegree(
	  VertexDegree(..)
	, vertexDegree
	) where

import GraphHammer

------------------------------------------------------------------------------------
-- Typical basic analysis.

-- | VertexDegree Tag
data VertexDegree = VertexDegree

type instance RequiredAnalyses VertexDegree = Nil

-- | Run vertex degree analysis:
--   
--   For each node calculate number of outgoing connections.
vertexDegree :: EnabledAnalysis VertexDegree wholeset => Analysis (VertexDegree :. Nil) wholeset
vertexDegree = basicAnalysis VertexDegree $ \a from to -> do
	incrementAnalysisResult a from (cst 1)
	incrementAnalysisResult a to (cst 1)
	return ()