diff options
author | Sergei Krivonos <sergei.krivonos@mariadb.com> | 2021-11-03 14:06:55 +0200 |
---|---|---|
committer | Sergei Krivonos <sergeikrivonos@gmail.com> | 2021-11-03 13:30:08 +0200 |
commit | 8a6e6da75866d9007c4cb73b5e5083a40ac4d3f4 (patch) | |
tree | 54ad5f9d23c017520f6c767e49534e7628ee8daa | |
parent | 3265fc0099135658e99206678bbd16ac9817cd83 (diff) | |
download | mariadb-git-bb-10.8-MDEV-18477.tar.gz |
MDEV-18477: add generic_hash_fnv1abb-10.8-MDEV-18477
-rw-r--r-- | include/hash.h | 9 | ||||
-rw-r--r-- | mysys/hash.cc | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/include/hash.h b/include/hash.h index c0a846ac120..a662b7378f2 100644 --- a/include/hash.h +++ b/include/hash.h @@ -41,13 +41,22 @@ extern "C" { #define HASH_UNIQUE 1 /* hash_insert fails on duplicate key */ #define HASH_THREAD_SPECIFIC 2 /* Mark allocated memory THREAD_SPECIFIC */ + typedef uint32 my_hash_value_type; typedef uchar *(*my_hash_get_key)(const uchar *,size_t*,my_bool); typedef my_hash_value_type (*my_hash_function)(CHARSET_INFO *, const uchar *, size_t); +/** + * @param ci - not used, for my_hash_function signature compatibility + * @param p - data + * @param sz - bytes count + */ +my_hash_value_type generic_hash_fnv1a(CHARSET_INFO *ci, const uchar *p, size_t sz); + typedef void (*my_hash_free_key)(void *); typedef my_bool (*my_hash_walk_action)(void *,void *); + typedef struct st_hash { size_t key_offset,key_length; /* Length of key if const length */ size_t blength; diff --git a/mysys/hash.cc b/mysys/hash.cc index d9132b28cd7..b12d8f0e6c2 100644 --- a/mysys/hash.cc +++ b/mysys/hash.cc @@ -41,6 +41,17 @@ static void movelink(HASH_LINK *array,uint pos,uint next_link,uint newlink); static int hashcmp(const HASH *hash, HASH_LINK *pos, const uchar *key, size_t length); +my_hash_value_type generic_hash_fnv1a(CHARSET_INFO *, const uchar *p, size_t sz) +{ + size_t result= static_cast<size_t>(14695981039346656037ULL); + for (; sz--; ) + { + result ^= static_cast<size_t>(*p++); + result *= static_cast<size_t>(1099511628211ULL); + } + return static_cast<my_hash_value_type>(result); +} + my_hash_value_type my_hash_sort(CHARSET_INFO *cs, const uchar *key, size_t length) { |