123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include "utils/HashCode.h"
- #include "utils/Utility.h"
- template<typename T>
- static u32 hashNumber(T t) {
- constexpr u32 L = sizeof(T) / 4 + (sizeof(T) % 4 != 0);
- u32 parts[L];
- Core::memorySet(parts, 0, sizeof(parts));
- Core::memoryCopy(parts, &t, sizeof(T));
- u32 hash = 0;
- for(u32 i = 0; i < L; i++) {
- hash ^= parts[i];
- }
- return hash;
- }
- u32 Core::hashCode(char key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(signed char key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(signed short key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(signed int key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(signed long key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(signed long long key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(unsigned char key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(unsigned short key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(unsigned int key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(unsigned long key) {
- return hashNumber(key);
- }
- u32 Core::hashCode(unsigned long long key) {
- return hashNumber(key);
- }
|