00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUCON_RUMAP_H
00019 #define CUCON_RUMAP_H
00020
00021 #include <cucon/umap.h>
00022 #include <cu/conf.h>
00023 #include <cu/wchar.h>
00024
00025 CU_BEGIN_DECLARATIONS
00026
00027
00028
00029 struct cucon_rumap
00030 {
00031 struct cucon_umap branches;
00032 void *data;
00033 };
00034
00035
00036 void cucon_rumap_init(cucon_rumap_t rmap);
00037
00038
00039 cucon_rumap_t cucon_rumap_new(void);
00040
00041
00042 void cucon_rumap_swap(cucon_rumap_t map0, cucon_rumap_t map1);
00043
00044
00045 CU_SINLINE void *
00046 cucon_rumap_value(cucon_rumap_t rmap)
00047 {
00048 return rmap->data;
00049 }
00050
00051
00052 CU_SINLINE void
00053 cucon_rumap_set_value(cucon_rumap_t rmap, void *ptr)
00054 {
00055 rmap->data = ptr;
00056 }
00057
00058
00059 CU_SINLINE cu_bool_t
00060 cucon_rumap_is_leaf(cucon_rumap_t rmap)
00061 {
00062 return cucon_umap_is_empty(&rmap->branches);
00063 }
00064
00065
00066
00067 cucon_rumap_t cucon_rumap_mref(cucon_rumap_t rmap, uintptr_t key);
00068
00069
00070 CU_SINLINE cucon_rumap_t
00071 cucon_rumap_cref(cucon_rumap_t rmap, uintptr_t key)
00072 {
00073 return (cucon_rumap_t)cucon_umap_find_mem(&rmap->branches, key);
00074 }
00075
00076
00077
00078
00079
00080 cucon_rumap_t
00081 cucon_rumap_mref_by_uint8_arr(cucon_rumap_t rmap,
00082 uint8_t const *key_arr, size_t key_cnt);
00083 cucon_rumap_t
00084 cucon_rumap_mref_by_uint16_arr(cucon_rumap_t rmap,
00085 uint16_t const *key_arr, size_t key_cnt);
00086 cucon_rumap_t
00087 cucon_rumap_mref_by_uint32_arr(cucon_rumap_t rmap,
00088 uint32_t const *key_arr, size_t key_cnt);
00089 #if CUCONF_WIDTHOF_INTPTR_T >= 64
00090 cucon_rumap_t
00091 cucon_rumap_mref_by_uint64_arr(cucon_rumap_t rmap,
00092 uint64_t const *key_arr, size_t key_cnt);
00093 #endif
00094
00095 #if CUCONF_WIDTHOF_INTPTR_T < CUCONF_WIDTHOF_WCHAR_T \
00096 || CUCONF_WIDTHOF_INTPTR_T < 32
00097 #error Failed size assumptions. Please report this incompatibility including
00098 #error the output of the generated file ccf/config.h, your architecture
00099 #error (uname -a) and the compiler your used.
00100 #endif
00101
00102 #define cuconP_APPLY(macro, ...) macro(__VA_ARGS__)
00103 #define cuconP_RUMAP_MREF_ARR(width, rmap, key_arr, key_cnt) \
00104 cucon_rumap_mref_by_uint##width##_arr( \
00105 rmap, (uint##width##_t *)key_arr, key_cnt)
00106
00107 CU_SINLINE cucon_rumap_t
00108 cucon_rumap_mref_by_uchar_arr(cucon_rumap_t rmap,
00109 unsigned char const *key_arr, size_t key_cnt)
00110 {
00111 return cuconP_APPLY(cuconP_RUMAP_MREF_ARR, CUCONF_WIDTHOF_CHAR,
00112 rmap, key_arr, key_cnt);
00113 }
00114 CU_SINLINE cucon_rumap_t
00115 cucon_rumap_mref_by_schar_arr(cucon_rumap_t rmap,
00116 signed char const *key_arr, size_t key_cnt)
00117 {
00118 return cuconP_APPLY(cuconP_RUMAP_MREF_ARR, CUCONF_WIDTHOF_CHAR,
00119 rmap, key_arr, key_cnt);
00120 }
00121 CU_SINLINE cucon_rumap_t
00122 cucon_rumap_mref_by_short_arr(cucon_rumap_t rmap,
00123 short const *key_arr, size_t key_cnt)
00124 {
00125 return cuconP_APPLY(cuconP_RUMAP_MREF_ARR, CUCONF_WIDTHOF_SHORT,
00126 rmap, key_arr, key_cnt);
00127 }
00128 CU_SINLINE cucon_rumap_t
00129 cucon_rumap_mref_by_ushort_arr(cucon_rumap_t rmap,
00130 unsigned short const *key_arr, size_t key_cnt)
00131 {
00132 return cuconP_APPLY(cuconP_RUMAP_MREF_ARR, CUCONF_WIDTHOF_SHORT,
00133 rmap, key_arr, key_cnt);
00134 }
00135 CU_SINLINE cucon_rumap_t
00136 cucon_rumap_mref_by_int_arr(cucon_rumap_t rmap,
00137 int const *key_arr, size_t key_cnt)
00138 {
00139 return cuconP_APPLY(cuconP_RUMAP_MREF_ARR, CUCONF_WIDTHOF_INT,
00140 rmap, key_arr, key_cnt);
00141 }
00142 CU_SINLINE cucon_rumap_t
00143 cucon_rumap_mref_by_uint_arr(cucon_rumap_t rmap,
00144 unsigned int const *key_arr, size_t key_cnt)
00145 {
00146 return cuconP_APPLY(cuconP_RUMAP_MREF_ARR, CUCONF_WIDTHOF_INT,
00147 rmap, key_arr, key_cnt);
00148 }
00149
00150 CU_SINLINE cucon_rumap_t
00151 cucon_rumap_mref_by_char_arr(cucon_rumap_t rmap,
00152 char const *key_arr, size_t key_cnt)
00153 {
00154 return cuconP_APPLY(cuconP_RUMAP_MREF_ARR, CUCONF_WIDTHOF_CHAR,
00155 rmap, key_arr, key_cnt);
00156 }
00157 CU_SINLINE cucon_rumap_t
00158 cucon_rumap_mref_by_wchar_arr(cucon_rumap_t rmap,
00159 cu_wchar_t const *key_arr, size_t key_cnt)
00160 {
00161 return cuconP_APPLY(cuconP_RUMAP_MREF_ARR, CU_WCHAR_WIDTH,
00162 rmap, key_arr, key_cnt);
00163 }
00164 #undef cuconP_APPLY
00165 #undef cuconP_RUMAP_MREF_ARR
00166
00167 cucon_rumap_t cucon_rumap_mref_by_wstring(cucon_rumap_t rmap, cu_wstring_t s);
00168
00169 size_t cucon_rumap_assign_left_union(cucon_rumap_t dst, cucon_rumap_t src);
00170 size_t cucon_rumap_assign_right_union(cucon_rumap_t dst, cucon_rumap_t src);
00171
00172
00173
00174
00175 CU_SINLINE cu_bool_t
00176 cucon_rumap_conj(cucon_rumap_t rmap,
00177 cu_clop(fn, cu_bool_t, uintptr_t, cucon_rumap_t))
00178 {
00179 return cucon_umap_conj_mem(&rmap->branches,
00180 (cu_clop(, cu_bool_t, uintptr_t, void *))fn);
00181 }
00182
00183
00184 CU_END_DECLARATIONS
00185
00186 #endif