47 [[nodiscard]]
static constexpr UInt32
fnv1a_32( StringView key ) {
48 static_assert( daw::traits::is_string_view_like_v<StringView>,
49 "Can only pass contiguous character ranges to fnv1a" );
50 std::size_t len = std::size( key );
51 auto *ptr = std::data( key );
52 auto hash = 0x811c'9dc5_u32;
53 if constexpr( expect_long_strings ) {
54 while( DAW_UNLIKELY( len >= 8 ) ) {
55 hash = fnv1a_32_N<8>( ptr, hash );
60 hash = fnv1a_32_N<4>( ptr, hash );
65 for( std::size_t n = 0; n < len; ++n ) {
66 hash ^=
static_cast<unsigned char>( ptr[n] );
67 hash *= 0x0100'0193_u32;
89 [[nodiscard]]
static constexpr UInt32
murmur3_32( StringView key,
90 std::uint32_t seed = 0 ) {
91 static_assert( daw::traits::is_string_view_like_v<StringView>,
92 "Can only pass contiguous character ranges to fnv1a" );
93 UInt32 h = to_uint32( seed );
95 char const *first = std::data( key );
96 char const *
const last = daw::data_end( key );
97 while( ( last - first ) >= 4 ) {
100 k = daw::to_uint32_buffer( first );
102 h ^= murmur3_details::murmur3_32_scramble( k );
103 h = rotate_left<13>( h );
104 h = h * 5 + 0xe654'6b64_u32;
109 for(
auto i = ( last - first ); i > 0; --i ) {
111 k |=
static_cast<unsigned char>( first[i - 1] );
114 h ^= murmur3_details::murmur3_32_scramble( k );
116 h ^= to_uint32( std::size( key ) );
118 h *= 0x85eb'ca6b_u32;
120 h *= 0xc2b2'ae35_u32;