Commit c6153226 authored by Kai Zhang's avatar Kai Zhang

add triadCensus

parent 1bb94810
......@@ -31,6 +31,7 @@ library
IGraph.Internal.Isomorphism
IGraph.Internal.Selector
IGraph.Internal.Structure
IGraph.Internal.Motif
IGraph.Internal.Clique
IGraph.Internal.Community
IGraph.Internal.Layout
......
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Internal.Motif where
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import Foreign
import Foreign.C.Types
{#import IGraph.Internal.Graph #}
{#import IGraph.Internal.Selector #}
{#import IGraph.Internal.Constants #}
{#import IGraph.Internal.Data #}
#include "igraph/igraph.h"
{#fun igraph_triad_census as ^ { `IGraphPtr'
, `VectorPtr' } -> `Int' #}
module IGraph.Motif
(triad) where
( triad
, triadCensus
) where
import Data.Hashable (Hashable)
import System.IO.Unsafe (unsafePerformIO)
import IGraph
import IGraph.Internal.Motif
import IGraph.Internal.Data
-- | Every triple of vertices in a directed graph
-- 003: A, B, C, the empty graph.
......@@ -40,6 +47,11 @@ triad = map make xs
, [(0,1), (1,2), (2,1), (0,2), (2,0)]
, [(0,1), (1,2), (1,2), (2,1), (0,2), (2,0)]
]
make :: [(Int, Int)] -> LGraph D () ()
make xs = mkGraph (replicate (length xs) ()) $ zip xs $ repeat ()
make :: [(Int, Int)] -> LGraph D () ()
make xs = mkGraph (replicate (length xs) ()) $ zip xs $ repeat ()
triadCensus :: (Hashable v, Eq v, Read v) => LGraph d v e -> [Int]
triadCensus gr = unsafePerformIO $ do
vptr <- igraphVectorNew 0
igraphTriadCensus (_graph gr) vptr
map truncate <$> vectorPtrToList vptr
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment