# HG changeset patch # User Mike Becker # Date 1678010132 -3600 # Node ID d50b5dc1e058c3665c5f0ebefb756493c3a883e1 # Parent d0d95740071b5ccc913ce29409c490c6fb56187e add cx_hash_key_cxstr() macro diff -r d0d95740071b -r d50b5dc1e058 src/cx/hash_key.h --- 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 diff -r d0d95740071b -r d50b5dc1e058 tests/test_hash_key.cpp --- 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 @@ -39,15 +40,19 @@ reinterpret_cast(str), len); auto obj_key = cx_hash_key( reinterpret_cast(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(str)); EXPECT_EQ(bytes_key.data.cobj, reinterpret_cast(str)); + EXPECT_EQ(cxstr_key.data.cobj, reinterpret_cast(str)); } TEST(cx_hash_key, empty_string) {