88 #define __ADS_FastHash
110#include <string_view>
111#include <type_traits>
135[[nodiscard]] [[gnu::always_inline]]
constexpr Product128
147hashWord( std::uint64_t x , std::uint64_t seed = 0 );
180hashBytes(
const void * p , std::size_t n , std::uint64_t seed = 0 );
197 requires( std::is_integral_v< T > || std::is_enum_v< T > ||
198 std::is_pointer_v< T > ||
199 ( std::is_floating_point_v< T > && (
sizeof( T ) <= 8 ) ) )
202 using is_avalanching = void;
204 std::uint64_t seed = 0;
209 void persist( A & a ) {
215 [[nodiscard]] std::uint64_t hash64( T x )
const noexcept {
216 if constexpr( std::is_pointer_v< T > )
217 return(
hashWord( std::uint64_t(
reinterpret_cast< std::uintptr_t
>( x ) ) ,
219 else if constexpr( std::is_enum_v< T > )
221 hashWord( std::uint64_t( std::underlying_type_t< T >( x ) ) , seed ) );
222 else if constexpr( std::is_floating_point_v< T > ) {
226 std::memcpy( &w , &x ,
sizeof( T ) );
230 return(
hashWord( std::uint64_t( x ) , seed ) );
235 [[nodiscard]] std::size_t operator()( T x )
const noexcept {
236 return( std::size_t( hash64( x ) ) );
259 [[nodiscard]] std::uint64_t
hash64( std::string_view s )
const noexcept {
264 [[nodiscard]] std::size_t
operator()( std::string_view s )
const noexcept {
265 return( std::size_t(
hash64( s ) ) );
289 using type = std::hash< K >;
293 requires requires {
sizeof( FastHash< K > ); }
294struct DefaultHashOf< K >
296 using type = FastHash< K >;
302template<
class H ,
class K >
303inline constexpr bool kHash64 =
requires(
const H & h ,
const K & k )
305 { h.hash64( k ) } -> std::same_as< std::uint64_t >;
310template<
class H ,
class K >
314 if constexpr( kHash64< H , K > )
315 return( h.hash64( k ) );
317 return( std::uint64_t( h( k ) ) );
324template<
class H ,
class K >
325inline constexpr bool kAvalanching64 =
326 requires {
typename H::is_avalanching; } &&
327 ( kHash64< H , K > || (
sizeof(
decltype( std::declval< const H & >()(
328 std::declval< const K & >() ) ) ) >= 8 ) );
333inline constexpr bool kIndirectKey =
requires(
const K & k )
335 { k.data() } -> std::convertible_to< const void * >;
342inline void prefetchKey(
const K & k )
344 if constexpr( kIndirectKey< K > )
345 ADS::detail::prefetchLine(
static_cast< const void *
>( k.data() ) );
371#include "ADS/dictionary/impl/FastHash.tpp"
The name of the configuration of the layouts, an inline namespace: the headers whose classes change t...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring ...
The vector kernels of ADS on Google Highway, with ADS_WITH_HIGHWAY: the loops over arrays that a stru...
The arithmetic of two words that C++20 does not spell, in one form for every compiler: the product of...
#define ADS_ABI_BEGIN
opens the inline namespace of the configuration
Definition Abi.h:106
#define ADS_ABI_END
closes the inline namespace of the configuration
Definition Abi.h:111
#define ADS_ALWAYS_INLINE
a function inlined even where the compiler would not
Definition Portable.h:90
typename detail::DefaultHashOf< K >::type DefaultHash
the hash of the engineered tables and filters of ADS: FastHash< K > for the integers,...
Definition FastHash.h:359
constexpr Product128 product128(std::uint64_t a, std::uint64_t b)
the product on 128 bits
constexpr std::uint64_t hashWord(std::uint64_t x, std::uint64_t seed=0)
the hash of the word under the seed, the folded product of and of the seed XOR a constant
std::uint64_t hashBytes(const void *p, std::size_t n, std::uint64_t seed=0)
the hash of the bytes from under the seed
constexpr std::uint64_t foldedProduct(std::uint64_t a, std::uint64_t b)
the folded product: the low half of on 128 bits XOR its high half,
the hash of a string, by its bytes; any std::string_view, std::string and C string with the same char...
Definition FastHash.h:246
void is_avalanching
the hash needs no further mixing
Definition FastHash.h:247
void persist(A &a)
the seed written to, or read from, the archive [see Persistence.h]
Definition FastHash.h:254
std::size_t operator()(std::string_view s) const noexcept
the low bits of hash64() that a std::size_t holds
Definition FastHash.h:264
std::uint64_t hash64(std::string_view s) const noexcept
hashBytes() of the characters of , on 64 bits
Definition FastHash.h:259
std::uint64_t seed
the seed of hashBytes()
Definition FastHash.h:249
void is_transparent
for the lookups by any string
Definition FastHash.h:248
the hash of the values of T, for the integers, the enumerations, the pointers, the floating point num...
Definition FastHash.h:190
the product on 128 bits, its low and its high half
Definition FastHash.h:129
std::uint64_t lo
the low half,
Definition FastHash.h:130
std::uint64_t hi
the high half,
Definition FastHash.h:131