00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUCON_PMAP_H
00019 #define CUCON_PMAP_H
00020
00021 #include <stdlib.h>
00022 #include <cucon/fwd.h>
00023 #include <cucon/umap.h>
00024 #include <cu/memory.h>
00025 #include <cu/util.h>
00026
00027 CU_BEGIN_DECLARATIONS
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 struct cucon_pmap
00042 {
00043 struct cucon_umap impl;
00044 };
00045
00046 struct cucon_pmap_node
00047 {
00048 struct cucon_umap_node impl;
00049 };
00050
00051 typedef struct cucon_pmap_node *cucon_pmap_node_t;
00052 typedef cucon_umap_it_t cucon_pmap_it_t;
00053
00054 CU_SINLINE void *cucon_pmap_node_key(cucon_pmap_node_t node)
00055 { return (void *)cucon_umap_node_key(&node->impl); }
00056
00057
00058 CU_SINLINE void cucon_pmap_init(cucon_pmap_t map)
00059 { cucon_umap_init(&map->impl); }
00060
00061
00062 CU_SINLINE cucon_pmap_t cucon_pmap_new(void)
00063 { return (cucon_pmap_t)cucon_umap_new(); }
00064
00065
00066 CU_SINLINE void cucon_pmap_init_copy_void(cucon_pmap_t dst, cucon_pmap_t src)
00067 { cucon_umap_init_copy_void(&dst->impl, &src->impl); }
00068
00069
00070 CU_SINLINE cucon_pmap_t cucon_pmap_new_copy_void(cucon_pmap_t src)
00071 { return (cucon_pmap_t)cucon_umap_new_copy_void(&src->impl); }
00072
00073
00074
00075 CU_SINLINE void cucon_pmap_init_copy_mem(cucon_pmap_t dst, cucon_pmap_t src,
00076 size_t slot_size)
00077 { cucon_umap_init_copy_mem(&dst->impl, &src->impl, slot_size); }
00078
00079
00080
00081 CU_SINLINE cucon_pmap_t cucon_pmap_new_copy_mem(cucon_pmap_t src,
00082 size_t slot_size)
00083 { return (cucon_pmap_t)cucon_umap_new_copy_mem(&src->impl, slot_size); }
00084
00085
00086 CU_SINLINE void cucon_pmap_init_copy_mem_ctor(
00087 cucon_pmap_t dst, cucon_pmap_t src, size_t slot_size,
00088 cu_clop(value_init_copy, void, void *dst_slot, void *src_slot,
00089 uintptr_t key))
00090 { cucon_umap_init_copy_mem_ctor(&dst->impl, &src->impl, slot_size,
00091 value_init_copy); }
00092
00093
00094
00095 CU_SINLINE void cucon_pmap_init_copy_node(
00096 cucon_pmap_t dst, cucon_pmap_t src,
00097 cu_clop(node_alloc_copy, cucon_pmap_node_t, void *, uintptr_t))
00098 {
00099 cucon_umap_init_copy_node(&dst->impl, &src->impl,
00100 (cu_clop(, cucon_umap_node_t, void *, uintptr_t))node_alloc_copy);
00101 }
00102
00103
00104 CU_SINLINE cucon_pmap_node_t cucon_pmap_node_alloc(size_t slot_size)
00105 {
00106 return (cucon_pmap_node_t)cu_galloc(
00107 CU_ALIGNED_SIZEOF(struct cucon_pmap_node) + slot_size);
00108 }
00109
00110 CU_SINLINE void *cucon_pmap_node_get_mem(cucon_pmap_node_t node)
00111 { return node + 1; }
00112
00113
00114 CU_SINLINE void cucon_pmap_swap(cucon_pmap_t map0, cucon_pmap_t map1)
00115 { cucon_umap_swap(&map0->impl, &map1->impl); }
00116
00117
00118 CU_SINLINE cu_bool_t
00119 cucon_pmap_insert_init_node(cucon_pmap_t map, cucon_pmap_node_t node)
00120 { return cucon_umap_insert_init_node(&map->impl, &node->impl); }
00121
00122
00123
00124
00125
00126 CU_SINLINE cu_bool_t
00127 cucon_pmap_insert_new_node(cucon_pmap_t map, void const *key,
00128 size_t node_size, cu_ptr_ptr_t node_out)
00129 { return cucon_umap_insert_new_node(&map->impl, (uintptr_t)key,
00130 node_size, node_out); }
00131
00132
00133 CU_SINLINE cu_bool_t
00134 cucon_pmap_insert_mem(cucon_pmap_t map, void const *key,
00135 size_t slot_size, cu_ptr_ptr_t slot)
00136 { return cucon_umap_insert_mem(&map->impl, (uintptr_t)key, slot_size, slot); }
00137
00138
00139 CU_SINLINE cu_bool_t
00140 cucon_pmap_insert_void(cucon_pmap_t map, void const *key)
00141 { return cucon_umap_insert_void(&map->impl, (uintptr_t)key); }
00142
00143
00144 CU_SINLINE cu_bool_t
00145 cucon_pmap_insert_ptr(cucon_pmap_t map, void const *key, void *ptr)
00146 { return cucon_umap_insert_ptr(&map->impl, (uintptr_t)key, ptr); }
00147
00148
00149 CU_SINLINE cu_bool_t
00150 cucon_pmap_insert_int(cucon_pmap_t map, void const *key, int val)
00151 { return cucon_umap_insert_int(&map->impl, (uintptr_t)key, val); }
00152
00153
00154 CU_SINLINE cu_bool_t
00155 cucon_pmap_insert_general(cucon_pmap_t map, void const *key,
00156 cu_clop0(alloc_node, cucon_pmap_node_t),
00157 cucon_pmap_node_t *node_out)
00158 { return cucon_umap_insert_general(&map->impl, (uintptr_t)key,
00159 (cu_clop0(, cucon_umap_node_t))alloc_node,
00160 (cucon_umap_node_t *)node_out); }
00161
00162
00163 CU_SINLINE void *
00164 cucon_pmap_replace_ptr(cucon_pmap_t map, void const *key, void *ptr)
00165 { return cucon_umap_replace_ptr(&map->impl, (uintptr_t)key, ptr); }
00166
00167
00168 CU_SINLINE int
00169 cucon_pmap_replace_int(cucon_pmap_t map, void const *key, int val)
00170 { return cucon_umap_replace_int(&map->impl, (uintptr_t)key, val); }
00171
00172
00173 CU_SINLINE cu_bool_t cucon_pmap_erase(cucon_pmap_t map, void const *key)
00174 { return cucon_umap_erase(&map->impl, (uintptr_t)key); }
00175
00176
00177 CU_SINLINE void *cucon_pmap_erase_ptr(cucon_pmap_t map, void const *key)
00178 { return cucon_umap_erase_ptr(&map->impl, (uintptr_t)key); }
00179
00180
00181 CU_SINLINE int cucon_pmap_erase_int(cucon_pmap_t map, void const *key)
00182 { return cucon_umap_erase_int(&map->impl, (uintptr_t)key); }
00183
00184
00185 CU_SINLINE cu_bool_t
00186 cucon_pmap_erase_keep_cap(cucon_pmap_t map, void const *key)
00187 { return cucon_umap_erase_keep_cap(&map->impl, (uintptr_t)key); }
00188
00189
00190 CU_SINLINE cucon_pmap_node_t
00191 cucon_pmap_pop_any_node(cucon_pmap_t map)
00192 { return (cucon_pmap_node_t)cucon_umap_pop_any_node(&map->impl); }
00193
00194
00195 CU_SINLINE void const *
00196 cucon_pmap_pop_any_key(cucon_pmap_t map)
00197 { return (void const *)cucon_umap_pop_any_key(&map->impl); }
00198
00199
00200 CU_SINLINE void cucon_pmap_update_cap(cucon_pmap_t map)
00201 { cucon_umap_update_cap(&map->impl); }
00202
00203
00204 CU_SINLINE cucon_pmap_node_t
00205 cucon_pmap_find_node(cucon_pmap_t map, void const *key)
00206 { return (cucon_pmap_node_t)cucon_umap_find_node(&map->impl, (uintptr_t)key); }
00207
00208
00209 CU_SINLINE void *cucon_pmap_find_mem(cucon_pmap_t map, void const *key)
00210 { return cucon_umap_find_mem(&map->impl, (uintptr_t)key); }
00211
00212
00213 CU_SINLINE void *cucon_pmap_find_ptr(cucon_pmap_t map, void const *key)
00214 { return cucon_umap_find_ptr(&map->impl, (uintptr_t)key); }
00215
00216
00217 CU_SINLINE int cucon_pmap_find_int(cucon_pmap_t map, void const *key)
00218 { return cucon_umap_find_int(&map->impl, (uintptr_t)key); }
00219
00220
00221 CU_SINLINE cu_bool_t cucon_pmap_find_void(cucon_pmap_t map, void const *key)
00222 { return cucon_pmap_find_node(map, key) != NULL; }
00223
00224
00225 void cucon_pmap_iter_mem(cucon_pmap_t map,
00226 cu_clop(cb, void, void const *key, void *value));
00227
00228 void cucon_pmap_iter_ptr(cucon_pmap_t map,
00229 cu_clop(cb, void, void const *key, void *value));
00230
00231 cu_bool_t cucon_pmap_conj_general(cucon_pmap_t map, size_t node_offset,
00232 cu_clop(cb, cu_bool_t, void const*, void*));
00233
00234
00235 cu_bool_t cucon_pmap_conj_mem(cucon_pmap_t map,
00236 cu_clop(cb, cu_bool_t, void const *, void *));
00237 cu_bool_t cucon_pmap_conj_ptr(cucon_pmap_t map,
00238 cu_clop(cb, cu_bool_t, void const *, void *));
00239
00240
00241 void cucon_pmap_iter_keys(cucon_pmap_t map, cu_clop(cb, void, void const *));
00242
00243
00244 cu_bool_t cucon_pmap_conj_keys(cucon_pmap_t map,
00245 cu_clop(cb, cu_bool_t, void const *));
00246
00247
00248 CU_SINLINE cu_bool_t
00249 cucon_pmap_conj_node(cucon_pmap_t map,
00250 cu_clop(cb, cu_bool_t, cucon_pmap_node_t node))
00251 {
00252 return cucon_umap_conj_node(&map->impl,
00253 (cu_clop(, cu_bool_t, cucon_umap_node_t))cb);
00254 }
00255
00256
00257 CU_SINLINE void
00258 cucon_pmap_assign_isecn_union(cucon_pmap_t map0, cucon_pmap_t map1)
00259 { cucon_umap_assign_isecn_union(&map0->impl, &map1->impl); }
00260
00261
00262 CU_SINLINE void
00263 cucon_pmap_move_isecn(cucon_pmap_t dst, cucon_pmap_t src0, cucon_pmap_t src1)
00264 { cucon_umap_move_isecn(&dst->impl, &src0->impl, &src1->impl); }
00265
00266
00267 CU_SINLINE void
00268 cucon_pmap_assign_isecn(cucon_pmap_t dst, cucon_pmap_t src)
00269 { cucon_umap_assign_isecn(&dst->impl, &src->impl); }
00270
00271
00272 CU_SINLINE void
00273 cucon_pmap_assign_union_void(cucon_pmap_t dst, cucon_pmap_t src)
00274 { cucon_umap_assign_union_void(&dst->impl, &src->impl); }
00275
00276
00277 CU_SINLINE void
00278 cucon_pmap_dump_stats(cucon_pmap_t map, FILE *out)
00279 { cucon_umap_dump_stats(&map->impl, out); }
00280
00281
00282 CU_SINLINE size_t
00283 cucon_pmap_size(cucon_pmap_t map)
00284 { return map->impl.size; }
00285
00286
00287 CU_SINLINE cu_bool_t
00288 cucon_pmap_is_empty(cucon_pmap_t map)
00289 {return !map->impl.size;}
00290
00291
00292 CU_SINLINE cu_bool_t
00293 cucon_pmap_eq_keys(cucon_pmap_t map0, cucon_pmap_t map1)
00294 { return cucon_umap_eq_keys(&map0->impl, &map1->impl); }
00295
00296
00297 CU_SINLINE cu_bool_t
00298 cucon_pmap_eq_mem(cucon_pmap_t map0, cucon_pmap_t map1, size_t slot_size)
00299 { return cucon_umap_eq_mem(&map0->impl, &map1->impl, slot_size); }
00300
00301
00302 CU_SINLINE cu_bool_t cucon_pmap_eq_ptr(cucon_pmap_t map0, cucon_pmap_t map1)
00303 { return cucon_umap_eq_ptr(&map0->impl, &map1->impl); }
00304
00305
00306 CU_SINLINE cu_hash_t cucon_pmap_hash_keys(cucon_pmap_t map)
00307 { return cucon_umap_hash_keys(&map->impl); }
00308
00309
00310 CU_SINLINE cu_hash_t cucon_pmap_hash_mem(cucon_pmap_t map, size_t slot_size)
00311 { return cucon_umap_hash_mem(&map->impl, slot_size); }
00312
00313
00314 CU_SINLINE cu_hash_t cucon_pmap_hash_ptr(cucon_pmap_t map)
00315 { return cucon_umap_hash_ptr(&map->impl); }
00316
00317
00318
00319
00320 CU_SINLINE cucon_pmap_it_t cucon_pmap_begin(cucon_pmap_t map)
00321 { return cucon_umap_begin(&map->impl); }
00322
00323 CU_SINLINE cucon_pmap_it_t cucon_pmap_end(cucon_pmap_t map)
00324 { return cucon_umap_end(&map->impl); }
00325
00326 CU_SINLINE cu_bool_t
00327 cucon_pmap_end_eq(cucon_pmap_t map, cucon_pmap_it_t it)
00328 {
00329 return it.node == (void *)-1;
00330 }
00331
00332 #define cucon_pmap_it_eq(it0, it1) ((it0.node) == (it1.node))
00333
00334 CU_SINLINE cucon_pmap_it_t cucon_pmap_it_next(cucon_pmap_it_t it)
00335 { return cucon_umap_it_next(it); }
00336
00337
00338 #define cucon_pmap_it_key(it) ((void*)(it).node->key)
00339
00340
00341 #define cucon_pmap_it_value_mem(it) ((void*)CU_ALIGNED_PTR_END((it).node))
00342 #define cucon_pmap_it_value_ptr(it) (*(void**)CU_ALIGNED_PTR_END((it).node))
00343
00344
00345
00346 void cucon_pmap_dump_idr_ptr(cucon_pmap_t map, FILE *out);
00347
00348
00349 #define cucon_pmap_cct cucon_pmap_init
00350
00351 #define cucon_pmap_cct_copy_void cucon_pmap_init_copy_void
00352
00353 #define cucon_pmap_cct_copy_mem cucon_pmap_init_copy_mem
00354
00355 #define cucon_pmap_cct_copy_mem_ctor cucon_pmap_init_copy_mem_ctor
00356
00357 #define cucon_pmap_cct_copy_node cucon_pmap_init_copy_node
00358
00359
00360 CU_END_DECLARATIONS
00361
00362 #endif