Source
xxxxxxxxxx
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
typedef unsigned char uchar;
/*
* modified FNV hash function (see http://www.isthe.com/chongo/tech/comp/fnv/)
*/
zbx_hash_t zbx_hash_modfnv(const void *data, size_t len, zbx_hash_t seed)
{
const uchar *p = (const uchar *)data;
zbx_hash_t hash;
hash = 2166136261u ^ seed;
while (len-- >= 1)
{
hash = (hash ^ *(p++)) * 16777619u;
}
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
}
/*
* see http://xoshiro.di.unimi.it/splitmix64.c
*/
zbx_hash_t zbx_hash_splittable64(const void *data)
{
zbx_uint64_t value = *(const zbx_uint64_t *)data;
value ^= value >> 30;
value *= __UINT64_C(0xbf58476d1ce4e5b9);
value ^= value >> 27;
value *= __UINT64_C(0x94d049bb133111eb);
value ^= value >> 31;
return (zbx_hash_t)value ^ (value >> 32);
}
/* default hash functions */
zbx_hash_t zbx_default_ptr_hash_func(const void *data)
{
return ZBX_DEFAULT_PTR_HASH_ALGO(data, ZBX_PTR_SIZE, ZBX_DEFAULT_HASH_SEED);
}
zbx_hash_t zbx_default_string_hash_func(const void *data)
{
return ZBX_DEFAULT_STRING_HASH_ALGO(data, strlen((const char *)data), ZBX_DEFAULT_HASH_SEED);
}
zbx_hash_t zbx_default_string_ptr_hash_func(const void *data)
{
return zbx_default_string_hash_func(*((const char * const *)data));
}
zbx_hash_t zbx_default_uint64_pair_hash_func(const void *data)
{
const zbx_uint64_pair_t *pair = (const zbx_uint64_pair_t *)data;
zbx_hash_t hash;
hash = ZBX_DEFAULT_UINT64_HASH_FUNC(&pair->first);
hash = ZBX_DEFAULT_UINT64_HASH_ALGO(&pair->second, sizeof(pair->second), hash);
return hash;
}
/* default comparison functions */