Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-03-25 18:01:28 +0300
committerJacques Lucke <jacques@blender.org>2021-03-25 18:01:41 +0300
commit1d7adb6d8a3ee9126b9361f652da89f014bef423 (patch)
treef9ff96750df6eec018406506576bd90b9edc3beb /source/blender/blenlib
parent9b426269189ce00add24e48c951c45aca01f2076 (diff)
BLI: simplify using DefaultHash
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_hash.hh27
-rw-r--r--source/blender/blenlib/BLI_user_counter.hh2
-rw-r--r--source/blender/blenlib/intern/math_vec.cc2
-rw-r--r--source/blender/blenlib/intern/mesh_boolean.cc5
4 files changed, 26 insertions, 10 deletions
diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh
index 39695b110b1..4022c2baa1f 100644
--- a/source/blender/blenlib/BLI_hash.hh
+++ b/source/blender/blenlib/BLI_hash.hh
@@ -206,19 +206,38 @@ template<typename T> struct DefaultHash<T *> {
}
};
+template<typename T> uint64_t get_default_hash(const T &v)
+{
+ return DefaultHash<T>{}(v);
+}
+
+template<typename T1, typename T2> uint64_t get_default_hash_2(const T1 &v1, const T2 &v2)
+{
+ const uint64_t h1 = get_default_hash(v1);
+ const uint64_t h2 = get_default_hash(v2);
+ return h1 ^ (h2 * 19349669);
+}
+
+template<typename T1, typename T2, typename T3>
+uint64_t get_default_hash_3(const T1 &v1, const T2 &v2, const T3 &v3)
+{
+ const uint64_t h1 = get_default_hash(v1);
+ const uint64_t h2 = get_default_hash(v2);
+ const uint64_t h3 = get_default_hash(v3);
+ return h1 ^ (h2 * 19349669) ^ (h3 * 83492791);
+}
+
template<typename T> struct DefaultHash<std::unique_ptr<T>> {
uint64_t operator()(const std::unique_ptr<T> &value) const
{
- return DefaultHash<T *>{}(value.get());
+ return get_default_hash(value.get());
}
};
template<typename T1, typename T2> struct DefaultHash<std::pair<T1, T2>> {
uint64_t operator()(const std::pair<T1, T2> &value) const
{
- uint64_t hash1 = DefaultHash<T1>{}(value.first);
- uint64_t hash2 = DefaultHash<T2>{}(value.second);
- return hash1 ^ (hash2 * 33);
+ return get_default_hash_2(value.first, value.second);
}
};
diff --git a/source/blender/blenlib/BLI_user_counter.hh b/source/blender/blenlib/BLI_user_counter.hh
index ef276814981..3e6d5af4c3f 100644
--- a/source/blender/blenlib/BLI_user_counter.hh
+++ b/source/blender/blenlib/BLI_user_counter.hh
@@ -125,7 +125,7 @@ template<typename T> class UserCounter {
uint64_t hash() const
{
- return DefaultHash<T *>{}(data_);
+ return get_default_hash(data_);
}
friend bool operator==(const UserCounter &a, const UserCounter &b)
diff --git a/source/blender/blenlib/intern/math_vec.cc b/source/blender/blenlib/intern/math_vec.cc
index 1d138d0b0f4..223c0e273f0 100644
--- a/source/blender/blenlib/intern/math_vec.cc
+++ b/source/blender/blenlib/intern/math_vec.cc
@@ -173,7 +173,7 @@ mpq3 mpq3::cross_poly(Span<mpq3> poly)
uint64_t hash_mpq_class(const mpq_class &value)
{
/* TODO: better/faster implementation of this. */
- return DefaultHash<float>{}(static_cast<float>(value.get_d()));
+ return get_default_hash(static_cast<float>(value.get_d()));
}
uint64_t mpq2::hash() const
diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc
index bc12ff1a652..bf70b044d0d 100644
--- a/source/blender/blenlib/intern/mesh_boolean.cc
+++ b/source/blender/blenlib/intern/mesh_boolean.cc
@@ -97,10 +97,7 @@ class Edge {
uint64_t hash() const
{
- constexpr uint64_t h1 = 33;
- uint64_t v0hash = DefaultHash<int>{}(v_[0]->id);
- uint64_t v1hash = DefaultHash<int>{}(v_[1]->id);
- return v0hash ^ (v1hash * h1);
+ return get_default_hash_2(v_[0]->id, v_[1]->id);
}
};