24
24
ne (g:: StaticDiGraph{T, U} ) where T where U = U (length (g. f_vec))
25
25
26
26
# sorted src, dst vectors for forward and backward edgelists.
27
- function StaticDiGraph (n_v , f_ss:: AbstractVector , f_ds:: AbstractVector , b_ss:: AbstractVector , b_ds:: AbstractVector )
27
+ function StaticDiGraph (nvtx :: I , f_ss:: AbstractVector{F} , f_ds:: AbstractVector{D} , b_ss:: AbstractVector{B} , b_ds:: AbstractVector{S} ) where {I <: Integer ,S <: Integer ,D <: Integer ,B <: Integer ,F <: Integer }
28
28
length (f_ss) == length (f_ds) == length (b_ss) == length (b_ds) || error (" source and destination vectors must be equal length" )
29
- (n_v == 0 || length (f_ss) == 0 ) && return StaticDiGraph (UInt8[], UInt8[1 ], UInt8[], UInt8[1 ])
30
- f_ind = [searchsortedfirst (f_ss, x) for x in 1 : n_v ]
29
+ (nvtx == 0 || length (f_ss) == 0 ) && return StaticDiGraph (UInt8[], UInt8[1 ], UInt8[], UInt8[1 ])
30
+ f_ind = [searchsortedfirst (f_ss, x) for x in Base . OneTo (nvtx) ]
31
31
push! (f_ind, length (f_ss)+ 1 )
32
- b_ind = [searchsortedfirst (b_ss, x) for x in 1 : n_v ]
32
+ b_ind = [searchsortedfirst (b_ss, x) for x in Base . OneTo (nvtx) ]
33
33
push! (b_ind, length (b_ss)+ 1 )
34
34
T = mintype (maximum (f_ds))
35
35
U = mintype (f_ind[end ])
@@ -42,21 +42,25 @@ function StaticDiGraph(n_v, f_ss::AbstractVector, f_ds::AbstractVector, b_ss::Ab
42
42
end
43
43
44
44
# sorted src, dst tuples for forward and backward
45
- function StaticDiGraph (n_v , f_sd:: Vector{Tuple{T, T}} , b_sd:: Vector{Tuple{T, T}} ) where T <: Integer
45
+ function StaticDiGraph (nvtx :: I , f_sd:: Vector{Tuple{T, T}} , b_sd:: Vector{Tuple{T, T}} ) where {T <: Integer ,I <: Integer }
46
46
f_ss = [x[1 ] for x in f_sd]
47
47
f_ds = [x[2 ] for x in f_sd]
48
48
b_ss = [x[1 ] for x in b_sd]
49
49
b_ds = [x[2 ] for x in b_sd]
50
50
51
- StaticDiGraph (n_v , f_ss, f_ds, b_ss, b_ds)
51
+ return StaticDiGraph (nvtx , f_ss, f_ds, b_ss, b_ds)
52
52
end
53
53
54
54
function StaticDiGraph (g:: LightGraphs.SimpleGraphs.SimpleDiGraph )
55
55
ne (g) == 0 && return StaticDiGraph (nv (g), Array {Tuple{UInt8, UInt8},1} (), Array {Tuple{UInt8, UInt8},1} ())
56
56
f_sd = [Tuple (e) for e in edges (g)]
57
57
b_sd = sort ([Tuple (reverse (e)) for e in edges (g)])
58
58
59
- StaticDiGraph (nv (g), f_sd, b_sd)
59
+ return StaticDiGraph (nv (g), f_sd, b_sd)
60
+ end
61
+
62
+ function StaticDiGraph ()
63
+ return StaticDiGraph (UInt8[], UInt8[1 ], UInt8[], UInt8[1 ])
60
64
end
61
65
62
66
function StaticDiGraph {T, U} (s:: StaticDiGraph ) where T <: Integer where U <: Integer
@@ -68,7 +72,6 @@ function StaticDiGraph{T, U}(s::StaticDiGraph) where T <: Integer where U <: Int
68
72
end
69
73
70
74
71
- #
72
75
== (g:: StaticDiGraph , h:: StaticDiGraph ) = g. f_vec == h. f_vec && g. f_ind == h. f_ind && g. b_vec == h. b_vec && g. b_ind == h. b_ind
73
76
74
77
degree (g:: StaticDiGraph , v:: Integer ) = indegree (g, v) + outdegree (g, v)
@@ -85,5 +88,6 @@ outdegree(g::StaticDiGraph) = [outdegree(g, v) for v in vertices(g)]
85
88
Return `true` if `g` is a directed graph.
86
89
"""
87
90
is_directed (:: Type{StaticDiGraph} ) = true
91
+ is_directed (:: Type{StaticDiGraph{T}} ) where T = true
88
92
is_directed (:: Type{StaticDiGraph{T, U}} ) where T where U = true
89
93
is_directed (g:: StaticDiGraph ) = true
0 commit comments