Struct StringViewHasher< 4 >

Synopsis

#include <lib/inc/drogon/utils/string_view.h>

template <>
struct StringViewHasher<4>

Description

No description yet.

Methods

operator()

Source

Lines 50-94 in lib/inc/drogon/utils/string_view.h.

template <>
struct StringViewHasher<4>
{
    size_t operator()(const drogon::string_view &__str) const noexcept
    {
        // Take from the memory header file
        //===-------------------------- memory
        //------------------------------------===//
        //
        //                     The LLVM Compiler Infrastructure
        //
        // This file is dual licensed under the MIT and the University of
        // Illinois Open Source Licenses. See LICENSE.TXT for details.
        //
        //===----------------------------------------------------------------------===//
        const uint32_t __m = 0x5bd1e995;
        const uint32_t __r = 24;
        uint32_t __h = __str.length();
        auto __len = __h;
        const unsigned char *__data = (const unsigned char *)(__str.data());
        for (; __len >= 4; __data += 4, __len -= 4)
        {
            uint32_t __k = *((uint32_t *)__data);
            __k *= __m;
            __k ^= __k >> __r;
            __k *= __m;
            __h *= __m;
            __h ^= __k;
        }
        switch (__len)
        {
            case 3:
                __h ^= __data[2] << 16;
            case 2:
                __h ^= __data[1] << 8;
            case 1:
                __h ^= __data[0];
                __h *= __m;
        }
        __h ^= __h >> 13;
        __h *= __m;
        __h ^= __h >> 15;
        return __h;
    }
};





Add Discussion as Guest

Log in