#ifndef UCX_HASH_KEY_H
#define UCX_HASH_KEY_H
#include "common.h"
#include "string.h"
#ifdef __cplusplus
extern "C" {
#endif
struct cx_hash_key_s {
const void *data;
size_t len;
uint64_t hash;
};
typedef struct cx_hash_key_s CxHashKey;
cx_attr_nonnull
CX_EXPORT void cx_hash_murmur(CxHashKey *key);
CX_EXPORT uint32_t cx_hash_u32(
uint32_t x);
CX_EXPORT uint64_t cx_hash_u64(
uint64_t x);
cx_attr_nodiscard
CX_EXPORT CxHashKey cx_hash_key_u32(
uint32_t x);
cx_attr_nodiscard
CX_EXPORT CxHashKey cx_hash_key_u64(
uint64_t x);
cx_attr_nodiscard cx_attr_cstr_arg(
1)
CX_EXPORT CxHashKey cx_hash_key_str(
const char *str);
cx_attr_nodiscard cx_attr_cstr_arg(
1)
CX_EXPORT CxHashKey cx_hash_key_ustr(
const unsigned char *str);
cx_attr_nodiscard cx_attr_access_r(
1,
2)
CX_EXPORT CxHashKey cx_hash_key_bytes(
const unsigned char *bytes,
size_t len);
cx_attr_nodiscard
cx_attr_access_r(
1,
2)
CX_EXPORT CxHashKey cx_hash_key(
const void *obj,
size_t len);
cx_attr_nodiscard
CX_EXPORT CxHashKey cx_hash_key_cxstr(cxstring str);
cx_attr_nodiscard
CX_EXPORT CxHashKey cx_hash_key_mutstr(cxmutstr str);
cx_attr_nodiscard
CX_INLINE CxHashKey cx_hash_key_identity(CxHashKey key) {
return key;
}
#ifndef __cplusplus
#define CX_HASH_KEY(key) _Generic((key), \
CxHashKey: cx_hash_key_identity, \
cxstring: cx_hash_key_cxstr, \
cxmutstr: cx_hash_key_mutstr, \
char*: cx_hash_key_str, \
const char*: cx_hash_key_str, \
unsigned char*: cx_hash_key_ustr, \
const unsigned char*: cx_hash_key_ustr, \
uint32_t: cx_hash_key_u32, \
uint64_t: cx_hash_key_u64) \
(key)
#endif
cx_attr_nodiscard cx_attr_nonnull
CX_EXPORT int cx_hash_key_cmp(
const void *left,
const void *right);
#ifdef __cplusplus
}
CX_CPPDECL CxHashKey
CX_HASH_KEY(CxHashKey key) {
return key;
}
CX_CPPDECL CxHashKey
CX_HASH_KEY(cxstring str) {
return cx_hash_key_cxstr(str);
}
CX_CPPDECL CxHashKey
CX_HASH_KEY(cxmutstr str) {
return cx_hash_key_mutstr(str);
}
CX_CPPDECL CxHashKey
CX_HASH_KEY(
const char *str) {
return cx_hash_key_str(str);
}
CX_CPPDECL CxHashKey
CX_HASH_KEY(
const unsigned char *str) {
return cx_hash_key_ustr(str);
}
CX_CPPDECL CxHashKey
CX_HASH_KEY(
uint32_t key) {
return cx_hash_key_u32(key);
}
CX_CPPDECL CxHashKey
CX_HASH_KEY(
uint64_t key) {
return cx_hash_key_u64(key);
}
#endif
#endif