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
10860cd9
Commit
10860cd9
authored
Aug 12, 2015
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement freeze and delEdges
parent
54994870
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
11 deletions
+53
-11
haskell-igraph.cabal
haskell-igraph.cabal
+10
-10
IGraph.hs
src/IGraph.hs
+6
-1
Selector.chs
src/IGraph/Internal/Selector.chs
+5
-0
Mutable.hs
src/IGraph/Mutable.hs
+19
-0
Basic.hs
tests/Test/Basic.hs
+13
-0
No files found.
haskell-igraph.cabal
View file @
10860cd9
-- Initial igraph-bindings.cabal generated by cabal init. For further
-- Initial igraph-bindings.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
-- documentation, see http://haskell.org/cabal/users-guide/
name: haskell-igraph
name: haskell-igraph
version: 0.1.0
version: 0.1.0
-- synopsis:
-- synopsis:
-- description:
-- description:
license: MIT
license: MIT
license-file: LICENSE
license-file: LICENSE
author: Kai Zhang
author: Kai Zhang
maintainer: kai@kzhang.org
maintainer: kai@kzhang.org
-- copyright:
-- copyright:
category: Math
category: Math
build-type: Simple
build-type: Simple
extra-source-files: cbits
extra-source-files: cbits
/haskelligraph.c
cabal-version: >=1.22
cabal-version: >=1.22
library
library
exposed-modules:
exposed-modules:
IGraph.Internal.Initialization
IGraph.Internal.Initialization
IGraph.Internal.Constants
IGraph.Internal.Constants
IGraph.Internal.Arpack
IGraph.Internal.Arpack
...
@@ -35,8 +35,8 @@ library
...
@@ -35,8 +35,8 @@ library
IGraph.Community
IGraph.Community
IGraph.Read
IGraph.Read
IGraph.Layout
IGraph.Layout
-- other-modules:
-- other-modules:
-- other-extensions:
-- other-extensions:
build-depends:
build-depends:
base >=4.0 && <5.0
base >=4.0 && <5.0
, bytestring >=0.9
, bytestring >=0.9
...
@@ -58,12 +58,12 @@ test-suite tests
...
@@ -58,12 +58,12 @@ test-suite tests
type: exitcode-stdio-1.0
type: exitcode-stdio-1.0
hs-source-dirs: tests
hs-source-dirs: tests
main-is: test.hs
main-is: test.hs
other-modules:
other-modules:
Test.Basic
Test.Basic
Test.Utils
Test.Utils
default-language: Haskell2010
default-language: Haskell2010
build-depends:
build-depends:
base
base
, haskell-igraph
, haskell-igraph
, tasty
, tasty
...
...
src/IGraph.hs
View file @
10860cd9
...
@@ -9,6 +9,7 @@ module IGraph
...
@@ -9,6 +9,7 @@ module IGraph
,
fromLabeledEdges
,
fromLabeledEdges
,
unsafeFreeze
,
unsafeFreeze
,
freeze
,
unsafeThaw
,
unsafeThaw
,
thaw
,
thaw
...
@@ -101,6 +102,11 @@ unsafeFreeze (MLGraph g) = return $ LGraph g labToId
...
@@ -101,6 +102,11 @@ unsafeFreeze (MLGraph g) = return $ LGraph g labToId
nV
=
igraphVcount
g
nV
=
igraphVcount
g
labels
=
map
(
read
.
igraphCattributeVAS
g
vertexAttr
)
[
0
..
nV
-
1
]
labels
=
map
(
read
.
igraphCattributeVAS
g
vertexAttr
)
[
0
..
nV
-
1
]
freeze
::
(
Hashable
v
,
Eq
v
,
Read
v
,
PrimMonad
m
)
=>
MLGraph
(
PrimState
m
)
d
v
e
->
m
(
LGraph
d
v
e
)
freeze
(
MLGraph
g
)
=
do
g'
<-
unsafePrimToPrim
$
igraphCopy
g
unsafeFreeze
(
MLGraph
g'
)
unsafeThaw
::
PrimMonad
m
=>
LGraph
d
v
e
->
m
(
MLGraph
(
PrimState
m
)
d
v
e
)
unsafeThaw
::
PrimMonad
m
=>
LGraph
d
v
e
->
m
(
MLGraph
(
PrimState
m
)
d
v
e
)
unsafeThaw
(
LGraph
g
_
)
=
return
$
MLGraph
g
unsafeThaw
(
LGraph
g
_
)
=
return
$
MLGraph
g
...
@@ -130,4 +136,3 @@ pre gr i = unsafePerformIO $ do
...
@@ -130,4 +136,3 @@ pre gr i = unsafePerformIO $ do
igraphVsAdj
vs
i
IgraphIn
igraphVsAdj
vs
i
IgraphIn
vit
<-
igraphVitNew
(
_graph
gr
)
vs
vit
<-
igraphVitNew
(
_graph
gr
)
vs
vitToList
vit
vitToList
vit
src/IGraph/Internal/Selector.chs
View file @
10860cd9
...
@@ -80,6 +80,8 @@ vitToList vit = do
...
@@ -80,6 +80,8 @@ vitToList vit = do
{#fun igraph_es_all as ^ { +, `EdgeOrderType' } -> `IGraphEsPtr' #}
{#fun igraph_es_all as ^ { +, `EdgeOrderType' } -> `IGraphEsPtr' #}
{# fun igraph_es_vector as ^ { +, `VectorPtr' } -> `IGraphEsPtr' #}
-- Edge iterator
-- Edge iterator
...
@@ -124,3 +126,6 @@ eitToList eit = do
...
@@ -124,3 +126,6 @@ eitToList eit = do
acc <- eitToList eit
acc <- eitToList eit
return $ cur : acc
return $ cur : acc
-- delete edges
{# fun igraph_delete_edges as ^ { `IGraphPtr', %`IGraphEsPtr' } -> `Int' #}
src/IGraph/Mutable.hs
View file @
10860cd9
...
@@ -5,6 +5,7 @@ import Foreign
...
@@ -5,6 +5,7 @@ import Foreign
import
Control.Monad.Primitive
import
Control.Monad.Primitive
import
IGraph.Internal.Graph
import
IGraph.Internal.Graph
import
IGraph.Internal.Selector
import
IGraph.Internal.Data
import
IGraph.Internal.Data
import
IGraph.Internal.Attribute
import
IGraph.Internal.Attribute
import
IGraph.Internal.Initialization
import
IGraph.Internal.Initialization
...
@@ -44,6 +45,8 @@ class MGraph d where
...
@@ -44,6 +45,8 @@ class MGraph d where
addLEdges
::
(
PrimMonad
m
,
Show
e
)
=>
[
LEdge
e
]
->
MLGraph
(
PrimState
m
)
d
v
e
->
m
()
addLEdges
::
(
PrimMonad
m
,
Show
e
)
=>
[
LEdge
e
]
->
MLGraph
(
PrimState
m
)
d
v
e
->
m
()
delEdges
::
PrimMonad
m
=>
[(
Int
,
Int
)]
->
MLGraph
(
PrimState
m
)
d
v
e
->
m
()
data
U
data
U
data
D
data
D
...
@@ -66,6 +69,14 @@ instance MGraph U where
...
@@ -66,6 +69,14 @@ instance MGraph U where
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
delEdges
es
(
MLGraph
g
)
=
unsafePrimToPrim
$
do
vptr
<-
listToVector
$
map
fromIntegral
eids
esptr
<-
igraphEsVector
vptr
igraphDeleteEdges
g
esptr
return
()
where
eids
=
flip
map
es
$
\
(
fr
,
to
)
->
igraphGetEid
g
fr
to
False
True
instance
MGraph
D
where
instance
MGraph
D
where
new
n
=
unsafePrimToPrim
$
igraphInit
>>=
igraphNew
n
True
>>=
return
.
MLGraph
new
n
=
unsafePrimToPrim
$
igraphInit
>>=
igraphNew
n
True
>>=
return
.
MLGraph
...
@@ -84,3 +95,11 @@ instance MGraph D where
...
@@ -84,3 +95,11 @@ instance MGraph D where
withVectorPPtr
vptr
$
\
p
->
igraphAddEdges
g
vec
$
castPtr
p
withVectorPPtr
vptr
$
\
p
->
igraphAddEdges
g
vec
$
castPtr
p
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
delEdges
es
(
MLGraph
g
)
=
unsafePrimToPrim
$
do
vptr
<-
listToVector
$
map
fromIntegral
eids
esptr
<-
igraphEsVector
vptr
igraphDeleteEdges
g
esptr
return
()
where
eids
=
flip
map
es
$
\
(
fr
,
to
)
->
igraphGetEid
g
fr
to
True
True
tests/Test/Basic.hs
View file @
10860cd9
...
@@ -2,6 +2,7 @@ module Test.Basic
...
@@ -2,6 +2,7 @@ module Test.Basic
(
tests
(
tests
)
where
)
where
import
Control.Monad.ST
import
Test.Tasty
import
Test.Tasty
import
Test.Tasty.HUnit
import
Test.Tasty.HUnit
import
Test.Utils
import
Test.Utils
...
@@ -9,10 +10,12 @@ import System.IO.Unsafe
...
@@ -9,10 +10,12 @@ import System.IO.Unsafe
import
Data.List
import
Data.List
import
IGraph
import
IGraph
import
IGraph.Mutable
tests
::
TestTree
tests
::
TestTree
tests
=
testGroup
"Basic tests"
tests
=
testGroup
"Basic tests"
[
graphCreation
[
graphCreation
,
graphEdit
]
]
graphCreation
::
TestTree
graphCreation
::
TestTree
...
@@ -26,3 +29,13 @@ graphCreation = testGroup "Graph creation"
...
@@ -26,3 +29,13 @@ graphCreation = testGroup "Graph creation"
edgeList
=
sort
$
unsafePerformIO
$
randEdges
1000
100
edgeList
=
sort
$
unsafePerformIO
$
randEdges
1000
100
gr
=
mkGraph
(
100
,
Nothing
)
(
edgeList
,
Nothing
)
::
LGraph
D
()
()
gr
=
mkGraph
(
100
,
Nothing
)
(
edgeList
,
Nothing
)
::
LGraph
D
()
()
simple
=
mkGraph
(
3
,
Nothing
)
([(
0
,
1
),(
1
,
2
),(
2
,
0
)],
Nothing
)
::
LGraph
D
()
()
simple
=
mkGraph
(
3
,
Nothing
)
([(
0
,
1
),(
1
,
2
),(
2
,
0
)],
Nothing
)
::
LGraph
D
()
()
graphEdit
::
TestTree
graphEdit
=
testGroup
"Graph editing"
[
testCase
""
$
[(
1
,
2
)]
@=?
(
sort
$
edges
simple'
)
]
where
simple
=
mkGraph
(
3
,
Nothing
)
([(
0
,
1
),(
1
,
2
),(
2
,
0
)],
Nothing
)
::
LGraph
U
()
()
simple'
=
runST
$
do
g
<-
thaw
simple
delEdges
[(
0
,
1
),(
0
,
2
)]
g
freeze
g
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