11 #include <daw/daw_endian.h>
12 #include <daw/daw_string_view.h>
13 #include <daw/daw_uint_buffer.h>
20 namespace murmur3_details {
21 [[nodiscard]]
inline constexpr UInt32 murmur3_32_scramble( UInt32 k ) {
23 k = rotate_left<15>( k );
29 template<
typename StringView>
30 [[nodiscard]] DAW_ATTRIBUTE_FLATTEN
inline constexpr UInt32
32 std::size_t
const len = std::size( key );
33 char const *ptr = std::data( key );
34 UInt32 hash = 0x811c
'9dc5_u32;
35 for( std::size_t n = 0; n < len; ++n ) {
36 hash ^= static_cast<unsigned char>( ptr[n] );
37 hash *= 0x0100'0193_u32;
42 template<
typename StringView>
43 [[nodiscard]] constexpr UInt32
name_hash( StringView key,
44 std::uint32_t seed = 0 ) {
46 auto const Sz = std::size( key );
47 if( Sz <=
sizeof( UInt32 ) ) {
49 for( std::size_t n = 0; n < Sz; ++n ) {
51 result |=
static_cast<unsigned char>( key[n] );
58 template<
typename StringView>
59 [[nodiscard]] DAW_ATTRIBUTE_FLATTEN
inline constexpr UInt32
61 UInt32 h = to_uint32( seed );
63 char const *first = std::data( key );
64 char const *
const last = std::data( key ) + std::size( key );
65 while( ( last - first ) >= 4 ) {
68 k = daw::to_uint32_buffer( first );
70 h ^= murmur3_details::murmur3_32_scramble( k );
71 h = rotate_left<13>( h );
72 h = h * 5 + 0xe654
'6b64_u32;
77 for( auto i = ( last - first ); i > 0; --i ) {
79 k |= static_cast<unsigned char>( first[i - 1] );
82 h ^= murmur3_details::murmur3_32_scramble( k );
84 h ^= to_uint32( std::size( key ) );