add cx_hash_key_cxstr() macro

Sun, 05 Mar 2023 10:55:32 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 05 Mar 2023 10:55:32 +0100
changeset 663
d50b5dc1e058
parent 662
d0d95740071b
child 664
af5bf4603a5d

add cx_hash_key_cxstr() macro

src/cx/hash_key.h file | annotate | diff | comparison | revisions
tests/test_hash_key.cpp file | annotate | diff | comparison | revisions
--- a/src/cx/hash_key.h	Thu Feb 23 22:43:13 2023 +0100
+++ b/src/cx/hash_key.h	Sun Mar 05 10:55:32 2023 +0100
@@ -121,6 +121,14 @@
         size_t len
 );
 
+/**
+ * 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)
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
--- a/tests/test_hash_key.cpp	Thu Feb 23 22:43:13 2023 +0100
+++ b/tests/test_hash_key.cpp	Sun Mar 05 10:55:32 2023 +0100
@@ -27,6 +27,7 @@
  */
 
 #include "cx/hash_key.h"
+#include "cx/string.h"
 
 #include <gtest/gtest.h>
 
@@ -39,15 +40,19 @@
             reinterpret_cast<unsigned char const *>(str), len);
     auto obj_key = cx_hash_key(
             reinterpret_cast<void const *>(str), len);
+    auto cxstr_key = cx_hash_key_cxstr(cx_str(str));
 
     EXPECT_EQ(str_key.hash, bytes_key.hash);
     EXPECT_EQ(obj_key.hash, bytes_key.hash);
+    EXPECT_EQ(cxstr_key.hash, bytes_key.hash);
     EXPECT_EQ(str_key.len, len);
+    EXPECT_EQ(cxstr_key.len, len);
     EXPECT_EQ(bytes_key.len, len);
     EXPECT_EQ(bytes_key.len, len);
     EXPECT_EQ(str_key.data.cstr, str);
     EXPECT_EQ(bytes_key.data.cbytes, reinterpret_cast<unsigned char const *>(str));
     EXPECT_EQ(bytes_key.data.cobj, reinterpret_cast<void const *>(str));
+    EXPECT_EQ(cxstr_key.data.cobj, reinterpret_cast<void const *>(str));
 }
 
 TEST(cx_hash_key, empty_string) {

mercurial