diff options
| author | void_17 <heroerror3@gmail.com> | 2026-03-02 14:51:05 +0700 |
|---|---|---|
| committer | void_17 <heroerror3@gmail.com> | 2026-03-02 14:51:05 +0700 |
| commit | def238ff08dd90a06e0916876601f9a03f22c510 (patch) | |
| tree | 54c2755099646b8bcc6480a3f4774fe0550b47c5 /Minecraft.World/JavaIntHash.h | |
| parent | dea1d620744b6d6eb8441f91e905facbee277156 (diff) | |
Fix C-style struct functor definitions
Diffstat (limited to 'Minecraft.World/JavaIntHash.h')
| -rw-r--r-- | Minecraft.World/JavaIntHash.h | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/Minecraft.World/JavaIntHash.h b/Minecraft.World/JavaIntHash.h index 447b8052..fe608469 100644 --- a/Minecraft.World/JavaIntHash.h +++ b/Minecraft.World/JavaIntHash.h @@ -1,13 +1,15 @@ #pragma once +#include <cstdint> + // Java doesn't have a default hash value for ints, however, the hashmap itself does some "supplemental" hashing, so // our ints actually get hashed by code as implemented below. std templates *do* have a standard hash for ints, but it // would appear to be a bit expensive so matching the java one for now anyway. This code implements the supplemental // hashing that happens in java so we can match what their maps are doing with ints. -typedef struct +struct IntKeyHash { - int operator() (const int &k) const + inline int operator()(const int &k) const { int h = k; h += ~(h << 9); @@ -16,62 +18,64 @@ typedef struct h ^= (((unsigned int)h) >> 10); return h; } +}; -} IntKeyHash; - -typedef struct +struct IntKeyEq { - bool operator() (const int &x, const int &y) const { return x==y; } -} IntKeyEq; - + inline bool operator()(const int &x, const int &y) const + { return x==y; } +}; // This hash functor is taken from the IntHashMap java class used by the game, so that we can use a standard std hashmap with this hash rather // than implement the class itself -typedef struct +struct IntKeyHash2 { - int operator() (const int &k) const + inline int operator()(const int &k) const { - unsigned int h = (unsigned int)k; + unsigned int h = static_cast<unsigned int>(k); h ^= (h >> 20) ^ (h >> 12); - return (int)(h ^ (h >> 7) ^ (h >> 4)); + return static_cast<int>(h ^ (h >> 7) ^ (h >> 4)); } -} IntKeyHash2; +}; // This hash functor is taken from the LongHashMap java class used by the game, so that we can use a standard std hashmap with this hash rather // than implement the class itself -typedef struct +struct LongKeyHash { - int hash(const int &k) const + inline int hash(const int &k) const { - unsigned int h = (unsigned int)k; + unsigned int h = static_cast<unsigned int>(k); h ^= (h >> 20) ^ (h >> 12); - return (int)(h ^ (h >> 7) ^ (h >> 4)); + return static_cast<int>(h ^ (h >> 7) ^ (h >> 4)); } - int operator() (const __int64 &k) const + inline int operator()(const int64_t &k) const { - return hash((int) ( k ^ (((__uint64)k) >> 32 ))); + return hash(static_cast<int>(k ^ ((static_cast<uint64_t>(k)) >> 32))); } -} LongKeyHash; +}; -typedef struct +struct LongKeyEq { - bool operator() (const __int64 &x, const __int64 &y) const { return x==y; } -} LongKeyEq; + inline bool operator() (const int64_t &x, const int64_t &y) const + { return x == y; } +}; -typedef struct +enum eINSTANCEOF; +struct eINSTANCEOFKeyHash { - int operator() (const eINSTANCEOF &k) const + int operator()(const eINSTANCEOF &k) const { - unsigned int h = (unsigned int)k; + unsigned int h = static_cast<unsigned int>(k); h ^= (h >> 20) ^ (h >> 12); - return (int)(h ^ (h >> 7) ^ (h >> 4)); + return static_cast<int>(h ^ (h >> 7) ^ (h >> 4)); } -} eINSTANCEOFKeyHash; +}; -typedef struct +struct eINSTANCEOFKeyEq { - bool operator() (const eINSTANCEOF &x, const eINSTANCEOF &y) const { return x==y; } -} eINSTANCEOFKeyEq; + inline bool operator()(const eINSTANCEOF &x, const eINSTANCEOF &y) const + { return x == y; } +}; |
