]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Viz/Graph/IGraph.hs
[ELEVE] Specifications to test to fix concurrent multi-terms.
[gargantext.git] / src / Gargantext / Viz / Graph / IGraph.hs
1 {-| Module : Gargantext.Viz.Graph.IGraph
2 Description : IGraph main functions used in Garg
3 Copyright : (c) CNRS, 2017-Present
4 License : AGPL + CECILL v3
5 Maintainer : team@gargantext.org
6 Stability : experimental
7 Portability : POSIX
8
9 Main IGraph funs/types to ease portability with FGL.
10
11 -}
12
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE DataKinds #-}
15
16 module Gargantext.Viz.Graph.IGraph where
17
18 import Data.Serialize (Serialize)
19 import Data.Singletons (SingI)
20 import Gargantext.Prelude
21 import IGraph hiding (mkGraph, neighbors, edges, nodes, Node, Graph)
22 import qualified IGraph as IG
23 import qualified Data.List as List
24
25 ------------------------------------------------------------------
26 -- | Main Types
27 type Graph_Undirected = IG.Graph 'U () ()
28 type Graph_Directed = IG.Graph 'D () ()
29
30 type Node = IG.Node
31 type Graph = IG.Graph
32
33 ------------------------------------------------------------------
34 -- | Main Functions
35
36 mkGraph :: (SingI d, Ord v,
37 Serialize v, Serialize e) =>
38 [v] -> [LEdge e] -> IG.Graph d v e
39 mkGraph = IG.mkGraph
40
41 neighbors :: IG.Graph d v e -> IG.Node -> [Node]
42 neighbors = IG.neighbors
43
44 edges :: IG.Graph d v e -> [Edge]
45 edges = IG.edges
46
47 nodes :: IG.Graph d v e -> [Node]
48 nodes = IG.nodes
49
50 ------------------------------------------------------------------
51 -- | Main sugared functions
52
53 mkGraphUfromEdges :: [(Int, Int)] -> Graph_Undirected
54 mkGraphUfromEdges es = mkGraph (List.replicate n ()) $ zip es $ repeat ()
55 where
56 (a,b) = List.unzip es
57 n = List.length (List.nub $ a <> b)
58
59 mkGraphDfromEdges :: [(Int, Int)] -> Graph_Directed
60 mkGraphDfromEdges = undefined
61
62