00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUCON_USE_DEPRECATED_DIGRAPH_H
00019 # error Don't use this header, it's replaced by cugra/graph.h
00020 #endif
00021
00022 #ifndef CUCON_DIGRAPH_H
00023 #define CUCON_DIGRAPH_H
00024
00025 #include <cucon/fwd.h>
00026 #include <cucon/list.h>
00027 #include <cucon/algo_colour.h>
00028 #include <cu/thread.h>
00029 #include <cu/ptr.h>
00030 #include <stdio.h>
00031
00032 #ifdef CU_NDEBUG
00033 # define CUCON_DIGRAPH_NDEBUG
00034 #endif
00035 #ifdef CU_NDEBUG_CLIENT
00036 # define CUCON_DIGRAPH_NDEBUG_CLIENT
00037 #endif
00038
00039
00040 CU_BEGIN_DECLARATIONS
00041
00042
00043
00044
00045
00046 struct cucon_digraph_vertex
00047 {
00048 struct cucon_list output_edges;
00049 };
00050
00051 struct cucon_digraph_edge
00052 {
00053 struct cucon_listnode as_output;
00054 cucon_digraph_vertex_t src;
00055 cucon_digraph_vertex_t dst;
00056 };
00057
00058
00059
00060
00061
00062
00063 typedef unsigned int cucon_digraph_opt_t;
00064
00065 #define cucon_digraph_opt_list_of_vertices 0x01
00066 #define cucon_digraph_opt_list_of_edges 0x02
00067 #define cucon_digraph_opt_lists \
00068 cucon_digraph_opt_list_of_vertices | cucon_digraph_opt_list_of_edges
00069
00070
00071 #define cucon_digraph_opt_no_oneedge_loops 0x10
00072
00073
00074 #define cucon_digraph_opt_no_multiedge_loops 0x20
00075
00076
00077 #define cucon_digraph_opt_no_loops 0x30
00078
00079 struct cucon_digraph
00080 {
00081 cucon_digraph_opt_t options;
00082 struct cucon_list vertices;
00083 struct cucon_list edges;
00084 #ifdef CUCONF_ENABLE_THREADS
00085 cu_mutex_t mutex;
00086 #endif
00087 };
00088
00089
00090
00091
00092 cucon_digraph_t cucon_digraph_new(cucon_digraph_opt_t options);
00093
00094
00095
00096
00097
00098
00099
00100 cucon_digraph_vertex_t
00101 cucon_digraph_insert_vertex_mem(cucon_digraph_t, size_t size);
00102
00103
00104 cucon_digraph_vertex_t
00105 cucon_digraph_insert_vertex_ptr(cucon_digraph_t, void *ptr);
00106
00107
00108
00109 void cucon_digraph_insert_vertex_node_cct(cucon_digraph_t G,
00110 cucon_digraph_vertex_t node);
00111
00112
00113
00114 cucon_digraph_edge_t
00115 cucon_digraph_insert_edge_mem(cucon_digraph_t G,
00116 cucon_digraph_vertex_t v0,
00117 cucon_digraph_vertex_t v1, size_t value_size);
00118
00119
00120 cucon_digraph_edge_t
00121 cucon_digraph_insert_edge_ptr(cucon_digraph_t G,
00122 cucon_digraph_vertex_t v0,
00123 cucon_digraph_vertex_t v1, cu_ptr_t value_ptr);
00124
00125
00126
00127
00128 typedef cucon_listnode_t cucon_digraph_all_edges_it_t;
00129 #define cucon_digraph_all_edges_it_next cucon_listnode_next
00130 #define cucon_digraph_all_edges_it_prev cucon_listnode_prev
00131 #define cucon_digraph_all_edges_it_get cucon_listnode_mem
00132 #define cucon_digraph_all_edges_begin(g) cucon_list_begin(&(g)->edges)
00133 #define cucon_digraph_all_edges_end(g) cucon_list_end(&(g)->edges)
00134
00135
00136
00137 typedef cucon_listnode_t cucon_digraph_all_vertices_it_t;
00138 #define cucon_digraph_all_vertices_it_next cucon_listnode_next
00139 #define cucon_digraph_all_vertices_it_prev cucon_listnode_prev
00140 #define cucon_digraph_all_vertices_it_get cucon_listnode_mem
00141 #define cucon_digraph_all_vertices_begin(g) cucon_list_begin(&(g)->vertices)
00142 #define cucon_digraph_all_vertices_end(g) cucon_list_end(&(g)->vertices)
00143
00144
00145
00146 #define cucon_digraph_vertex_get_mem(v) \
00147 ((void*)CU_ALIGNED_MARG_END(cucon_digraph_vertex_t, (v)))
00148 #define cucon_digraph_vertex_from_mem(mem) \
00149 CU_ALIGNED_PTR_FROM_END(cucon_digraph_t, mem)
00150 #define cucon_digraph_vertex_get_ptr(v) \
00151 (*(void**)CU_ALIGNED_MARG_END(cucon_digraph_vertex_t, (v)))
00152 #define cucon_digraph_vertex_set_ptr(v, x) \
00153 (*(void**)CU_ALIGNED_MARG_END(cucon_digraph_vertex_t, (v)) = (x))
00154
00155
00156
00157 #define cuconP_OUTEDGE(e) \
00158 ((cucon_digraph_edge_t) \
00159 (cu_ptr_sub((void *)e, \
00160 offsetof(struct cucon_digraph_edge, as_output))))
00161 #define cuconP_OUTEDGE_TO_IT(e) \
00162 (&CU_MARG(cucon_digraph_edge_t, e)->as_output)
00163
00164 #define cucon_digraph_edge_first_from_vertex(v) \
00165 cuconP_OUTEDGE( \
00166 cucon_list_begin(&CU_MARG(cucon_digraph_vertex_t, v)->output_edges))
00167 #define cucon_digraph_edge_last_from_vertex(v) \
00168 cuconP_OUTEDGE( \
00169 cucon_listnode_prev( \
00170 cucon_list_end(&CU_MARG(cucon_digraph_vertex_t, v)->output_edges)))
00171 #define cucon_digraph_edge_stop_from_vertex(v) \
00172 cuconP_OUTEDGE( \
00173 cucon_list_end(&CU_MARG(cucon_digraph_vertex_t, v)->output_edges))
00174 #define cucon_digraph_edge_next_from_vertex(e) \
00175 cuconP_OUTEDGE(cucon_listnode_next(cuconP_OUTEDGE_TO_IT(e)))
00176 #define cucon_digraph_edge_prev_from_vertex(e) \
00177 cuconP_OUTEDGE(cucon_listnode_prev(cuconP_OUTEDGE_TO_IT(e)))
00178
00179
00180
00181
00182 #define cucon_digraph_edge_get_mem(e) \
00183 ((void*)CU_ALIGNED_MARG_END(cucon_digraph_edge_t, e))
00184 #define cucon_digraph_edge_from_mem(mem) \
00185 ALIGNED_PTR_FROM_END(cucon_digraph_edge_t, mem)
00186 #define cucon_digraph_edge_get_ptr(e) \
00187 (*(void**)CU_ALIGNED_MARG_END(cucon_digraph_edge_t, e))
00188 #define cucon_digraph_edge_set_ptr(e, x) \
00189 (*(void**)CU_ALIGNED_MARG_END(cucon_digraph_edge_t, e) = (x))
00190
00191
00192
00193 #define cucon_digraph_edge_src(e) ((e)->src)
00194 #define cucon_digraph_edge_dst(e) ((e)->dst)
00195 #define cucon_digraph_edge_is_directed(e) cu_false
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 cucon_list_t
00210 cucon_digraph_shortest_path_if(
00211 cucon_digraph_t g,
00212 cucon_digraph_vertex_t v_start,
00213 cu_clop(vertex_test, cu_bool_t, cucon_digraph_vertex_t),
00214 cu_clop(edge_distance, double, cucon_digraph_edge_t));
00215
00216 cucon_list_t
00217 cucon_digraph_shortest_path(
00218 cucon_digraph_t g,
00219 cucon_digraph_vertex_t v_start,
00220 cucon_digraph_vertex_t v_final,
00221 cu_clop(edge_distance, double, cucon_digraph_edge_t));
00222
00223
00224
00225
00226
00227 void
00228 cucon_digraph_write_graphviz(
00229 cucon_digraph_t g,
00230 cu_clop(vertex_label, char const *, cucon_digraph_vertex_t),
00231 cu_clop(edge_label, char const *, cucon_digraph_edge_t),
00232 FILE* out);
00233 void
00234 cucon_digraph_write_graphviz_props(
00235 cucon_digraph_t g,
00236 cu_clop(vertex_print_props, void, cucon_digraph_vertex_t, FILE *),
00237 cu_clop(edge_print_props, void, cucon_digraph_edge_t, FILE *),
00238 FILE *out);
00239
00240
00241
00242 CU_END_DECLARATIONS
00243
00244 #endif