From b03411e30a72abae1892b9bb6abeef97fe2dac42 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 22 Nov 2012 08:31:18 +0000 Subject: [PATCH] core: make hash operators const. --- src/core/hash.cpp | 26 +++++++++++++------------- src/lol/core/hash.h | 30 +++++++++++++++--------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/core/hash.cpp b/src/core/hash.cpp index da382c1a..1d61a7ac 100644 --- a/src/core/hash.cpp +++ b/src/core/hash.cpp @@ -87,42 +87,42 @@ static inline uint32_t Hash64(uint64_t x) * Integer hash functions */ -uint32_t Hash::operator ()(int8_t x) +uint32_t Hash::operator ()(int8_t x) const { return Hash8((uint8_t)x); } -uint32_t Hash::operator ()(uint8_t x) +uint32_t Hash::operator ()(uint8_t x) const { return Hash8(x); } -uint32_t Hash::operator ()(int16_t x) +uint32_t Hash::operator ()(int16_t x) const { return Hash16((uint16_t)x); } -uint32_t Hash::operator ()(uint16_t x) +uint32_t Hash::operator ()(uint16_t x) const { return Hash16(x); } -uint32_t Hash::operator ()(int32_t x) +uint32_t Hash::operator ()(int32_t x) const { return Hash32((uint32_t)x); } -uint32_t Hash::operator ()(uint32_t x) +uint32_t Hash::operator ()(uint32_t x) const { return Hash32(x); } -uint32_t Hash::operator ()(int64_t x) +uint32_t Hash::operator ()(int64_t x) const { return Hash64((uint64_t)x); } -uint32_t Hash::operator ()(uint64_t x) +uint32_t Hash::operator ()(uint64_t x) const { return Hash64(x); } @@ -131,18 +131,18 @@ uint32_t Hash::operator ()(uint64_t x) * Floating-point hash functions */ -uint32_t Hash::operator ()(half f) +uint32_t Hash::operator ()(half f) const { return Hash16(f.bits); } -uint32_t Hash::operator ()(float f) +uint32_t Hash::operator ()(float f) const { union { float tmp; uint32_t x; } u = { f }; return Hash32(u.x); } -uint32_t Hash::operator ()(double f) +uint32_t Hash::operator ()(double f) const { union { double tmp; uint64_t x; } u = { f }; return Hash64(u.x); @@ -162,12 +162,12 @@ static uint32_t HashCharString(char const *s) return ret ^ 0xffffffffu; } -uint32_t Hash::operator ()(char const *s) +uint32_t Hash::operator ()(char const *s) const { return HashCharString(s); } -uint32_t Hash::operator ()(String const &s) +uint32_t Hash::operator ()(String const &s) const { return HashCharString(&s[0]); } diff --git a/src/lol/core/hash.h b/src/lol/core/hash.h index f25ea3a2..ced96467 100644 --- a/src/lol/core/hash.h +++ b/src/lol/core/hash.h @@ -22,30 +22,30 @@ namespace lol template class Hash; -template<> class Hash { public: uint32_t operator()(int8_t); }; -template<> class Hash { public: uint32_t operator()(uint8_t); }; -template<> class Hash { public: uint32_t operator()(int16_t); }; -template<> class Hash { public: uint32_t operator()(uint16_t); }; -template<> class Hash { public: uint32_t operator()(int32_t); }; -template<> class Hash { public: uint32_t operator()(uint32_t); }; -template<> class Hash { public: uint32_t operator()(int64_t); }; -template<> class Hash { public: uint32_t operator()(uint64_t); }; - -template<> class Hash { public: uint32_t operator()(half); }; -template<> class Hash { public: uint32_t operator()(float); }; -template<> class Hash { public: uint32_t operator()(double); }; -template<> class Hash { public: uint32_t operator()(ldouble); }; +template<> class Hash { public: uint32_t operator()(int8_t) const; }; +template<> class Hash { public: uint32_t operator()(uint8_t) const; }; +template<> class Hash { public: uint32_t operator()(int16_t) const; }; +template<> class Hash { public: uint32_t operator()(uint16_t) const; }; +template<> class Hash { public: uint32_t operator()(int32_t) const; }; +template<> class Hash { public: uint32_t operator()(uint32_t) const; }; +template<> class Hash { public: uint32_t operator()(int64_t) const; }; +template<> class Hash { public: uint32_t operator()(uint64_t) const; }; + +template<> class Hash { public: uint32_t operator()(half) const; }; +template<> class Hash { public: uint32_t operator()(float) const; }; +template<> class Hash { public: uint32_t operator()(double) const; }; +template<> class Hash { public: uint32_t operator()(ldouble) const; }; template<> class Hash { public: - uint32_t operator()(char const *x); + uint32_t operator()(char const *x) const; }; template<> class Hash { public: - uint32_t operator()(String const &s); + uint32_t operator()(String const &s) const; }; } /* namespace lol */