00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUCON_UCMAP_H
00019 #define CUCON_UCMAP_H
00020
00021
00022
00023 #define CUCONP_UCMAP_ENABLE_HCONS 1
00024
00025 #include <cucon/fwd.h>
00026 #include <stdio.h>
00027 #include <cu/clos.h>
00028 #if CUCONP_UCMAP_ENABLE_HCONS
00029 # include <cuoo/hcobj.h>
00030 #else
00031 # include <cuoo/fwd.h>
00032 #endif
00033 #include <stdint.h>
00034 #include <limits.h>
00035
00036 CU_BEGIN_DECLARATIONS
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 struct cucon_ucmap
00061 {
00062 #if CUCONP_UCMAP_ENABLE_HCONS
00063 CUOO_HCOBJ
00064 #else
00065 CUOO_OBJ
00066 #endif
00067 uintptr_t key;
00068 cucon_ucmap_t left;
00069 cucon_ucmap_t right;
00070 uintptr_t value;
00071 };
00072
00073 #if CUCONP_UCMAP_ENABLE_HCONS
00074 extern cuoo_type_t cuconP_ucmap_type;
00075 CU_SINLINE cuoo_type_t cucon_ucmap_type()
00076 { return cuconP_ucmap_type; }
00077 #endif
00078
00079 #define cucon_ucmap_int_none INT_MIN
00080
00081
00082 CU_SINLINE cucon_ucmap_t cucon_ucmap_empty() { return NULL; }
00083
00084
00085 CU_SINLINE cu_bool_t
00086 cucon_ucmap_is_empty(cucon_ucmap_t map) { return map == NULL; }
00087
00088
00089 cucon_ucmap_t cucon_ucmap_singleton(uintptr_t key, uintptr_t val);
00090
00091
00092 CU_SINLINE cucon_ucmap_t
00093 cucon_ucmap_singleton_ptr(uintptr_t key, void *val)
00094 { return cucon_ucmap_singleton(key, (uintptr_t)val); }
00095
00096
00097 CU_SINLINE cu_bool_t
00098 cucon_ucmap_is_singleton(cucon_ucmap_t map)
00099 { return map != NULL && map->left == NULL && map->right == NULL; }
00100
00101
00102
00103 cucon_ucmap_t cucon_ucmap_insert(cucon_ucmap_t, uintptr_t, uintptr_t);
00104
00105
00106 CU_SINLINE cucon_ucmap_t
00107 cucon_ucmap_insert_ptr(cucon_ucmap_t map, uintptr_t key, void *val)
00108 { return cucon_ucmap_insert(map, key, (uintptr_t)val); }
00109
00110
00111 CU_SINLINE cucon_ucmap_t
00112 cucon_ucmap_insert_int(cucon_ucmap_t map, uintptr_t key, int val)
00113 { return cucon_ucmap_insert(map, key, val); }
00114
00115
00116
00117 cucon_ucmap_t cucon_ucmap_erase(cucon_ucmap_t map, uintptr_t key);
00118
00119
00120 cu_bool_t cucon_ucmap_contains(cucon_ucmap_t map, uintptr_t key);
00121
00122
00123
00124 cu_bool_t cucon_ucmap_find(cucon_ucmap_t map, uintptr_t key, uintptr_t *v_out);
00125
00126
00127 void *cucon_ucmap_find_ptr(cucon_ucmap_t map, uintptr_t key);
00128
00129
00130
00131 int cucon_ucmap_find_int(cucon_ucmap_t map, uintptr_t key);
00132
00133
00134 size_t cucon_ucmap_card(cucon_ucmap_t map);
00135
00136
00137 cu_bool_t cucon_ucmap_iterA(cu_clop(f, cu_bool_t, uintptr_t, uintptr_t),
00138 cucon_ucmap_t M);
00139
00140 cu_bool_t cucon_ucmap_iterA_clipped(cu_clop(f, cu_bool_t, uintptr_t, uintptr_t),
00141 cucon_ucmap_t M,
00142 uintptr_t k_min, uintptr_t k_max);
00143
00144
00145
00146 void cucon_ucmap_iter_ptr(cucon_ucmap_t M, cu_clop(f, void, uintptr_t, void *));
00147
00148
00149
00150 void cucon_ucmap_iter_int(cucon_ucmap_t M, cu_clop(f, void, uintptr_t, int));
00151
00152
00153 cu_bool_t cucon_ucmap_conj_ptr(cucon_ucmap_t map,
00154 cu_clop(f, cu_bool_t, uintptr_t, void *));
00155
00156
00157 cu_bool_t cucon_ucmap_conj_int(cucon_ucmap_t map,
00158 cu_clop(cb, cu_bool_t, uintptr_t, int));
00159
00160
00161
00162
00163 cucon_ucmap_t cucon_ucmap_left_union(cucon_ucmap_t M0, cucon_ucmap_t M1);
00164
00165
00166 uintptr_t cucon_ucmap_min_ukey(cucon_ucmap_t map);
00167
00168
00169 uintptr_t cucon_ucmap_max_ukey(cucon_ucmap_t map);
00170
00171 cucon_ucmap_t cucon_ucmap_uclip(cucon_ucmap_t map,
00172 uintptr_t k_min, uintptr_t k_max);
00173
00174 cucon_ucmap_t cucon_ucmap_clip(cucon_ucmap_t map,
00175 uintptr_t k_min, uintptr_t k_max);
00176
00177
00178
00179 cu_bool_t cucon_ucmap_eq(cucon_ucmap_t map0, cucon_ucmap_t map1);
00180
00181
00182
00183 cu_bool_t cucon_ucmap_eq_ptr(cu_clop(f, cu_bool_t, void const *, void const *),
00184 cucon_ucmap_t map0, cucon_ucmap_t map1);
00185
00186
00187
00188 int cucon_ucmap_cmp(cucon_ucmap_t map0, cucon_ucmap_t map1);
00189
00190
00191
00192
00193 int cucon_ucmap_cmp_ptr(cu_clop(f, int, void const *, void const *),
00194 cucon_ucmap_t map0, cucon_ucmap_t map1);
00195
00196
00197 void cucon_ucmap_dump(cucon_ucmap_t map, FILE *out);
00198
00199
00200
00201 CU_END_DECLARATIONS
00202
00203 #endif