diff -r 12f38affefd5 -r 415bf2ce6bab src/cx/hash_key.h --- a/src/cx/hash_key.h Sun Dec 22 22:14:57 2024 +0100 +++ b/src/cx/hash_key.h Sun Dec 22 22:53:53 2024 +0100 @@ -38,6 +38,7 @@ #define UCX_HASH_KEY_H #include "common.h" +#include "string.h" #ifdef __cplusplus extern "C" { @@ -112,22 +113,51 @@ */ cx_attr_nodiscard cx_attr_access_r(1, 2) -__attribute__((__warn_unused_result__)) CxHashKey cx_hash_key( const void *obj, size_t len ); +#ifdef __cplusplus +} // extern "C" + +cx_attr_nodiscard +static inline CxHashKey cx_hash_key_cxstr(cxstring str) { + return cx_hash_key(str.ptr, str.length); +} + +cx_attr_nodiscard +static inline CxHashKey cx_hash_key_cxstr(cxmutstr str) { + return cx_hash_key(str.ptr, str.length); +} + +#else /** * Computes a hash key from a UCX string. * * @param str the string * @return the hash key */ -#define cx_hash_key_cxstr(str) cx_hash_key((void*)(str).ptr, (str).length) +#define cx_hash_key_cxstr(str) _Generic((str), \ + cxstring: cx_hash_key_cxstring, \ + cxmutstr: cx_hash_key_cxmutstr) \ + (str) -#ifdef __cplusplus -} // extern "C" +/** + * @copydoc cx_hash_key_cxstr() + */ +cx_attr_nodiscard +static inline CxHashKey cx_hash_key_cxstring(cxstring str) { + return cx_hash_key(str.ptr, str.length); +} + +/** + * @copydoc cx_hash_key_cxstr() + */ +cx_attr_nodiscard +static inline CxHashKey cx_hash_key_cxmutstr(cxmutstr str) { + return cx_hash_key(str.ptr, str.length); +} #endif #endif // UCX_HASH_KEY_H