Template
1
0

Properly named Helpers

This commit is contained in:
2025-06-25 23:25:39 +03:00
parent 8fed5d3808
commit c023c5f5ed

19
src/Helpers.cpp Normal file
View 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));
}