@@ -74,7 +74,7 @@ has_vertex(g::AbstractMetaGraph, x...) = has_vertex(g.graph, x...)
7474inneighbors (g:: AbstractMetaGraph , v:: Integer ) = inneighbors (g. graph, v)
7575outneighbors (g:: AbstractMetaGraph , v:: Integer ) = fadj (g. graph, v)
7676
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)
7878
7979"""
8080 add_edge!(g, u, v, s, val)
@@ -135,10 +135,10 @@ function rem_vertex!(g::AbstractMetaGraph, v::Integer)
135135 lasteoutprops = Dict (n => props (g, lastv, n) for n in outneighbors (g, lastv))
136136 lasteinprops = Dict (n => props (g, n, lastv) for n in inneighbors (g, lastv))
137137 for ind in g. indices
138- if haskey (props (g,lastv),ind)
138+ if haskey (props (g, lastv), ind)
139139 pop! (g. metaindex[ind], get_prop (g, lastv, ind))
140140 end
141- if haskey (props (g,v),ind)
141+ if haskey (props (g, v), ind)
142142 v != lastv && pop! (g. metaindex[ind], get_prop (g, v, ind))
143143 end
144144 end
@@ -191,7 +191,7 @@ function rem_vertex!(g::AbstractMetaGraph, v::Integer)
191191 return true
192192end
193193
194- struct MetaWeights{T <: Integer ,U <: Real } <: AbstractMatrix{U}
194+ struct MetaWeights{T<: Integer ,U<: Real } <: AbstractMatrix{U}
195195 n:: T
196196 weightfield:: Symbol
197197 defaultweight:: U
@@ -203,7 +203,7 @@ show(io::IO, z::MIME"text/plain", x::MetaWeights) = show(io, x)
203203
204204MetaWeights (g:: AbstractMetaGraph ) = MetaWeights {eltype(g),eltype(g.defaultweight)} (nv (g), g. weightfield, g. defaultweight, g. eprops, is_directed (g))
205205
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 }
207207 _e = Edge (u, v)
208208 e = ! w. directed && ! Graphs. is_ordered (_e) ? reverse (_e) : _e
209209 ! haskey (w. eprops, e) && return w. defaultweight
@@ -253,20 +253,33 @@ props(g::AbstractMetaGraph, v::Integer) = get(PropDict, g.vprops, v)
253253props (g:: AbstractMetaGraph , u:: Integer , v:: Integer ) = props (g, Edge (u, v))
254254
255255"""
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)
260266
261267Return the property `prop` defined for graph `g`, vertex `v`, or edge `e`
262268(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.
264270"""
265271get_prop (g:: AbstractMetaGraph , prop:: Symbol ) = props (g)[prop]
272+ get_prop (g:: AbstractMetaGraph , prop:: Symbol , default) = get (props (g), prop, default)
273+
266274get_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+
267277get_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)
268279
269280get_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+
270283
271284"""
272285 has_prop(g, prop)
@@ -300,15 +313,15 @@ end
300313
301314function set_props! (g:: AbstractMetaGraph , v:: Integer , d:: Dict )
302315 if has_vertex (g, v)
303- for (prop,val) in d
316+ for (prop, val) in d
304317 index_available (g, v, prop, val) || error (" ':$prop ' index already contains $val " )
305318 end
306319 if ! _hasdict (g, v)
307320 g. vprops[v] = d
308321 else
309322 merge! (g. vprops[v], d)
310323 end
311- for prop in intersect (keys (d), g. indices)
324+ for prop in intersect (keys (d), g. indices)
312325 g. metaindex[prop][d[prop]] = v
313326 end
314327 return true
@@ -317,7 +330,7 @@ function set_props!(g::AbstractMetaGraph, v::Integer, d::Dict)
317330end
318331# set_props!(g::AbstractMetaGraph, e::SimpleEdge, d::Dict) is dependent on directedness.
319332
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)
321334
322335"""
323336 set_prop!(g, prop, val)
@@ -339,7 +352,7 @@ set_prop!(g::AbstractMetaGraph, v::Integer, prop::Symbol, val) = begin
339352end
340353set_prop! (g:: AbstractMetaGraph , e:: SimpleEdge , prop:: Symbol , val) = set_props! (g, e, Dict (prop => val))
341354
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)
343356
344357"""
345358 rem_prop!(g, prop)
@@ -355,7 +368,7 @@ rem_prop!(g::AbstractMetaGraph, prop::Symbol) = delete!(g.gprops, prop)
355368rem_prop! (g:: AbstractMetaGraph , v:: Integer , prop:: Symbol ) = delete! (g. vprops[v], prop)
356369rem_prop! (g:: AbstractMetaGraph , e:: SimpleEdge , prop:: Symbol ) = delete! (g. eprops[e], prop)
357370
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)
359372
360373"""
361374 default_index_value(v, prop, index_values; exclude=nothing)
@@ -416,7 +429,7 @@ function set_indexing_prop!(g::AbstractMetaGraph, v::Integer, prop::Symbol, val:
416429 haskey (g. metaindex[prop], val) && error (" ':$prop ' index already contains $val " )
417430
418431 if ! haskey (g. vprops, v)
419- push! (g. vprops, v=> Dict {Symbol,Any} ())
432+ push! (g. vprops, v => Dict {Symbol,Any} ())
420433 end
421434 if haskey (g. vprops[v], prop)
422435 delete! (g. metaindex[prop], g. vprops[v][prop])
@@ -438,7 +451,7 @@ clear_props!(g::AbstractMetaGraph, v::Integer) = _hasdict(g, v) && delete!(g.vpr
438451clear_props! (g:: AbstractMetaGraph , e:: SimpleEdge ) = _hasdict (g, e) && delete! (g. eprops, e)
439452clear_props! (g:: AbstractMetaGraph ) = g. gprops = PropDict ()
440453
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)))
442455
443456"""
444457 weightfield!(g, prop)
@@ -514,7 +527,7 @@ filter_vertices(g::AbstractMetaGraph, prop::Symbol) =
514527filter_vertices (g:: AbstractMetaGraph , prop:: Symbol , val) =
515528 filter_vertices (g, (g, x) -> has_prop (g, x, prop) && get_prop (g, x, prop) == val)
516529
517- function _copy_props! (oldg:: T , newg:: T , vmap) where T <: AbstractMetaGraph
530+ function _copy_props! (oldg:: T , newg:: T , vmap) where {T <: AbstractMetaGraph }
518531 for (newv, oldv) in enumerate (vmap)
519532 p = props (oldg, oldv)
520533 if ! isempty (p)
@@ -540,21 +553,21 @@ function _copy_props!(oldg::T, newg::T, vmap) where T <: AbstractMetaGraph
540553 return nothing
541554end
542555
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 }
544557 inducedgraph, vmap = induced_subgraph (g. graph, v)
545558 newg = T (inducedgraph)
546559 _copy_props! (g, newg, vmap)
547560 return newg, vmap
548561end
549562
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 }
551564 inducedgraph, vmap = induced_subgraph (g. graph, v)
552565 newg = T (inducedgraph)
553566 _copy_props! (g, newg, vmap)
554567 return newg, vmap
555568end
556569
557- induced_subgraph (g:: T , filt:: Iterators.Filter ) where T <: AbstractMetaGraph =
570+ induced_subgraph (g:: T , filt:: Iterators.Filter ) where {T <: AbstractMetaGraph } =
558571 induced_subgraph (g, collect (filt))
559572
560573# 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 =
563576
564577== (x:: AbstractMetaGraph , y:: AbstractMetaGraph ) = x. graph == y. graph
565578
566- copy (g:: T ) where T <: AbstractMetaGraph = deepcopy (g)
579+ copy (g:: T ) where {T <: AbstractMetaGraph } = deepcopy (g)
567580
568581include (" metadigraph.jl" )
569582include (" metagraph.jl" )
0 commit comments