Properly named Helpers
This commit is contained in:
19
src/Helpers.cpp
Normal file
19
src/Helpers.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Big thanks to
|
||||
// https://medium.com/@ryan_forrester_/using-switch-statements-with-strings-in-c-a-complete-guide-efa12f64a59d
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
// This is called a polynomial rolling hash, prob going to collide
|
||||
namespace Helpers {
|
||||
constexpr uint64_t Pathhash(std::string_view s) {
|
||||
uint64_t res = 0;
|
||||
for (uint8_t c : s) {
|
||||
res = (res * 131) + c;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace Helpers
|
||||
constexpr uint64_t operator""_hash(const char *string, std::size_t count) {
|
||||
return Helpers::Pathhash(std::string_view(string));
|
||||
}
|
Reference in New Issue
Block a user