diff options
Diffstat (limited to 'libs/math/include/math/TVecHelpers.h')
-rw-r--r-- | libs/math/include/math/TVecHelpers.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libs/math/include/math/TVecHelpers.h b/libs/math/include/math/TVecHelpers.h index 20f852fd9f..0dac662e97 100644 --- a/libs/math/include/math/TVecHelpers.h +++ b/libs/math/include/math/TVecHelpers.h @@ -19,9 +19,11 @@ #include <math.h> #include <stdint.h> +#include <math/HashCombine.h> #include <sys/types.h> #include <cmath> +#include <functional> #include <limits> #include <iostream> @@ -250,6 +252,17 @@ public: } return r; } + + // This isn't strictly a unary operator, but it is a common place shared between both + // matrix and vector classes + size_t hash() const { + VECTOR<T> const& rv(static_cast<VECTOR<T> const&>(*this)); + size_t hashed = 0; + for (size_t i = 0; i < rv.size(); i++) { + android::hashCombineSingle(hashed, rv[i]); + } + return hashed; + } }; /* @@ -606,3 +619,16 @@ public: // ------------------------------------------------------------------------------------- } // namespace details } // namespace android + +namespace std { + template<template<typename T> class VECTOR, typename T> + struct hash<VECTOR<T>> { + static constexpr bool IS_VECTOR = + std::is_base_of<android::details::TVecUnaryOperators<VECTOR, T>, VECTOR<T>>::value; + + typename std::enable_if<IS_VECTOR, size_t>::type + operator()(const VECTOR<T>& v) const { + return v.hash(); + } + }; +} |