@@ -74,7 +74,7 @@ has_vertex(g::AbstractMetaGraph, x...) = has_vertex(g.graph, x...)
74
74
inneighbors (g:: AbstractMetaGraph , v:: Integer ) = inneighbors (g. graph, v)
75
75
outneighbors (g:: AbstractMetaGraph , v:: Integer ) = fadj (g. graph, v)
76
76
77
- issubset (g:: T , h:: T ) where T <: AbstractMetaGraph = issubset (g. graph, h. graph)
77
+ issubset (g:: T , h:: T ) where {T <: AbstractMetaGraph } = issubset (g. graph, h. graph)
78
78
79
79
"""
80
80
add_edge!(g, u, v, s, val)
@@ -135,10 +135,10 @@ function rem_vertex!(g::AbstractMetaGraph, v::Integer)
135
135
lasteoutprops = Dict (n => props (g, lastv, n) for n in outneighbors (g, lastv))
136
136
lasteinprops = Dict (n => props (g, n, lastv) for n in inneighbors (g, lastv))
137
137
for ind in g. indices
138
- if haskey (props (g,lastv),ind)
138
+ if haskey (props (g, lastv), ind)
139
139
pop! (g. metaindex[ind], get_prop (g, lastv, ind))
140
140
end
141
- if haskey (props (g,v),ind)
141
+ if haskey (props (g, v), ind)
142
142
v != lastv && pop! (g. metaindex[ind], get_prop (g, v, ind))
143
143
end
144
144
end
@@ -191,7 +191,7 @@ function rem_vertex!(g::AbstractMetaGraph, v::Integer)
191
191
return true
192
192
end
193
193
194
- struct MetaWeights{T <: Integer ,U <: Real } <: AbstractMatrix{U}
194
+ struct MetaWeights{T<: Integer ,U<: Real } <: AbstractMatrix{U}
195
195
n:: T
196
196
weightfield:: Symbol
197
197
defaultweight:: U
@@ -203,7 +203,7 @@ show(io::IO, z::MIME"text/plain", x::MetaWeights) = show(io, x)
203
203
204
204
MetaWeights (g:: AbstractMetaGraph ) = MetaWeights {eltype(g),eltype(g.defaultweight)} (nv (g), g. weightfield, g. defaultweight, g. eprops, is_directed (g))
205
205
206
- function getindex (w:: MetaWeights{T,U} , u:: Integer , v:: Integer ):: U where T <: Integer where U <: Real
206
+ function getindex (w:: MetaWeights{T,U} , u:: Integer , v:: Integer ):: U where {T <: Integer } where {U <: Real }
207
207
_e = Edge (u, v)
208
208
e = ! w. directed && ! Graphs. is_ordered (_e) ? reverse (_e) : _e
209
209
! haskey (w. eprops, e) && return w. defaultweight
@@ -253,20 +253,33 @@ props(g::AbstractMetaGraph, v::Integer) = get(PropDict, g.vprops, v)
253
253
props (g:: AbstractMetaGraph , u:: Integer , v:: Integer ) = props (g, Edge (u, v))
254
254
255
255
"""
256
- get_prop(g, prop)
257
- get_prop(g, v, prop)
258
- get_prop(g, e, prop)
259
- get_prop(g, s, d, prop)
256
+ get_prop(g, prop::Symbol)
257
+ get_prop(g, prop::Symbol, default)
258
+
259
+ get_prop(g, v, prop::Symbol)
260
+ get_prop(g, v, prop::Symbol, default)
261
+
262
+ get_prop(g, e, prop::Symbol)
263
+ get_prop(g, e, prop::Symbol, default)
264
+ get_prop(g, s, d, prop::Symbol)
265
+ get_prop(g, s, d, prop::Symbol, default)
260
266
261
267
Return the property `prop` defined for graph `g`, vertex `v`, or edge `e`
262
268
(optionally referenced by source vertex `s` and destination vertex `d`).
263
- If property is not defined, return an error.
269
+ Use the version with `default`, to return a default value if the property is not defined. Otherwise, it will return an error.
264
270
"""
265
271
get_prop (g:: AbstractMetaGraph , prop:: Symbol ) = props (g)[prop]
272
+ get_prop (g:: AbstractMetaGraph , prop:: Symbol , default) = get (props (g), prop, default)
273
+
266
274
get_prop (g:: AbstractMetaGraph , v:: Integer , prop:: Symbol ) = props (g, v)[prop]
275
+ get_prop (g:: AbstractMetaGraph , v:: Integer , prop:: Symbol , default) = get (props (g, v), prop, default)
276
+
267
277
get_prop (g:: AbstractMetaGraph , e:: SimpleEdge , prop:: Symbol ) = props (g, e)[prop]
278
+ get_prop (g:: AbstractMetaGraph , e:: SimpleEdge , prop:: Symbol , default) = get (props (g, e), prop, default)
268
279
269
280
get_prop (g:: AbstractMetaGraph , u:: Integer , v:: Integer , prop:: Symbol ) = get_prop (g, Edge (u, v), prop)
281
+ get_prop (g:: AbstractMetaGraph , u:: Integer , v:: Integer , prop:: Symbol , default) = get_prop (g, Edge (u, v), prop, default)
282
+
270
283
271
284
"""
272
285
has_prop(g, prop)
@@ -300,15 +313,15 @@ end
300
313
301
314
function set_props! (g:: AbstractMetaGraph , v:: Integer , d:: Dict )
302
315
if has_vertex (g, v)
303
- for (prop,val) in d
316
+ for (prop, val) in d
304
317
index_available (g, v, prop, val) || error (" ':$prop ' index already contains $val " )
305
318
end
306
319
if ! _hasdict (g, v)
307
320
g. vprops[v] = d
308
321
else
309
322
merge! (g. vprops[v], d)
310
323
end
311
- for prop in intersect (keys (d), g. indices)
324
+ for prop in intersect (keys (d), g. indices)
312
325
g. metaindex[prop][d[prop]] = v
313
326
end
314
327
return true
@@ -317,7 +330,7 @@ function set_props!(g::AbstractMetaGraph, v::Integer, d::Dict)
317
330
end
318
331
# set_props!(g::AbstractMetaGraph, e::SimpleEdge, d::Dict) is dependent on directedness.
319
332
320
- set_props! (g:: AbstractMetaGraph{T} , u:: Integer , v:: Integer , d:: Dict ) where T = set_props! (g, Edge (T (u), T (v)), d)
333
+ set_props! (g:: AbstractMetaGraph{T} , u:: Integer , v:: Integer , d:: Dict ) where {T} = set_props! (g, Edge (T (u), T (v)), d)
321
334
322
335
"""
323
336
set_prop!(g, prop, val)
@@ -339,7 +352,7 @@ set_prop!(g::AbstractMetaGraph, v::Integer, prop::Symbol, val) = begin
339
352
end
340
353
set_prop! (g:: AbstractMetaGraph , e:: SimpleEdge , prop:: Symbol , val) = set_props! (g, e, Dict (prop => val))
341
354
342
- set_prop! (g:: AbstractMetaGraph{T} , u:: Integer , v:: Integer , prop:: Symbol , val) where T = set_prop! (g, Edge (T (u), T (v)), prop, val)
355
+ set_prop! (g:: AbstractMetaGraph{T} , u:: Integer , v:: Integer , prop:: Symbol , val) where {T} = set_prop! (g, Edge (T (u), T (v)), prop, val)
343
356
344
357
"""
345
358
rem_prop!(g, prop)
@@ -355,7 +368,7 @@ rem_prop!(g::AbstractMetaGraph, prop::Symbol) = delete!(g.gprops, prop)
355
368
rem_prop! (g:: AbstractMetaGraph , v:: Integer , prop:: Symbol ) = delete! (g. vprops[v], prop)
356
369
rem_prop! (g:: AbstractMetaGraph , e:: SimpleEdge , prop:: Symbol ) = delete! (g. eprops[e], prop)
357
370
358
- rem_prop! (g:: AbstractMetaGraph{T} , u:: Integer , v:: Integer , prop:: Symbol ) where T = rem_prop! (g, Edge (T (u), T (v)), prop)
371
+ rem_prop! (g:: AbstractMetaGraph{T} , u:: Integer , v:: Integer , prop:: Symbol ) where {T} = rem_prop! (g, Edge (T (u), T (v)), prop)
359
372
360
373
"""
361
374
default_index_value(v, prop, index_values; exclude=nothing)
@@ -416,7 +429,7 @@ function set_indexing_prop!(g::AbstractMetaGraph, v::Integer, prop::Symbol, val:
416
429
haskey (g. metaindex[prop], val) && error (" ':$prop ' index already contains $val " )
417
430
418
431
if ! haskey (g. vprops, v)
419
- push! (g. vprops, v=> Dict {Symbol,Any} ())
432
+ push! (g. vprops, v => Dict {Symbol,Any} ())
420
433
end
421
434
if haskey (g. vprops[v], prop)
422
435
delete! (g. metaindex[prop], g. vprops[v][prop])
@@ -438,7 +451,7 @@ clear_props!(g::AbstractMetaGraph, v::Integer) = _hasdict(g, v) && delete!(g.vpr
438
451
clear_props! (g:: AbstractMetaGraph , e:: SimpleEdge ) = _hasdict (g, e) && delete! (g. eprops, e)
439
452
clear_props! (g:: AbstractMetaGraph ) = g. gprops = PropDict ()
440
453
441
- clear_props! (g:: AbstractMetaGraph{T} , u:: Integer , v:: Integer ) where T = clear_props! (g, Edge (T (u), T (v)))
454
+ clear_props! (g:: AbstractMetaGraph{T} , u:: Integer , v:: Integer ) where {T} = clear_props! (g, Edge (T (u), T (v)))
442
455
443
456
"""
444
457
weightfield!(g, prop)
@@ -514,7 +527,7 @@ filter_vertices(g::AbstractMetaGraph, prop::Symbol) =
514
527
filter_vertices (g:: AbstractMetaGraph , prop:: Symbol , val) =
515
528
filter_vertices (g, (g, x) -> has_prop (g, x, prop) && get_prop (g, x, prop) == val)
516
529
517
- function _copy_props! (oldg:: T , newg:: T , vmap) where T <: AbstractMetaGraph
530
+ function _copy_props! (oldg:: T , newg:: T , vmap) where {T <: AbstractMetaGraph }
518
531
for (newv, oldv) in enumerate (vmap)
519
532
p = props (oldg, oldv)
520
533
if ! isempty (p)
@@ -540,21 +553,21 @@ function _copy_props!(oldg::T, newg::T, vmap) where T <: AbstractMetaGraph
540
553
return nothing
541
554
end
542
555
543
- function induced_subgraph (g:: T , v:: AbstractVector{U} ) where T <: AbstractMetaGraph where U <: Integer
556
+ function induced_subgraph (g:: T , v:: AbstractVector{U} ) where {T <: AbstractMetaGraph } where {U <: Integer }
544
557
inducedgraph, vmap = induced_subgraph (g. graph, v)
545
558
newg = T (inducedgraph)
546
559
_copy_props! (g, newg, vmap)
547
560
return newg, vmap
548
561
end
549
562
550
- function induced_subgraph (g:: T , v:: AbstractVector{U} ) where T <: AbstractMetaGraph where U <: SimpleEdge
563
+ function induced_subgraph (g:: T , v:: AbstractVector{U} ) where {T <: AbstractMetaGraph } where {U <: SimpleEdge }
551
564
inducedgraph, vmap = induced_subgraph (g. graph, v)
552
565
newg = T (inducedgraph)
553
566
_copy_props! (g, newg, vmap)
554
567
return newg, vmap
555
568
end
556
569
557
- induced_subgraph (g:: T , filt:: Iterators.Filter ) where T <: AbstractMetaGraph =
570
+ induced_subgraph (g:: T , filt:: Iterators.Filter ) where {T <: AbstractMetaGraph } =
558
571
induced_subgraph (g, collect (filt))
559
572
560
573
# TODO - would be nice to be able to apply a function to properties. Not sure
@@ -563,7 +576,7 @@ induced_subgraph(g::T, filt::Iterators.Filter) where T <: AbstractMetaGraph =
563
576
564
577
== (x:: AbstractMetaGraph , y:: AbstractMetaGraph ) = x. graph == y. graph
565
578
566
- copy (g:: T ) where T <: AbstractMetaGraph = deepcopy (g)
579
+ copy (g:: T ) where {T <: AbstractMetaGraph } = deepcopy (g)
567
580
568
581
include (" metadigraph.jl" )
569
582
include (" metagraph.jl" )
0 commit comments