11 #include <daw/daw_endian.h>
12 #include <daw/daw_string_view.h>
13 #include <daw/daw_uint_buffer.h>
21 namespace murmur3_details {
22 [[nodiscard]] DAW_ATTRIB_FLATTEN
inline constexpr UInt32
23 murmur3_32_scramble( UInt32 k ) {
25 k = rotate_left<15>( k );
31 template<
typename StringView>
32 [[nodiscard]] DAW_ATTRIB_FLATTEN constexpr UInt32
34 std::size_t
const len = std::size( key );
35 char const *ptr = std::data( key );
36 UInt32 hash = 0x811c'9dc5_u32;
37 for( std::size_t n = 0; n < len; ++n ) {
38 hash ^=
static_cast<unsigned char>( ptr[n] );
39 hash *= 0x0100'0193_u32;
44 template<
typename StringView>
45 [[nodiscard]] constexpr UInt32
name_hash( StringView
const &key,
46 std::uint32_t seed = 0 ) {
48 auto const Sz = std::size( key );
49 if( Sz <=
sizeof( UInt32 ) ) {
51 for( std::size_t n = 0; n < Sz; ++n ) {
53 result |=
static_cast<unsigned char>( key[n] );
60 template<
typename StringView>
61 [[nodiscard]] DAW_ATTRIB_FLATINLINE
inline constexpr UInt32
63 UInt32 h = to_uint32( seed );
65 char const *first = std::data( key );
66 char const *
const last = daw::data_end( key );
67 while( ( last - first ) >= 4 ) {
70 k = daw::to_uint32_buffer( first );
72 h ^= murmur3_details::murmur3_32_scramble( k );
73 h = rotate_left<13>( h );
74 h = h * 5 + 0xe654'6b64_u32;
79 for(
auto i = ( last - first ); i > 0; --i ) {
81 k |=
static_cast<unsigned char>( first[i - 1] );
84 h ^= murmur3_details::murmur3_32_scramble( k );
86 h ^= to_uint32( std::size( key ) );
Definition: daw_from_json.h:22
constexpr DAW_ATTRIB_FLATTEN UInt32 fnv1a_32(StringView &&key)
Definition: daw_murmur3.h:33
constexpr DAW_ATTRIB_FLATINLINE UInt32 murmur3_32(StringView &&key, std::uint32_t seed=0)
Definition: daw_murmur3.h:62
constexpr UInt32 name_hash(StringView const &key, std::uint32_t seed=0)
Definition: daw_murmur3.h:45