src/cx/hash_key.h

changeset 1675
36c0fb2b60b2
parent 1665
b79405fbf91d
--- a/src/cx/hash_key.h	Sun Dec 28 15:45:39 2025 +0100
+++ b/src/cx/hash_key.h	Sun Dec 28 17:31:20 2025 +0100
@@ -40,10 +40,6 @@
 #include "common.h"
 #include "string.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /** Internal structure for a key within a hash map. */
 struct cx_hash_key_s {
     /**
@@ -78,8 +74,8 @@
  * @param key the key, the hash shall be computed for
  * @see cx_hash_key()
  */
-cx_attr_nonnull
-CX_EXPORT void cx_hash_murmur(CxHashKey *key);
+CX_EXTERN CX_NONNULL
+void cx_hash_murmur(CxHashKey *key);
 
 /**
  * Mixes up a 32-bit integer to be used as a hash.
@@ -89,7 +85,8 @@
  * @param x the integer
  * @return the hash
  */
-CX_INLINE uint32_t cx_hash_u32(uint32_t x) {
+CX_INLINE
+uint32_t cx_hash_u32(uint32_t x) {
     x = ((x >> 16) ^ x) * 0x45d9f3bu;
     x = ((x >> 16) ^ x) * 0x45d9f3bu;
     x = (x >> 16) ^ x;
@@ -104,7 +101,8 @@
  * @param x the integer
  * @return the hash
  */
-CX_INLINE uint64_t cx_hash_u64(uint64_t x){
+CX_INLINE
+uint64_t cx_hash_u64(uint64_t x){
     x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
     x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb);
     x = x ^ (x >> 31);
@@ -122,9 +120,8 @@
  * @param len the length of the object in memory
  * @return the hash key
  */
-cx_attr_nodiscard
-cx_attr_access_r(1, 2)
-CX_EXPORT CxHashKey cx_hash_key(const void *obj, size_t len);
+CX_EXTERN CX_NODISCARD CX_ACCESS_R(1, 2)
+CxHashKey cx_hash_key(const void *obj, size_t len);
 
 /**
  * Computes a hash key from a 32-bit integer.
@@ -132,8 +129,8 @@
  * @param x the integer
  * @return the hash key
  */
-cx_attr_nodiscard
-CX_INLINE CxHashKey cx_hash_key_u32(uint32_t x) {
+CX_NODISCARD CX_INLINE
+CxHashKey cx_hash_key_u32(uint32_t x) {
     CxHashKey key;
     key.data = NULL;
     key.len = 0;
@@ -147,8 +144,8 @@
  * @param x the integer
  * @return the hash key
  */
-cx_attr_nodiscard
-CX_INLINE CxHashKey cx_hash_key_u64(uint64_t x) {
+CX_NODISCARD CX_INLINE
+CxHashKey cx_hash_key_u64(uint64_t x) {
     CxHashKey key;
     key.data = NULL;
     key.len = 0;
@@ -164,8 +161,8 @@
  * @param str the string
  * @return the hash key
  */
-cx_attr_nodiscard cx_attr_cstr_arg(1)
-CX_INLINE CxHashKey cx_hash_key_str(const char *str) {
+CX_NODISCARD CX_CSTR_ARG(1) CX_INLINE
+CxHashKey cx_hash_key_str(const char *str) {
     return cx_hash_key((const void*)str, str == NULL ? 0 : strlen(str));
 }
 
@@ -180,8 +177,8 @@
  * @param str the string
  * @return the hash key
  */
-cx_attr_nodiscard cx_attr_cstr_arg(1)
-CX_INLINE CxHashKey cx_hash_key_ustr(const unsigned char *str) {
+CX_NODISCARD CX_CSTR_ARG(1) CX_INLINE
+CxHashKey cx_hash_key_ustr(const unsigned char *str) {
     return cx_hash_key((const void*)str, str == NULL ? 0 : strlen((const char*)str));
 }
 
@@ -192,8 +189,8 @@
  * @param len the length
  * @return the hash key
  */
-cx_attr_nodiscard cx_attr_access_r(1, 2)
-CX_INLINE CxHashKey cx_hash_key_bytes(const unsigned char *bytes, size_t len) {
+CX_NODISCARD CX_ACCESS_R(1, 2) CX_INLINE
+CxHashKey cx_hash_key_bytes(const unsigned char *bytes, size_t len) {
     return cx_hash_key((const void*)bytes, len);
 }
 
@@ -203,8 +200,8 @@
  * @param str the string
  * @return the hash key
  */
-cx_attr_nodiscard
-CX_INLINE CxHashKey cx_hash_key_cxstr(cxstring str) {
+CX_NODISCARD CX_INLINE
+CxHashKey cx_hash_key_cxstr(cxstring str) {
     return cx_hash_key((void*)str.ptr, str.length);
 }
 
@@ -214,8 +211,8 @@
  * @param str the string
  * @return the hash key
  */
-cx_attr_nodiscard
-CX_INLINE CxHashKey cx_hash_key_mutstr(cxmutstr str) {
+CX_NODISCARD CX_INLINE
+CxHashKey cx_hash_key_mutstr(cxmutstr str) {
     return cx_hash_key((void*)str.ptr, str.length);
 }
 
@@ -226,8 +223,8 @@
  * @param key the key
  * @return a copy of the key (not the data)
  */
-cx_attr_nodiscard
-CX_INLINE CxHashKey cx_hash_key_identity(CxHashKey key) {
+CX_NODISCARD CX_INLINE
+CxHashKey cx_hash_key_identity(CxHashKey key) {
     return key;
 }
 
@@ -238,8 +235,8 @@
  * @param key a pointer to a key
  * @return a copy of the key (not the data)
  */
-cx_attr_nodiscard
-CX_INLINE CxHashKey cx_hash_key_deref(const CxHashKey *key) {
+CX_NODISCARD CX_INLINE
+CxHashKey cx_hash_key_deref(const CxHashKey *key) {
     return *key;
 }
 
@@ -279,8 +276,8 @@
  * @param right (@c CxHashKey*) the second key
  * @return zero when the keys equal, non-zero when they differ
  */
-cx_attr_nodiscard cx_attr_nonnull
-CX_EXPORT int cx_hash_key_cmp(const void *left, const void *right);
+CX_EXTERN CX_NODISCARD CX_NONNULL
+int cx_hash_key_cmp(const void *left, const void *right);
 
 /**
  * Interprets the key data as a string and returns it.
@@ -288,11 +285,10 @@
  * @param key the key
  * @return the key data as a string
  */
-CX_EXPORT cxstring cx_hash_key_as_string(const CxHashKey *key);
+CX_EXTERN
+cxstring cx_hash_key_as_string(const CxHashKey *key);
 
 #ifdef __cplusplus
-} // extern "C"
-
 // ----------------------------------------------------------
 // Overloads of CX_HASH_KEY (the C++ version of a _Generic)
 // ----------------------------------------------------------

mercurial