src/cx/hash_key.h

changeset 1664
e5a8c41ecb58
parent 1653
6a842bd49fea
child 1665
b79405fbf91d
equal deleted inserted replaced
1663:9c995cba3393 1664:e5a8c41ecb58
190 /** 190 /**
191 * The identity function for the CX_HASH_KEY() macro. 191 * The identity function for the CX_HASH_KEY() macro.
192 * You should never need to use this manually. 192 * You should never need to use this manually.
193 * 193 *
194 * @param key the key 194 * @param key the key
195 * @return a copy of the key 195 * @return a copy of the key (not the data)
196 */ 196 */
197 cx_attr_nodiscard 197 cx_attr_nodiscard
198 CX_INLINE CxHashKey cx_hash_key_identity(CxHashKey key) { 198 CX_INLINE CxHashKey cx_hash_key_identity(CxHashKey key) {
199 return key; 199 return key;
200 } 200 }
201 201
202 /**
203 * The dereference function for the CX_HASH_KEY() macro.
204 * You should never need to use this manually.
205 *
206 * @param key a pointer to a key
207 * @return a copy of the key (not the data)
208 */
209 cx_attr_nodiscard
210 CX_INLINE CxHashKey cx_hash_key_deref(const CxHashKey *key) {
211 return *key;
212 }
213
202 #ifndef __cplusplus 214 #ifndef __cplusplus
203 /** 215 /**
204 * Creates a hash key from any of the supported types with implicit length. 216 * Creates a hash key from any of the supported types with implicit length.
205 * 217 *
206 * Does nothing when passing a CxHashkey. 218 * Does nothing when passing a CxHashKey and dereferences CxHashKey pointers.
207 * 219 *
208 * Supported types are UCX strings, zero-terminated C strings, 220 * Supported types are UCX strings, zero-terminated C strings,
209 * and 32-bit or 64-bit unsigned integers. 221 * and 32-bit or 64-bit unsigned integers.
210 * 222 *
211 * @param key the key data 223 * @param key the key data
212 * @returns the @c CxHashKey 224 * @returns the @c CxHashKey
213 */ 225 */
214 #define CX_HASH_KEY(key) _Generic((key), \ 226 #define CX_HASH_KEY(key) _Generic((key), \
227 CxHashKey*: cx_hash_key_deref, \
228 const CxHashKey*: cx_hash_key_deref, \
215 CxHashKey: cx_hash_key_identity, \ 229 CxHashKey: cx_hash_key_identity, \
216 cxstring: cx_hash_key_cxstr, \ 230 cxstring: cx_hash_key_cxstr, \
217 cxmutstr: cx_hash_key_mutstr, \ 231 cxmutstr: cx_hash_key_mutstr, \
218 char*: cx_hash_key_str, \ 232 char*: cx_hash_key_str, \
219 const char*: cx_hash_key_str, \ 233 const char*: cx_hash_key_str, \
253 267
254 CX_CPPDECL CxHashKey CX_HASH_KEY(CxHashKey key) { 268 CX_CPPDECL CxHashKey CX_HASH_KEY(CxHashKey key) {
255 return key; 269 return key;
256 } 270 }
257 271
272 CX_CPPDECL CxHashKey CX_HASH_KEY(const CxHashKey *key) {
273 return *key;
274 }
275
258 CX_CPPDECL CxHashKey CX_HASH_KEY(cxstring str) { 276 CX_CPPDECL CxHashKey CX_HASH_KEY(cxstring str) {
259 return cx_hash_key_cxstr(str); 277 return cx_hash_key_cxstr(str);
260 } 278 }
261 279
262 CX_CPPDECL CxHashKey CX_HASH_KEY(cxmutstr str) { 280 CX_CPPDECL CxHashKey CX_HASH_KEY(cxmutstr str) {

mercurial