@@ -10,6 +10,11 @@ using NamedGraphs: NamedGraphs, AbstractEdges, AbstractNamedEdge, AbstractNamedG
1010 similar_graph, subgraph_edges
1111using SimpleTraits: SimpleTraits, @traitfn , Not
1212
13+ struct VertexEdgeDataTypes{VD, ED}
14+ vertex_data_type:: VD
15+ edge_data_type:: ED
16+ end
17+
1318abstract type AbstractDataGraph{V, VD, ED} <: AbstractNamedGraph{V} end
1419
1520vertex_data_type (:: Type{<:AbstractGraph} ) = Any
@@ -145,21 +150,19 @@ end
145150"""
146151 similar_graph(datagraph::AbstractDataGraph, D::Type)
147152 similar_graph(datagraph::AbstractDataGraph, D::Type, vertices)
148- similar_graph(datagraph::AbstractDataGraph, VD::Type, ED::Type )
149- similar_graph(datagraph::AbstractDataGraph, VD::Type, ED::Type , vertices)
153+ similar_graph(datagraph::AbstractDataGraph, D::VertexEdgeDataTypes )
154+ similar_graph(datagraph::AbstractDataGraph, D::VertexEdgeDataTypes , vertices)
150155
151156Create an uninitialized data graph, similar to the provided `datagraph`, but with vertices
152157defined by `vertices` and a vertex and edge data type `D`. One may also provide separate
153- vertex and edge data types `VD` and `ED`.
158+ vertex and edge data types `VD` and `ED` by using the wrapper `VertexEdgeDataTypes(VD, ED)` .
154159If vertices are not provided, then the graph is constructed with the same vertices and edges
155160as the input graph.
156161"""
157- function NamedGraphs. similar_graph (
158- graph:: AbstractDataGraph
159- )
160- VD = vertex_data_type (graph)
161- ED = edge_data_type (graph)
162- return similar_graph (graph, VD, ED)
162+
163+ NamedGraphs. similar_graph (graph:: AbstractDataGraph , D:: Type ) = similar_datagraph (graph, D)
164+ function NamedGraphs. similar_graph (graph:: AbstractDataGraph , D:: VertexEdgeDataTypes )
165+ return similar_datagraph (graph, D)
163166end
164167
165168function NamedGraphs. similar_graph (
@@ -168,37 +171,36 @@ function NamedGraphs.similar_graph(
168171 )
169172 VD = vertex_data_type (graph)
170173 ED = edge_data_type (graph)
171- return similar_graph (graph, VD, ED, vertices)
172- end
173- function NamedGraphs. similar_graph (
174- graph:: AbstractDataGraph ,
175- D:: Type
176- )
177- return similar_graph (graph, D, D)
174+
175+ return similar_graph (graph, VertexEdgeDataTypes (VD, ED), vertices)
178176end
179177
178+ # Base case(s) (overload these if fallback not wanted).
180179function NamedGraphs. similar_graph (
181180 graph:: AbstractDataGraph ,
182181 D:: Type ,
183182 vertices
184183 )
185- return similar_graph (graph, D, D, vertices)
184+ return similar_datagraph (graph, D, D, vertices)
186185end
187-
188186function NamedGraphs. similar_graph (
189187 graph:: AbstractDataGraph ,
190- VD :: Type ,
191- ED :: Type
188+ D :: VertexEdgeDataTypes ,
189+ vertices
192190 )
193- new_graph = similar_graph (graph, VD, ED, vertices (graph))
191+ return similar_datagraph (graph, D. vertex_data_type, D. edge_data_type, vertices)
192+ end
193+
194+ # Internal implementation functions,
195+ function similar_datagraph (graph:: AbstractGraph , D)
196+ new_graph = similar_graph (graph, D, vertices (graph))
194197 add_edges! (new_graph, edges (graph))
195198
196199 return new_graph
197200end
198201
199- # Base case(s) (overload these if fallback not wanted).
200- @traitfn function NamedGraphs. similar_graph (
201- graph:: AbstractDataGraph :: (!IsDirected) ,
202+ @traitfn function similar_datagraph (
203+ graph:: AbstractGraph :: (!IsDirected) ,
202204 VD:: Type ,
203205 ED:: Type ,
204206 vertices
207209
208210 return DataGraph (underlying_graph; vertex_data_type = VD, edge_data_type = ED)
209211end
210- @traitfn function NamedGraphs . similar_graph (
211- graph:: AbstractDataGraph :: IsDirected ,
212+ @traitfn function similar_datagraph (
213+ graph:: AbstractGraph :: IsDirected ,
212214 VD:: Type ,
213215 ED:: Type ,
214216 vertices
0 commit comments