From 38a6ab02e4cb86cfbd7e2328c078b6b219030133 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 2 Feb 2017 14:17:33 +1100 Subject: [PATCH] yo sup dawg (nw) --- src/lib/util/hashing.h | 54 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/src/lib/util/hashing.h b/src/lib/util/hashing.h index 906bad047b4..5e9c9134c97 100644 --- a/src/lib/util/hashing.h +++ b/src/lib/util/hashing.h @@ -15,10 +15,12 @@ #include "osdcore.h" #include "corestr.h" -#include #include "md5.h" #include "sha1.h" +#include +#include + namespace util { //************************************************************************** @@ -132,13 +134,23 @@ protected: // final digest struct crc32_t { - bool operator==(const crc32_t &rhs) const { return m_raw == rhs.m_raw; } - bool operator!=(const crc32_t &rhs) const { return m_raw != rhs.m_raw; } + crc32_t() { } + constexpr crc32_t(const crc32_t &rhs) = default; + constexpr crc32_t(const uint32_t crc) : m_raw(crc) { } + + constexpr bool operator==(const crc32_t &rhs) const { return m_raw == rhs.m_raw; } + constexpr bool operator!=(const crc32_t &rhs) const { return m_raw != rhs.m_raw; } + + crc32_t &operator=(const crc32_t &rhs) = default; crc32_t &operator=(const uint32_t crc) { m_raw = crc; return *this; } - operator uint32_t() const { return m_raw; } + + constexpr operator uint32_t() const { return m_raw; } + bool from_string(const char *string, int length = -1); std::string as_string() const; + uint32_t m_raw; + static const crc32_t null; }; @@ -178,13 +190,23 @@ protected: // final digest struct crc16_t { - bool operator==(const crc16_t &rhs) const { return m_raw == rhs.m_raw; } - bool operator!=(const crc16_t &rhs) const { return m_raw != rhs.m_raw; } + crc16_t() { } + constexpr crc16_t(const crc16_t &rhs) = default; + constexpr crc16_t(const uint16_t crc) : m_raw(crc) { } + + constexpr bool operator==(const crc16_t &rhs) const { return m_raw == rhs.m_raw; } + constexpr bool operator!=(const crc16_t &rhs) const { return m_raw != rhs.m_raw; } + + crc16_t &operator=(const crc16_t &rhs) = default; crc16_t &operator=(const uint16_t crc) { m_raw = crc; return *this; } - operator uint16_t() const { return m_raw; } + + constexpr operator uint16_t() const { return m_raw; } + bool from_string(const char *string, int length = -1); std::string as_string() const; + uint16_t m_raw; + static const crc16_t null; }; @@ -220,4 +242,22 @@ protected: } // namespace util +namespace std { + +template <> struct hash<::util::crc32_t> +{ + typedef ::util::crc32_t argument_type; + typedef std::size_t result_type; + result_type operator()(argument_type const & s) const { return std::hash()(s); } +}; + +template <> struct hash<::util::crc16_t> +{ + typedef ::util::crc16_t argument_type; + typedef std::size_t result_type; + result_type operator()(argument_type const & s) const { return std::hash()(s); } +}; + +} // namespace std + #endif // __HASHING_H__