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
62fb8045
Commit
62fb8045
authored
Jun 05, 2015
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add directed graph instance
parent
67d1be7c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
9 deletions
+37
-9
haskell-igraph.cabal
haskell-igraph.cabal
+3
-0
IGraph.hs
src/IGraph.hs
+8
-0
Mutable.hs
src/IGraph/Mutable.hs
+26
-9
No files found.
haskell-igraph.cabal
View file @
62fb8045
...
@@ -59,6 +59,8 @@ test-suite tests
...
@@ -59,6 +59,8 @@ test-suite tests
hs-source-dirs: tests
hs-source-dirs: tests
main-is: test.hs
main-is: test.hs
other-modules:
other-modules:
Test.Basic
Test.Utils
default-language: Haskell2010
default-language: Haskell2010
build-depends:
build-depends:
...
@@ -67,6 +69,7 @@ test-suite tests
...
@@ -67,6 +69,7 @@ test-suite tests
, tasty
, tasty
, tasty-golden
, tasty-golden
, tasty-hunit
, tasty-hunit
, random
source-repository head
source-repository head
type: git
type: git
...
...
src/IGraph.hs
View file @
62fb8045
...
@@ -46,12 +46,19 @@ class MGraph d => Graph d where
...
@@ -46,12 +46,19 @@ class MGraph d => Graph d where
nEdges
::
LGraph
d
v
e
->
Int
nEdges
::
LGraph
d
v
e
->
Int
nEdges
(
LGraph
g
_
)
=
igraphEcount
g
nEdges
(
LGraph
g
_
)
=
igraphEcount
g
{-
edges :: LGraph d v e -> [Edge]
edges :: LGraph d v e -> [Edge]
edges (LGraph g _) = unsafePerformIO $ do
edges (LGraph g _) = unsafePerformIO $ do
es <- igraphEsAll IgraphEdgeorderFrom
es <- igraphEsAll IgraphEdgeorderFrom
eit <- igraphEitNew g es
eit <- igraphEitNew g es
eids <- eitToList eit
eids <- eitToList eit
mapM (igraphEdge g) eids
mapM (igraphEdge g) eids
-}
edges
::
LGraph
d
v
e
->
[
Edge
]
edges
gr
@
(
LGraph
g
_
)
=
unsafePerformIO
$
mapM
(
igraphEdge
g
)
[
0
..
n
-
1
]
where
n
=
nEdges
gr
nodeLab
::
Read
v
=>
LGraph
d
v
e
->
Node
->
v
nodeLab
::
Read
v
=>
LGraph
d
v
e
->
Node
->
v
nodeLab
(
LGraph
g
_
)
i
=
read
$
igraphCattributeVAS
g
vertexAttr
i
nodeLab
(
LGraph
g
_
)
i
=
read
$
igraphCattributeVAS
g
vertexAttr
i
...
@@ -64,6 +71,7 @@ class MGraph d => Graph d where
...
@@ -64,6 +71,7 @@ class MGraph d => Graph d where
instance
Graph
U
where
instance
Graph
U
where
instance
Graph
D
where
mkGraph
::
(
Graph
d
,
Hashable
v
,
Read
v
,
Eq
v
,
Show
v
,
Show
e
)
=>
(
Node
,
Maybe
[
v
])
->
([
Edge
],
Maybe
[
e
])
->
LGraph
d
v
e
mkGraph
::
(
Graph
d
,
Hashable
v
,
Read
v
,
Eq
v
,
Show
v
,
Show
e
)
=>
(
Node
,
Maybe
[
v
])
->
([
Edge
],
Maybe
[
e
])
->
LGraph
d
v
e
...
...
src/IGraph/Mutable.hs
View file @
62fb8045
...
@@ -25,11 +25,20 @@ class MGraph d where
...
@@ -25,11 +25,20 @@ class MGraph d where
new
::
PrimMonad
m
=>
Int
->
m
(
MLGraph
(
PrimState
m
)
d
v
e
)
new
::
PrimMonad
m
=>
Int
->
m
(
MLGraph
(
PrimState
m
)
d
v
e
)
addNodes
::
PrimMonad
m
=>
Int
->
MLGraph
(
PrimState
m
)
d
v
e
->
m
()
addNodes
::
PrimMonad
m
=>
Int
->
MLGraph
(
PrimState
m
)
d
v
e
->
m
()
addNodes
n
(
MLGraph
g
)
=
unsafePrimToPrim
$
igraphAddVertices
g
n
nullPtr
addLNodes
::
(
Show
v
,
PrimMonad
m
)
addLNodes
::
(
Show
v
,
PrimMonad
m
)
=>
Int
-- ^ the number of new vertices add to the graph
=>
Int
-- ^ the number of new vertices add to the graph
->
[
v
]
-- ^ vertices' labels
->
[
v
]
-- ^ vertices' labels
->
MLGraph
(
PrimState
m
)
d
v
e
->
m
()
->
MLGraph
(
PrimState
m
)
d
v
e
->
m
()
addLNodes
n
labels
(
MLGraph
g
)
|
n
/=
length
labels
=
error
"addLVertices: incorrect number of labels"
|
otherwise
=
unsafePrimToPrim
$
do
let
attr
=
makeAttributeRecord
vertexAttr
labels
alloca
$
\
ptr
->
do
poke
ptr
attr
vptr
<-
listToVectorP
[
castPtr
ptr
]
withVectorPPtr
vptr
$
\
p
->
igraphAddVertices
g
n
$
castPtr
p
addEdges
::
PrimMonad
m
=>
[(
Int
,
Int
)]
->
MLGraph
(
PrimState
m
)
d
v
e
->
m
()
addEdges
::
PrimMonad
m
=>
[(
Int
,
Int
)]
->
MLGraph
(
PrimState
m
)
d
v
e
->
m
()
...
@@ -41,16 +50,24 @@ data D
...
@@ -41,16 +50,24 @@ data D
instance
MGraph
U
where
instance
MGraph
U
where
new
n
=
unsafePrimToPrim
$
igraphInit
>>=
igraphNew
n
False
>>=
return
.
MLGraph
new
n
=
unsafePrimToPrim
$
igraphInit
>>=
igraphNew
n
False
>>=
return
.
MLGraph
addNodes
n
(
MLGraph
g
)
=
unsafePrimToPrim
$
igraphAddVertices
g
n
nullPtr
addEdges
es
(
MLGraph
g
)
=
unsafePrimToPrim
$
do
vec
<-
listToVector
xs
igraphAddEdges
g
vec
nullPtr
where
xs
=
concatMap
(
\
(
a
,
b
)
->
[
fromIntegral
a
,
fromIntegral
b
]
)
es
addLNodes
n
labels
(
MLGraph
g
)
addLEdges
es
(
MLGraph
g
)
=
unsafePrimToPrim
$
do
|
n
/=
length
labels
=
error
"addLVertices: incorrect number of labels"
vec
<-
listToVector
$
concat
xs
|
otherwise
=
unsafePrimToPrim
$
do
let
attr
=
makeAttributeRecord
edgeAttr
vs
let
attr
=
makeAttributeRecord
vertexAttr
labels
alloca
$
\
ptr
->
do
alloca
$
\
ptr
->
do
poke
ptr
attr
poke
ptr
attr
vptr
<-
listToVectorP
[
castPtr
ptr
]
vptr
<-
listToVectorP
[
castPtr
ptr
]
withVectorPPtr
vptr
$
\
p
->
igraphAddEdges
g
vec
$
castPtr
p
withVectorPPtr
vptr
$
\
p
->
igraphAddVertices
g
n
$
castPtr
p
where
(
xs
,
vs
)
=
unzip
$
map
(
\
(
a
,
b
,
v
)
->
([
fromIntegral
a
,
fromIntegral
b
],
v
)
)
es
instance
MGraph
D
where
new
n
=
unsafePrimToPrim
$
igraphInit
>>=
igraphNew
n
True
>>=
return
.
MLGraph
addEdges
es
(
MLGraph
g
)
=
unsafePrimToPrim
$
do
addEdges
es
(
MLGraph
g
)
=
unsafePrimToPrim
$
do
vec
<-
listToVector
xs
vec
<-
listToVector
xs
...
...
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