mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-03 02:02:24 +00:00
Optimize codes
Force fileGet to use binary mode to prevent some problem. Make cache system serve the existing cache when download failed. Replace some if-statements with switch-statements. Clean up codes.
This commit is contained in:
8 files changed
+223
-180
No files matched your search
@@ -0,0 +1,38 @@
|
||||
#ifndef STRING_HASH_H_INCLUDED
|
||||
#define STRING_HASH_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
|
||||
typedef uint64_t hash_t;
|
||||
|
||||
constexpr hash_t prime = 0x100000001B3ull;
|
||||
constexpr hash_t basis = 0xCBF29CE484222325ull;
|
||||
|
||||
hash_t hash_(char const* str)
|
||||
{
|
||||
hash_t ret{basis};
|
||||
while(*str)
|
||||
{
|
||||
ret ^= *str;
|
||||
ret *= prime;
|
||||
str++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
hash_t hash_(const std::string &str)
|
||||
{
|
||||
return hash_(str.data());
|
||||
}
|
||||
|
||||
constexpr hash_t hash_compile_time(char const* str, hash_t last_value = basis)
|
||||
{
|
||||
return *str ? hash_compile_time(str + 1, (*str ^ last_value) * prime) : last_value;
|
||||
}
|
||||
|
||||
constexpr unsigned long long operator "" _hash(char const* p, size_t)
|
||||
{
|
||||
return hash_compile_time(p);
|
||||
}
|
||||
|
||||
#endif // STRING_HASH_H_INCLUDED
|
||||
Reference in new issue
Block a user