13 template<
class value_t>
14 constexpr
size_t djb2a_hash(
const value_t* pszStr,
size_t nSeed,
size_t nLen)
18 for (
size_t i = 0; i < nLen; ++i)
19 nHash = nHash * 33 ^ pszStr[i];
24 template<
class value_t>
25 constexpr
size_t djb2a_hash(
const value_t* pszStr,
size_t nSeed)
29 for (
size_t i = 0; pszStr[i]; ++i)
30 nHash = nHash * 33 ^ pszStr[i];
35 template<
class value_t>
36 constexpr
size_t murmur_32_hash(
const value_t* pStr,
size_t nSeed,
size_t nLen) noexcept
49 sizeof(value_t) ==
sizeof(
u8) ||
sizeof(value_t) ==
sizeof(
u16) ||
sizeof(value_t) ==
sizeof(
u32));
51 if constexpr (
sizeof(value_t) ==
sizeof(
u32))
55 else if constexpr (
sizeof(value_t) ==
sizeof(
u16))
75 k = (k << 15) | (k >> 17);
79 nHash = (nHash << 13) | (nHash >> 19);
80 nHash = nHash * 5 + 0xe6546b64;
94 k = (k << 15) | (k >> 17);
100 nHash ^= nHash >> 16;
102 nHash ^= nHash >> 13;
104 nHash ^= nHash >> 16;
109 template<
class fwd_it_1_t,
class fwd_it_2_t>
110 constexpr
int iter_strcmp(fwd_it_1_t itBegin1, fwd_it_1_t itEnd1, fwd_it_2_t itBegin2, fwd_it_2_t itEnd2) noexcept
115 while (it1 != itEnd1 && it2 != itEnd2 && *it1 == *it2)
121 if (it1 == itEnd1 && it2 == itEnd2)
125 return -
static_cast<int>(*it2);
128 return static_cast<int>(*it1);
130 return static_cast<int>(*it1) -
static_cast<int>(*it2);
133 template<
class value_t>
134 constexpr
int strcmp(
const value_t* pszLeft,
const value_t* pszRight)
136 while (*pszLeft && (*pszLeft == *pszRight))
141 return *pszLeft - *pszRight;
147 template<
class value_t,
size_t N>
148 constexpr
const auto& choose_str_prefix(
const char (&c)[N],
const wchar_t (&w)[N]) noexcept
150 if constexpr (std::is_same_v<value_t, char>)
157 constexpr
char choose_char_prefix<char>(
char c,
wchar_t) noexcept
163 constexpr
wchar_t choose_char_prefix<wchar_t>(
char,
wchar_t w) noexcept
170 template<
class value_t,
class T>
173 const value_t* pszFormat =
nullptr;
175 using test_type = std::remove_cvref_t<T>;
177 if constexpr (std::is_same_v<test_type, char>)
181 else if constexpr (std::is_same_v<test_type, unsigned char>)
185 else if constexpr (std::is_same_v<test_type, short>)
189 else if constexpr (std::is_same_v<test_type, unsigned short>)
193 else if constexpr (std::is_same_v<test_type, int>)
197 else if constexpr (std::is_same_v<test_type, unsigned int>)
201 else if constexpr (std::is_same_v<test_type, long>)
205 else if constexpr (std::is_same_v<test_type, unsigned long>)
209 else if constexpr (std::is_same_v<test_type, long long>)
213 else if constexpr (std::is_same_v<test_type, unsigned long long>)
217 else if constexpr (std::is_same_v<test_type, float>)
221 else if constexpr (std::is_same_v<test_type, double>)
225 else if constexpr (std::is_same_v<test_type, long double>)
229 else if constexpr (std::is_same_v<std::remove_cv_t<std::remove_pointer_t<test_type>>,
char>)
233 else if constexpr (std::is_same_v<std::remove_cv_t<std::remove_pointer_t<test_type>>,
wchar_t>)
237 else if constexpr (std::is_pointer_v<test_type>)
249 template<
class value_t>
250 constexpr std::size_t
strlen(
const value_t* psz)
255 std::size_t nLen = 0;
constexpr size_t djb2a_hash(const value_t *pszStr, size_t nSeed, size_t nLen)
djb2a hash
#define QX_CHAR_PREFIX(value_t, ch)
Chose witch of prefixes add to char : L or none.
constexpr int iter_strcmp(fwd_it_1_t itBegin1, fwd_it_1_t itEnd1, fwd_it_2_t itBegin2, fwd_it_2_t itEnd2) noexcept
Compares string 1 with string 2.
constexpr size_t murmur_32_hash(const value_t *pStr, size_t nSeed, size_t nLen) noexcept
Murmur nHash.
constexpr int strcmp(const value_t *pszLeft, const value_t *pszRight)
Constexpr compare two strings.
constexpr std::size_t strlen(const value_t *psz)
Naive but constexpr string length algorithm, for runtime prefer std::strlen as there are may be a lot...
#define QX_STR_PREFIX(value_t, str)
Chose witch of prefixes add to string : L or none.
constexpr const value_t * get_format_specifier() noexcept
Get format specifier for type.
std::uint8_t u8
0 .. 65 535
std::uint32_t u32
0 .. 18 446 744 073 709 551 615
std::uint16_t u16
0 .. 4 294 967 295