Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while (sscanf(remainder, "%s", buf) == 1) {
- string flag = buf;
- switch (cleanHash(flag.c_str(), flag.length())) {
- case str_case(flag, "OnCeil") {
- ...
- break;
- }
- case str_case(flag, "OnFaces") {
- ...
- break;
- }
- case str_case(flag, "OnFloor") {
- ...
- break;
- }
- case str_case(flag, "OnSurf") {
- ...
- break;
- }
- case str_case(flag, "OnTorch") {
- ...
- break;
- }
- case str_case(flag, "OnWall") {
- ...
- break;
- }
- }
- // The magic
- constexpr int filthyHash(const char *x, int y, int z, int res) {
- return z < y
- ? filthyHash(x, y, z + 1, (int)((long)res * 31 + x[z]))
- : res;
- }
- constexpr int cleanHash(const char* x, int y) {
- return filthyHash(x, y, 0, 0) << 4 | (y & ((1 << 4) - 1));
- }
- template<size_t N> constexpr int dirtyHash(const char (&x)[N]) {
- return cleanHash(x, N);
- }
- #define str_case(key, x) dirtyHash(x): if ((key) == (x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement