1 // Ah... The joys graph data structures :)
2 // A hole into which many a good computer scientist has fallen, never to be heard from again.
6 Basic idea: provide concepts that define the interface(s) to different kinds of graphs so that you can do
7 basic graph operations and algoriths without knowing exactly which kind of graph it is and keep ignorant
8 about implementation details.
10 Basic design idea: do like the STL
14 // Graph concepts (like STL containers):
15 // Do we need them (STL doesn't make containers explicit)
16 template<class G> concept bool Graph = false; // general graph operations
17 template<class G> concept bool DAG = false; // operations simplified for DAGs (any extra operations?)
18 template<class G> concept bool Tree = false; // operations simplified for trees (any extra operations?)
20 // accessor concepts (like STL Iterators):
21 template<class G> concept bool Edge_ref = false; // most general and slowest
22 template<class G> concept bool DAG_edge_ref = false; // operations simplified for DAGs (any extra operations?)
23 template<class G> concept bool Tree_edge_ref = false; // operations simplified for trees (any extra operations?)
25 template<class G> concept bool Vertex_ref = false; // most general and slowest
26 template<class G> concept bool DAG_vertex_ref = false; // operations simplified for DAGs (any extra operations?)
27 template<class G> concept bool Tree_vertex_ref = false; // operations simplified for DAGs (any extra operations?)
29 // the value type (in a more general design, this would be a template parmeter):
32 // specific directed graphs:
38 struct Edge_ref {}; // Is an Edge an object? (if not, refer to parent node)
40 struct DAG_vertex_ref {};
41 struct DAG_edge_ref {}; // Is an Edge an object? (if not, refer to parent node)
44 struct Gedge_ref {}; // Is an Edge an object? (if not, refer to parent node)
46 // another Graph representation:
48 struct DGE_ref {}; // Is an Edge an object? (if not, refer to parent node)
54 vector<???> found; // there is a way (look up traits), lets try g::value_type
60 Basic idea: provide concepts that define the interface(s) to different kinds of graphs so that you can do
61 basic graph operations and algoriths without knowing exactly which kind of graph it is and keep ignorant
62 about implementation details.
64 Basic design idea: do like the STL
68 // Graph concepts (like STL containers):
69 // Do we need them (STL doesn't make containers explicit)
70 template<class G> concept bool Graph = // general graph operations
71 requires { typename G::value_type; };
72 template<class G> concept bool DAG = Graph<G> && requires(G g) { tops(g); }; // operations simplified for DAGs
73 template<class G> concept bool Tree = DAG<G> && requires(G g) { top(g); }; // operations simplified for trees
75 // accessor concepts (like STL Iterators):
76 template<class E> concept bool Edge_ref = // most general and slowest
77 requires { typename E::value_type; };
78 template<class E> concept bool DAG_edge_ref = // operations simplified for DAGs (any extra operations?)
80 template<class E> concept bool Tree_edge_ref = // operations simplified for trees (any extra operations?)
81 DAG_edge_ref<E> && false;
83 template<class G> concept bool Vertex_ref = true; // most general and slowest
84 template<class G> concept bool DAG_vertex_ref = false; // operations simplified for DAGs (any extra operations?)
85 template<class G> concept bool Tree_vertex_ref = false; // operations simplified for DAGs (any extra operations?)
87 // the value type (in a more general design, this would be a template parmeter):
90 // specific directed graphs (note: we can't assume common structure or common naming from implementation):
92 using value_type = Val;
96 struct Edge_ref {}; // Is an Edge an object? (if not, refer to parent node)
98 void tops(Tree&); // return vector Tree_vertex_refs
102 using value_type = Val;
105 struct DAG_vertex_ref {};
106 struct DAG_edge_ref {}; // Is an Edge an object? (if not, refer to parent node)
111 using value_type = Val;
116 struct Gedge_ref {}; // Is an Edge an object? (if not, refer to parent node)
118 // another Graph representation:
120 struct DGE_ref {}; // Is an Edge an object? (if not, refer to parent node)
126 template<Graph G, Vertex_ref R>
127 void traverse(G& g, R r)
129 vector<typename G::value_type> found; // member g::value_type (old habit: could just have used Val)
133 void use1(Tree& t, Dag& d, Dgraph& dg, Node_ref& tr, DAG_vertex_ref& dr, Gnode_ref& gr)
144 Basic idea: provide concepts that define the interface(s) to different kinds of graphs so that you can do
145 basic graph operations and algoriths without knowing exactly which kind of graph it is and keep ignorant
146 about implementation details.
148 Basic design idea: do like the STL
151 // Graph concepts (like STL containers):
152 // Do we need them (STL doesn't make containers explicit)
153 template<class G> concept bool Graph = // general graph operations
154 requires { typename G::value_type; };
155 template<class G> concept bool DAG = Graph<G> && requires(G g) { tops(g); }; // operations simplified for DAGs
156 template<class G> concept bool Tree = DAG<G> && requires(G g) { top(g); }; // operations simplified for trees
158 // accessor concepts (like STL Iterators):
159 template<class E> concept bool Edge_ref = // most general and slowest
161 typename E::value_type;
162 { *e } -> typename E::value_type;
163 { e.vertex } -> Vertex_ref;
165 template<class E> concept bool DAG_edge_ref = // operations simplified for DAGs (any extra operations?)
166 Edge_ref<E> && false;
167 template<class E> concept bool Tree_edge_ref = // operations simplified for trees (any extra operations?)
168 DAG_edge_ref<E> && false;
170 template<class V> concept bool Vertex_ref = // most general and slowest
171 requires(V v, int i) {
172 typename V::value_type;
173 { *v } -> typename V::value_type;
174 { v.edge[i] } -> Edge_ref;
176 template<class V> concept bool DAG_vertex_ref = false; // operations simplified for DAGs (any extra operations?)
177 template<class V> concept bool Tree_vertex_ref = false; // operations simplified for DAGs (any extra operations?)
179 // the value type (in a more general design, this would be a template parmeter):
182 // specific directed graphs (note: we can't assume common structure or common naming from implementation):
184 using value_type = Val;
188 struct Edge_ref {}; // Is an Edge an object? (if not, refer to parent node)
190 void tops(Tree&); // return vector Tree_vertex_refs
194 using value_type = Val;
197 struct DAG_vertex_ref {};
198 struct DAG_edge_ref {}; // Is an Edge an object? (if not, refer to parent node)
203 using value_type = Val;
208 struct Gedge_ref {}; // Is an Edge an object? (if not, refer to parent node)
210 // another Graph representation:
212 struct DGE_ref {}; // Is an Edge an object? (if not, refer to parent node)
218 template<Graph G, Vertex_ref R>
219 void traverse(G& g, R r)
221 vector<typename G::value_type> found; // member g::value_type (old habit: could just have used Val)
225 void use1(Tree& t, Dag& d, Dgraph& dg, Node_ref& tr, DAG_vertex_ref& dr, Gnode_ref& gr)