00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUCON_PO_H
00019 #define CUCON_PO_H
00020
00021 #include <cu/clos.h>
00022 #include <cucon/list.h>
00023 #include <cucon/fwd.h>
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <pthread.h>
00027
00028 CU_BEGIN_DECLARATIONS
00029
00030
00031
00032 #define CUCON_PO_ELT_LINKS_PO 1
00033
00034 struct cucon_po
00035 {
00036 struct cucon_poelt *bot;
00037 struct cucon_poelt *top;
00038 };
00039
00040 struct cucon_poelt
00041 {
00042 struct cucon_list isuccs;
00043 struct cucon_list ipreds;
00044
00045 unsigned int level;
00046
00047 #ifdef CUCON_PO_ELT_LINKS_PO
00048 struct cucon_po *po;
00049 #endif
00050 };
00051
00052
00053 typedef enum {
00054 cucon_pocmp_eq
00055 , cucon_pocmp_prec
00056 , cucon_pocmp_succ
00057 , cucon_pocmp_unord
00058 } cucon_pocmp_t;
00059
00060 typedef cucon_listnode_t cucon_po_ipred_it_t;
00061 typedef cucon_listnode_t cucon_po_isucc_it_t;
00062
00063
00064 void cucon_po_cct(cucon_po_t po);
00065 #define cucon_po_cct(po) cucon_po_cct_mem(po, 0, 0)
00066
00067
00068 cucon_po_t cucon_po_new(void);
00069 #define cucon_po_new() cucon_po_new_mem(0, 0)
00070
00071
00072
00073 void cucon_po_cct_mem(cucon_po_t po,
00074 size_t size_bot, size_t size_top);
00075
00076
00077 cucon_po_t cucon_po_new_mem(size_t size_bot, size_t size_top);
00078
00079
00080
00081 void cucon_po_cct_ptr(cucon_po_t po, void *bot, void *top);
00082
00083
00084
00085 cucon_po_t cucon_po_new_ptr(void *bot, void *top);
00086
00087
00088
00089 void cucon_po_cct_2elt(cucon_po_t po,
00090 cucon_poelt_t bot, cucon_poelt_t top);
00091
00092
00093
00094 void cucon_po_cct_2elt_cct(cucon_po_t po,
00095 cucon_poelt_t bot, cucon_poelt_t top);
00096
00097
00098 cucon_poelt_t cucon_po_bot(cucon_po_t po);
00099 #define cucon_po_bot(po) ((po)->bot)
00100
00101
00102 cucon_poelt_t cucon_po_top(cucon_po_t po);
00103 #define cucon_po_top(po) ((po)->top)
00104
00105
00106
00107 unsigned int cucon_po_depth(cucon_po_t po);
00108 #define cucon_po_depth(po) (CU_MARG(cucon_po_t, po)->top->level + 1)
00109
00110
00111
00112
00113 cucon_poelt_t cucon_po_insert_mem(cucon_po_t po, size_t size);
00114
00115
00116
00117
00118 cucon_poelt_t cucon_po_insert_ptr(cucon_po_t po, void *ptr);
00119
00120
00121
00122 void cucon_po_insert_cct(cucon_po_t po, cucon_poelt_t elt);
00123
00124
00125
00126 void cucon_po_insert_constrain(cucon_po_t po, cucon_poelt_t elt,
00127 cu_clop(prec, cu_bool_t, void *v0, void *v1));
00128
00129
00130 void cucon_poelt_cct(cucon_poelt_t elt);
00131 cucon_poelt_t cucon_poelt_new_alloc(size_t size);
00132
00133
00134 CU_SINLINE void*cucon_poelt_get_mem(cucon_poelt_t elt)
00135 { return CU_ALIGNED_MARG_END(cucon_poelt_t, elt); }
00136
00137
00138 CU_SINLINE void*cucon_poelt_get_ptr(cucon_poelt_t elt)
00139 { return *(void **)CU_ALIGNED_MARG_END(cucon_poelt_t, elt); }
00140
00141
00142 CU_SINLINE
00143 unsigned int cucon_poelt_level(cucon_poelt_t elt) { return elt->level; }
00144
00145
00146 cucon_poelt_t cucon_poelt_of_data(void *slot);
00147 #define cucon_poelt_of_data(data) \
00148 CU_ALIGNED_PTR_FROM_END(cucon_poelt_t, data)
00149
00150
00151
00152
00153
00154 cu_bool_t cucon_po_constrain_prec(cucon_po_t po,
00155 cucon_poelt_t e0, cucon_poelt_t e1);
00156
00157
00158 cu_bool_t cucon_po_prec(cucon_poelt_t e0, cucon_poelt_t e1);
00159
00160
00161 CU_SINLINE cu_bool_t
00162 cucon_po_preceq(cucon_poelt_t e0, cucon_poelt_t e1)
00163 { return e0 == e1 || cucon_po_prec(e0, e1); }
00164
00165
00166 void cucon_po_iter_open_range(cucon_poelt_t below, cucon_poelt_t above,
00167 cu_clop(f, void, cucon_poelt_t));
00168
00169
00170 void cucon_po_iter_left_range(cucon_poelt_t min, cucon_poelt_t above,
00171 cu_clop(f, void, cucon_poelt_t));
00172
00173
00174 void cucon_po_iter_right_range(cucon_poelt_t below, cucon_poelt_t max,
00175 cu_clop(f, void, cucon_poelt_t));
00176
00177
00178 void cucon_po_iter_closed_range(cucon_poelt_t min, cucon_poelt_t max,
00179 cu_clop(f, void, cucon_poelt_t));
00180
00181
00182 void cucon_po_iter_ipreds(cucon_poelt_t e, cu_clop(f, void, cucon_poelt_t));
00183
00184
00185 void cucon_po_iter_isuccs(cucon_poelt_t e, cu_clop(f, void, cucon_poelt_t));
00186
00187
00188
00189 void cucon_po_topological_succs(cucon_poelt_t e,
00190 cu_clop(f, void, cucon_poelt_t));
00191 void cucon_po_topological_preds(cucon_poelt_t e,
00192 cu_clop(f, void, cucon_poelt_t));
00193
00194
00195
00196
00197 CU_SINLINE cu_bool_t
00198 cucon_poelt_has_single_ipred(cucon_poelt_t e)
00199 { return cucon_list_is_singleton(&e->ipreds); }
00200
00201
00202 CU_SINLINE cu_bool_t
00203 cucon_poelt_has_single_isucc(cucon_poelt_t e)
00204 { return cucon_list_is_singleton(&e->isuccs); }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 void
00219 cucon_po_range_and_bounds_of_fn(cucon_poelt_t bot, cucon_poelt_t top,
00220 cu_clop(cmp, cucon_pocmp_t, cucon_poelt_t),
00221 cucon_pmap_t range,
00222 cucon_pmap_t ipreds, cucon_pmap_t isuccs);
00223
00224
00225
00226 CU_SINLINE cucon_po_ipred_it_t
00227 cucon_po_ipred_begin(cucon_poelt_t e)
00228 { return cucon_list_begin(&e->ipreds); }
00229
00230
00231
00232 CU_SINLINE cucon_po_ipred_it_t
00233 cucon_po_ipred_end(cucon_poelt_t e)
00234 { return cucon_list_end(&e->ipreds); }
00235
00236
00237 CU_SINLINE cucon_po_ipred_it_t
00238 cucon_po_ipred_it_next(cucon_po_ipred_it_t it)
00239 { return cucon_listnode_next(it); }
00240
00241
00242 CU_SINLINE cucon_poelt_t
00243 cucon_po_ipred_it_get(cucon_po_ipred_it_t it)
00244 { return (cucon_poelt_t)cucon_listnode_ptr(it); }
00245
00246
00247
00248 CU_SINLINE cucon_po_isucc_it_t
00249 cucon_po_isucc_begin(cucon_poelt_t e)
00250 { return cucon_list_begin(&e->isuccs); }
00251
00252
00253
00254 CU_SINLINE cucon_po_isucc_it_t
00255 cucon_po_isucc_end(cucon_poelt_t e)
00256 { return cucon_list_end(&e->isuccs); }
00257
00258
00259 CU_SINLINE cucon_po_isucc_it_t
00260 cucon_po_isucc_it_next(cucon_po_isucc_it_t it)
00261 { return cucon_listnode_next(it); }
00262
00263
00264 CU_SINLINE cucon_poelt_t
00265 cucon_po_isucc_it_get(cucon_po_isucc_it_t it)
00266 { return (cucon_poelt_t)cucon_listnode_ptr(it); }
00267
00268
00269 cucon_pmap_t cucon_po_pruned_lspanning(cucon_po_t po, cucon_pmap_t S);
00270
00271
00272
00273 cu_bool_t cucon_po_conj_lspan(cucon_po_t po, cucon_pmap_t S,
00274 cu_clop(cb, cu_bool_t, cucon_poelt_t elt));
00275
00276
00277
00278
00279 void cucon_po_lspan_accum(cucon_poelt_t max, cucon_pmap_t accum);
00280
00281
00282
00283
00284 void cucon_po_uspan_accum(cucon_poelt_t min, cucon_pmap_t accum);
00285
00286
00287 cucon_pmap_t cucon_po_lspan(cucon_poelt_t max);
00288
00289
00290 cucon_pmap_t cucon_po_uspan(cucon_poelt_t min);
00291
00292
00293 cucon_pmap_t cucon_po_lspan_isecn(cucon_poelt_t max, cucon_pmap_t S);
00294
00295
00296 cucon_pmap_t cucon_po_uspan_isecn(cucon_poelt_t min, cucon_pmap_t S);
00297
00298
00299
00300 cu_bool_t cucon_po_open_range_accum(cucon_poelt_t below, cucon_poelt_t above,
00301 cucon_pmap_t S);
00302
00303
00304 cucon_pmap_t cucon_po_open_range(cucon_poelt_t min, cucon_poelt_t max);
00305
00306 cu_bool_t
00307 cucon_po_closed_range_and_succs(cucon_poelt_t min, cucon_poelt_t max,
00308 cucon_pmap_t range, cucon_pmap_t succs);
00309
00310
00311
00312 void cucon_po_connected_prune_to_max(cucon_pmap_t S, cucon_poelt_t start);
00313
00314
00315
00316 void cucon_po_connected_prune_to_min(cucon_pmap_t S, cucon_poelt_t start);
00317
00318
00319
00320 cucon_pmap_t cucon_po_inf_of_list(cucon_list_t L);
00321
00322
00323
00324 cucon_pmap_t cucon_po_sup_of_list(cucon_list_t L);
00325
00326 cucon_pmap_t cucon_po_ucollect_reachable_ljunctions(cucon_poelt_t start);
00327
00328
00329
00330 void cucon_po_print_gviz(cucon_po_t po,
00331 cu_clop(label, cu_str_t, cucon_poelt_t),
00332 FILE *out);
00333
00334
00335
00336
00337 size_t cucon_po_debug_count_connections(cucon_po_t po);
00338 void cucon_po_debug_check_nonredundant(cucon_poelt_t elt);
00339 void cucon_po_debug_dump_gviz(cucon_po_t po, FILE *out);
00340
00341
00342 CU_END_DECLARATIONS
00343
00344 #endif
00345
00346
00347
00348
00349
00350