Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-igraph
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-igraph
Commits
db3879a4
Commit
db3879a4
authored
May 29, 2015
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement attributes
parent
db24923b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
14 deletions
+29
-14
.gitignore
.gitignore
+12
-0
IGraph.hs
src/IGraph.hs
+6
-4
Attribute.chs
src/IGraph/Internal/Attribute.chs
+11
-9
test.hs
test.hs
+0
-1
No files found.
.gitignore
0 → 100644
View file @
db3879a4
dist
cabal-dev
*.o
*.hi
*.chi
*.chs.h
*.swp
.virtualenv
.hsenv
.cabal-sandbox/
cabal.sandbox.config
cabal.config
src/IGraph.hs
View file @
db3879a4
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
module
IGraph
where
module
IGraph
where
import
qualified
Data.ByteString.Char8
as
B
import
qualified
Data.ByteString.Char8
as
B
import
Foreign
(
nullPtr
)
import
Foreign
hiding
(
new
)
import
IGraph.Internal.Graph
import
IGraph.Internal.Graph
import
IGraph.Internal.Initialization
import
IGraph.Internal.Initialization
...
@@ -35,9 +35,11 @@ instance Graph LGraph U where
...
@@ -35,9 +35,11 @@ instance Graph LGraph U where
addLEdges
name
es
(
LGraph
g
)
=
do
addLEdges
name
es
(
LGraph
g
)
=
do
vec
<-
listToVector
$
concat
xs
vec
<-
listToVector
$
concat
xs
igraphAddEdges
g
vec
nullPtr
let
attr
=
makeAttributeRecord
name
vs
value
<-
listToStrVector
$
map
(
B
.
pack
.
show
)
vs
alloca
$
\
ptr
->
do
igraphCattributeEASSetv
g
name
value
poke
ptr
attr
vptr
<-
listToVectorP
[
castPtr
ptr
]
igraphAddEdges
g
vec
(
castPtr
vptr
)
return
()
return
()
where
where
(
xs
,
vs
)
=
unzip
$
map
(
\
(
a
,
b
,
v
)
->
([
fromIntegral
a
,
fromIntegral
b
],
v
)
)
es
(
xs
,
vs
)
=
unzip
$
map
(
\
(
a
,
b
,
v
)
->
([
fromIntegral
a
,
fromIntegral
b
],
v
)
)
es
...
...
src/IGraph/Internal/Attribute.chs
View file @
db3879a4
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Internal.Attribute where
module IGraph.Internal.Attribute where
import
Data.Serialize (Serialize, encode)
import
qualified Data.ByteString.Char8 as B
import Control.Monad
import Control.Monad
import Control.Applicative
import Control.Applicative
import Foreign
import Foreign
...
@@ -15,22 +15,24 @@ import System.IO.Unsafe (unsafePerformIO)
...
@@ -15,22 +15,24 @@ import System.IO.Unsafe (unsafePerformIO)
#include "igraph/igraph.h"
#include "igraph/igraph.h"
#include "cbits/igraph.c"
#include "cbits/igraph.c"
makeAttributeRecord :: Serialize a => String -> [a] -> AttributeRecord
makeAttributeRecord :: Show a => String -> [a] -> AttributeRecord
makeAttributeRecord name xs = AttributeRecord name 2 value
makeAttributeRecord name xs = unsafePerformIO $ do
where
ptr <- newCAString name
value = unsafePerformIO $ listToStrVector $ map encode xs
value <- listToStrVector $ map (B.pack . show) xs
return $ AttributeRecord ptr 2 value
data AttributeRecord = AttributeRecord String Int StrVectorPtr
data AttributeRecord = AttributeRecord CString Int StrVectorPtr
deriving (Show)
instance Storable AttributeRecord where
instance Storable AttributeRecord where
sizeOf _ = {#sizeof igraph_attribute_record_t #}
sizeOf _ = {#sizeof igraph_attribute_record_t #}
alignment _ = {#alignof igraph_attribute_record_t #}
alignment _ = {#alignof igraph_attribute_record_t #}
peek p = AttributeRecord
peek p = AttributeRecord
<$> (
({#get igraph_attribute_record_t->name #} p) >>= peekCString
)
<$> (
{#get igraph_attribute_record_t->name #} p
)
<*> liftM fromIntegral ({#get igraph_attribute_record_t->type #} p)
<*> liftM fromIntegral ({#get igraph_attribute_record_t->type #} p)
<*> liftM castPtr ({#get igraph_attribute_record_t->value #} p)
<*> liftM castPtr ({#get igraph_attribute_record_t->value #} p)
poke p (AttributeRecord name t vptr) = do
poke p (AttributeRecord name t vptr) = do
liftM ({#set igraph_attribute_record_t.name #} p) $ newCString
name
{#set igraph_attribute_record_t.name #} p
name
{#set igraph_attribute_record_t.type #} p $ fromIntegral t
{#set igraph_attribute_record_t.type #} p $ fromIntegral t
{#set igraph_attribute_record_t.value #} p $ castPtr vptr
{#set igraph_attribute_record_t.value #} p $ castPtr vptr
...
@@ -46,4 +48,4 @@ instance Storable AttributeRecord where
...
@@ -46,4 +48,4 @@ instance Storable AttributeRecord where
{#fun igraph_cattribute_EAS_setv as ^ { `IGraphPtr', `String', `StrVectorPtr' } -> `Int' #}
{#fun igraph_cattribute_EAS_setv as ^ { `IGraphPtr', `String', `StrVectorPtr' } -> `Int' #}
{#fun c_test as ^ {} -> `Ptr AttributeRecord' castPtr #}
test.hs
View file @
db3879a4
...
@@ -12,6 +12,5 @@ import Foreign.Ptr
...
@@ -12,6 +12,5 @@ import Foreign.Ptr
main
=
do
main
=
do
let
g
=
new
5
::
LGraph
U
String
Double
let
g
=
new
5
::
LGraph
U
String
Double
addLEdges
"weight"
[(
1
,
2
,
1.1234
),(
3
,
4
,
pi
)]
g
addLEdges
"weight"
[(
1
,
2
,
1.1234
),(
3
,
4
,
pi
)]
g
print
$
igraphCattributeHasAttr
(
_graph
g
)
2
"weight"
let
s
=
igraphCattributeEAS
(
_graph
g
)
"weight"
1
let
s
=
igraphCattributeEAS
(
_graph
g
)
"weight"
1
print
$
(
read
s
::
Double
)
print
$
(
read
s
::
Double
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment