From f37c3217f307cba41180c37c1ca920aaaa4f793d Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Wed, 3 Nov 2021 14:06:55 +0200 Subject: MDEV-18477: add generic_hash_fnv1a --- include/hash.h | 9 +++++++++ mysys/hash.cc | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/hash.h b/include/hash.h index fd64bf4c5df..4c5b5a186c9 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 d29297a5233..0ea8a802ef0 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(14695981039346656037ULL); + for (; sz--; ) + { + result ^= static_cast(*p++); + result *= static_cast(1099511628211ULL); + } + return static_cast(result); +} + my_hash_value_type my_hash_sort(CHARSET_INFO *cs, const uchar *key, size_t length) { -- cgit v1.2.1