| 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, \ |