//===-- Portable string hash function ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_LIBC_SRC___SUPPORT_HASH_H #define LLVM_LIBC_SRC___SUPPORT_HASH_H #include "src/__support/CPP/bit.h" // rotl #include "src/__support/CPP/limits.h" // numeric_limits #include "src/__support/macros/attributes.h" // LIBC_INLINE #include "src/__support/macros/config.h" #include "src/__support/uint128.h" // UInt128 #include <stdint.h> // For uint64_t namespace LIBC_NAMESPACE_DECL { namespace internal { // Folded multiplication. // This function multiplies two 64-bit integers and xor the high and // low 64-bit parts of the result. LIBC_INLINE uint64_t folded_multiply(uint64_t x, uint64_t y) { … } // Read as little endian. // Shift-and-or implementation does not give a satisfactory code on aarch64. // Therefore, we use a union to read the value. template <typename T> LIBC_INLINE T read_little_endian(const void *ptr) { … } // Specialized read functions for small values. size must be <= 8. LIBC_INLINE void read_small_values(const void *ptr, size_t size, uint64_t &low, uint64_t &high) { … } // This constant comes from Kunth's prng (it empirically works well). LIBC_INLINE_VAR constexpr uint64_t MULTIPLE = …; // Rotation amount for mixing. LIBC_INLINE_VAR constexpr uint64_t ROTATE = …; // Randomly generated values. For now, we use the same values as in aHash as // they are widely tested. // https://github.com/tkaitchuck/aHash/blob/9f6a2ad8b721fd28da8dc1d0b7996677b374357c/src/random_state.rs#L38 LIBC_INLINE_VAR constexpr uint64_t RANDOMNESS[2][4] = …; // This is a portable string hasher. It is not cryptographically secure. // The quality of the hash is good enough to pass all tests in SMHasher. // The implementation is derived from the generic routine of aHash. class HashState { … }; } // namespace internal } // namespace LIBC_NAMESPACE_DECL #endif // LLVM_LIBC_SRC___SUPPORT_HASH_H