improve JoyMap hashing

This commit is contained in:
Thomas Jentzsch 2019-08-15 14:52:43 +02:00
parent 22b4f36bbc
commit e3c97c3725
2 changed files with 16 additions and 13 deletions

View File

@ -130,12 +130,13 @@ class JoyMap
struct JoyHash {
size_t operator()(const JoyMapping& m)const {
return std::hash<uInt64>()((uInt64(m.mode)) // 3 bit
^ ((uInt64(m.button)) << 2) // 2 bits
^ ((uInt64(m.axis)) << 4) // 1 bit
^ ((uInt64(m.adir)) << 5) // 1 bit
^ ((uInt64(m.hat)) << 6) // 1 bit
^ ((uInt64(m.hdir)) << 7) // 2 bits
return std::hash<uInt64>()((uInt64(m.mode)) // 3 bits
+ ((uInt64(m.button)) * 7) // 3 bits
+ (((uInt64(m.axis)) << 0) // 2 bits
| ((uInt64(m.adir)) << 2) // 2 bits
| ((uInt64(m.hat )) << 4) // 1 bit
| ((uInt64(m.hdir)) << 5) // 2 bits
) * 61
);
}
};

View File

@ -109,7 +109,9 @@ class KeyMap
+ (((uInt64((m.mod & KBDM_SHIFT) != 0) << 0)) // 1 bit
| ((uInt64((m.mod & KBDM_ALT ) != 0) << 1)) // 1 bit
| ((uInt64((m.mod & KBDM_GUI ) != 0) << 2)) // 1 bit
| ((uInt64((m.mod & KBDM_CTRL ) != 0) << 3))) * 2047); // 1 bit
| ((uInt64((m.mod & KBDM_CTRL ) != 0) << 3)) // 1 bit
) * 2047
);
}
};