Commit 329c4c03 authored by Kai Zhang's avatar Kai Zhang

add nodeLabMaybe and edgeLabMaybe

parent 1cd91ff1
......@@ -69,11 +69,25 @@ class MGraph d => Graph d where
nodeLab (LGraph g _) i = read $ igraphCattributeVAS g vertexAttr i
{-# INLINE nodeLab #-}
nodeLabMaybe :: Read v => LGraph d v e -> Node -> Maybe v
nodeLabMaybe gr@(LGraph g _) i =
if igraphCattributeHasAttr g IgraphAttributeVertex vertexAttr
then Just $ nodeLab gr i
else Nothing
{-# INLINE nodeLabMaybe #-}
edgeLab :: Read e => LGraph d v e -> Edge -> e
edgeLab (LGraph g _) (fr,to) = read $ igraphCattributeEAS g edgeAttr $
igraphGetEid g fr to True True
{-# INLINE edgeLab #-}
edgeLabMaybe :: Read e => LGraph d v e -> Edge -> Maybe e
edgeLabMaybe gr@(LGraph g _) i =
if igraphCattributeHasAttr g IgraphAttributeEdge edgeAttr
then Just $ edgeLab gr i
else Nothing
{-# INLINE edgeLabMaybe #-}
edgeLabByEid :: Read e => LGraph d v e -> Int -> e
edgeLabByEid (LGraph g _) i = read $ igraphCattributeEAS g edgeAttr i
{-# INLINE edgeLabByEid #-}
......
......@@ -11,6 +11,7 @@ import System.IO.Unsafe (unsafePerformIO)
{#import IGraph.Internal.Graph #}
{#import IGraph.Internal.Data #}
{#import IGraph.Internal.Constants #}
#include "igraph/igraph.h"
......@@ -37,7 +38,7 @@ instance Storable AttributeRecord where
withStrVectorPtr vptr $ \ptr ->
{#set igraph_attribute_record_t.value #} p $ castPtr ptr
{#fun pure igraph_cattribute_has_attr as ^ { `IGraphPtr', `Int', `String' } -> `Bool' #}
{#fun pure igraph_cattribute_has_attr as ^ { `IGraphPtr', `AttributeElemtype', `String' } -> `Bool' #}
{#fun igraph_cattribute_GAN_set as ^ { `IGraphPtr', `String', `Double' } -> `Int' #}
......
......@@ -12,3 +12,5 @@ import Foreign
{#enum igraph_spincomm_update_t as SpincommUpdate {underscoreToCase} deriving (Show, Eq) #}
{#enum igraph_spinglass_implementation_t as SpinglassImplementation {underscoreToCase} deriving (Show, Eq) #}
{#enum igraph_attribute_elemtype_t as AttributeElemtype {underscoreToCase} deriving (Show, Eq) #}
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