Sun, 05 Mar 2023 10:55:32 +0100
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 |
1.1 --- a/src/cx/hash_key.h Thu Feb 23 22:43:13 2023 +0100 1.2 +++ b/src/cx/hash_key.h Sun Mar 05 10:55:32 2023 +0100 1.3 @@ -121,6 +121,14 @@ 1.4 size_t len 1.5 ); 1.6 1.7 +/** 1.8 + * Computes a hash key from a UCX string. 1.9 + * 1.10 + * @param str the string 1.11 + * @return the hash key 1.12 + */ 1.13 +#define cx_hash_key_cxstr(str) cx_hash_key((void*)(str).ptr, (str).length) 1.14 + 1.15 #ifdef __cplusplus 1.16 } // extern "C" 1.17 #endif
2.1 --- a/tests/test_hash_key.cpp Thu Feb 23 22:43:13 2023 +0100 2.2 +++ b/tests/test_hash_key.cpp Sun Mar 05 10:55:32 2023 +0100 2.3 @@ -27,6 +27,7 @@ 2.4 */ 2.5 2.6 #include "cx/hash_key.h" 2.7 +#include "cx/string.h" 2.8 2.9 #include <gtest/gtest.h> 2.10 2.11 @@ -39,15 +40,19 @@ 2.12 reinterpret_cast<unsigned char const *>(str), len); 2.13 auto obj_key = cx_hash_key( 2.14 reinterpret_cast<void const *>(str), len); 2.15 + auto cxstr_key = cx_hash_key_cxstr(cx_str(str)); 2.16 2.17 EXPECT_EQ(str_key.hash, bytes_key.hash); 2.18 EXPECT_EQ(obj_key.hash, bytes_key.hash); 2.19 + EXPECT_EQ(cxstr_key.hash, bytes_key.hash); 2.20 EXPECT_EQ(str_key.len, len); 2.21 + EXPECT_EQ(cxstr_key.len, len); 2.22 EXPECT_EQ(bytes_key.len, len); 2.23 EXPECT_EQ(bytes_key.len, len); 2.24 EXPECT_EQ(str_key.data.cstr, str); 2.25 EXPECT_EQ(bytes_key.data.cbytes, reinterpret_cast<unsigned char const *>(str)); 2.26 EXPECT_EQ(bytes_key.data.cobj, reinterpret_cast<void const *>(str)); 2.27 + EXPECT_EQ(cxstr_key.data.cobj, reinterpret_cast<void const *>(str)); 2.28 } 2.29 2.30 TEST(cx_hash_key, empty_string) {