MDEV-35247: ut_fold_ull() is a waste

ut_fold_ull(): For SIZEOF_SIZE_T < 8, we simulate universal hashing
(Carter and Wegman, 1977) by pretending that SIZE_T_MAX + 1
is a prime. In other words, we implement a Rabin–Karp rolling
hash algorithm similar to java.lang.String.hashCode().
This is used for representing 64-bit dict_index_t::id or
dict_table_t::id in the native word size.

For SIZEOF_SIZE_T >= 8, we just use an identity mapping.

Reviewed by: Debarun Banerjee
This commit is contained in:
Marko Mäkelä 2024-11-21 08:59:17 +02:00
parent 3c312d247c
commit a9b0a1c5d0
2 changed files with 8 additions and 22 deletions

View file

@ -81,15 +81,14 @@ ut_hash_ulint(
/*==========*/
ulint key, /*!< in: value to be hashed */
ulint table_size); /*!< in: hash table size */
/*************************************************************//**
Folds a 64-bit integer.
@return folded value */
UNIV_INLINE
ulint
ut_fold_ull(
/*========*/
ib_uint64_t d) /*!< in: 64-bit integer */
MY_ATTRIBUTE((const));
# if SIZEOF_SIZE_T < 8
inline size_t ut_fold_ull(uint64_t d) noexcept
{
return size_t(d) * 31 + size_t(d >> (SIZEOF_SIZE_T * CHAR_BIT));
}
# else
# define ut_fold_ull(d) d
# endif
/***********************************************************//**
Looks for a prime number slightly greater than the given argument.
The prime is chosen so that it is not near any power of 2.

View file

@ -46,19 +46,6 @@ ut_hash_ulint(
return(key % table_size);
}
/*************************************************************//**
Folds a 64-bit integer.
@return folded value */
UNIV_INLINE
ulint
ut_fold_ull(
/*========*/
ib_uint64_t d) /*!< in: 64-bit integer */
{
return(ut_fold_ulint_pair((ulint) d & ULINT32_MASK,
(ulint) (d >> 32)));
}
#endif /* !UNIV_INNOCHECKSUM */
/*************************************************************//**