summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2017-02-02 14:17:33 +1100
committer Vas Crabb <vas@vastheman.com>2017-02-02 14:17:40 +1100
commit38a6ab02e4cb86cfbd7e2328c078b6b219030133 (patch)
tree7ae51ad15011afb198f71aa95cd5858ea5af0ee9
parent421e0b233a4dc76323f94abf7259ccef8875b0b3 (diff)
yo sup dawg (nw)
-rw-r--r--src/lib/util/hashing.h54
1 files 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 <string>
#include "md5.h"
#include "sha1.h"
+#include <functional>
+#include <string>
+
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<std::uint32_t>()(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<std::uint16_t>()(s); }
+};
+
+} // namespace std
+
#endif // __HASHING_H__