ucx/cx/hash_key.h

changeset 11
0aa8cbd7912e
parent 0
1a157da63d7c
child 16
04c9f8d8f03b
--- a/ucx/cx/hash_key.h	Fri Jan 03 21:40:57 2025 +0100
+++ b/ucx/cx/hash_key.h	Sat Jan 04 13:03:01 2025 +0100
@@ -38,6 +38,7 @@
 #define UCX_HASH_KEY_H
 
 #include "common.h"
+#include "string.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -46,7 +47,7 @@
 /** Internal structure for a key within a hash map. */
 struct cx_hash_key_s {
     /** The key data. */
-    void const *data;
+    const void *data;
     /**
      * The key data length.
      */
@@ -70,6 +71,7 @@
  *
  * @param key the key, the hash shall be computed for
  */
+cx_attr_nonnull
 void cx_hash_murmur(CxHashKey *key);
 
 /**
@@ -80,8 +82,9 @@
  * @param str the string
  * @return the hash key
  */
-__attribute__((__warn_unused_result__))
-CxHashKey cx_hash_key_str(char const *str);
+cx_attr_nodiscard
+cx_attr_cstr_arg(1)
+CxHashKey cx_hash_key_str(const char *str);
 
 /**
  * Computes a hash key from a byte array.
@@ -90,9 +93,10 @@
  * @param len the length
  * @return the hash key
  */
-__attribute__((__warn_unused_result__))
+cx_attr_nodiscard
+cx_attr_access_r(1, 2)
 CxHashKey cx_hash_key_bytes(
-        unsigned char const *bytes,
+        const unsigned char *bytes,
         size_t len
 );
 
@@ -107,9 +111,10 @@
  * @param len the length of object in memory
  * @return the hash key
  */
-__attribute__((__warn_unused_result__))
+cx_attr_nodiscard
+cx_attr_access_r(1, 2)
 CxHashKey cx_hash_key(
-        void const *obj,
+        const void *obj,
         size_t len
 );
 
@@ -119,7 +124,18 @@
  * @param str the string
  * @return the hash key
  */
-#define cx_hash_key_cxstr(str) cx_hash_key((void*)(str).ptr, (str).length)
+cx_attr_nodiscard
+static inline CxHashKey cx_hash_key_cxstr(cxstring str) {
+    return cx_hash_key(str.ptr, str.length);
+}
+
+/**
+ * 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_cxstr(cx_strcast(str))
 
 #ifdef __cplusplus
 } // extern "C"

mercurial