1
1
module StaticGraphs
2
2
3
3
using LightGraphs
4
+ using JLD2
4
5
5
6
import Base:
6
7
convert, eltype, show, == , Pair, Tuple, in, copy, length, start, next, done, issubset, zero, one,
@@ -10,7 +11,7 @@ import LightGraphs:
10
11
_NI, _insert_and_dedup!, AbstractEdge, AbstractEdgeIter,
11
12
src, dst, edgetype, nv, ne, vertices, edges, is_directed,
12
13
has_vertex, has_edge, in_neighbors, out_neighbors,
13
- indegree, outdegree, degree, insorted,
14
+ indegree, outdegree, degree, insorted, squash,
14
15
15
16
AbstractGraphFormat, loadgraph, savegraph
16
17
39
40
40
41
include (" utils.jl" )
41
42
42
- const StaticEdgeIter{G} = LightGraphs. SimpleGraphs. SimpleEdgeIter{G}
43
- const AbstractStaticEdge = AbstractSimpleEdge
44
- const StaticEdge = SimpleEdge
43
+ const AbstractStaticEdge{T} = AbstractSimpleEdge{T}
44
+ const StaticEdge{T} = SimpleEdge{T}
45
45
46
46
"""
47
47
AbstractStaticGraph
@@ -50,7 +50,11 @@ An abstract type representing a simple graph structure.
50
50
AbstractStaticGraphs must have the following elements:
51
51
- weightmx::AbstractSparseMatrix{Real}
52
52
"""
53
- abstract type AbstractStaticGraph <: AbstractSimpleGraph end
53
+ abstract type AbstractStaticGraph{T<: Integer , U<: Integer } <: AbstractSimpleGraph{T} end
54
+
55
+ vectype (g:: AbstractStaticGraph{T, U} ) where T where U = T
56
+ indtype (g:: AbstractStaticGraph{T, U} ) where T where U = U
57
+ eltype (x:: AbstractStaticGraph ) = vectype (x)
54
58
55
59
function show (io:: IO , g:: AbstractStaticGraph )
56
60
if is_directed (g)
@@ -59,9 +63,9 @@ function show(io::IO, g::AbstractStaticGraph)
59
63
dir = " undirected"
60
64
end
61
65
if nv (g) == 0
62
- print (io, " empty $dir simple static $( eltype (g)) graph" )
66
+ print (io, " empty $dir simple static { $( vectype (g)), $( indtype (g)) } graph" )
63
67
else
64
- print (io, " {$(nv (g)) , $(ne (g)) } $dir simple static $( eltype (g)) graph" )
68
+ print (io, " {$(nv (g)) , $(ne (g)) } $dir simple static { $( vectype (g)), $( indtype (g)) } graph" )
65
69
end
66
70
end
67
71
76
80
return fastview (g. f_vec, r)
77
81
end
78
82
79
- nv (g:: AbstractStaticGraph ) = length (g. f_ind) - 1
80
- vertices (g:: AbstractStaticGraph ) = one (eltype (g) ): nv (g)
81
- eltype (x :: AbstractStaticGraph ) = eltype (x . f_vec)
83
+ nv (g:: AbstractStaticGraph{T, U} ) where T where U = T ( length (g. f_ind) - 1 )
84
+ vertices (g:: AbstractStaticGraph{T, U} ) where T where U = one (T ): nv (g)
85
+
82
86
83
87
has_edge (g:: AbstractStaticGraph , e:: AbstractStaticEdge ) =
84
- insorted (dst (e), neighbors (g, src (e)))
88
+ insorted (dst (e), out_neighbors (g, src (e)))
85
89
86
- edgetype (g:: AbstractStaticGraph ) = StaticEdge
90
+ edgetype (g:: AbstractStaticGraph{T} ) where T = StaticEdge{T}
87
91
edges (g:: AbstractStaticGraph ) = StaticEdgeIter (g)
88
92
89
93
has_vertex (g:: AbstractStaticGraph , v:: Integer ) = v in vertices (g)
@@ -104,4 +108,10 @@ include("persistence.jl")
104
108
const SGraph = StaticGraph
105
109
const SDiGraph = StaticDiGraph
106
110
111
+ const StaticEdgeIter{G} = LightGraphs. SimpleGraphs. SimpleEdgeIter{G}
112
+
113
+ eltype (:: Type{StaticEdgeIter{StaticGraph{T, U}}} ) where T where U = StaticGraphEdge{T}
114
+ eltype (:: Type{StaticEdgeIter{StaticDiGraph{T, U}}} ) where T where U = StaticDiGraphEdge{T}
115
+
116
+
107
117
end # module
0 commit comments