[Bf-blender-cvs] [863570d0990] temp-compact-node-prototype: simplify supporting heterogenous hashing
Jacques Lucke
noreply at git.blender.org
Thu Mar 25 16:11:06 CET 2021
Commit: 863570d0990392d87ee9d347a99ebe02e6abe64d
Author: Jacques Lucke
Date: Thu Mar 25 13:23:30 2021 +0100
Branches: temp-compact-node-prototype
https://developer.blender.org/rB863570d0990392d87ee9d347a99ebe02e6abe64d
simplify supporting heterogenous hashing
===================================================================
M source/blender/blenlib/BLI_hash.hh
M source/blender/blenlib/BLI_heap_value.hh
===================================================================
diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh
index f4cb6e6c778..816eba0afcc 100644
--- a/source/blender/blenlib/BLI_hash.hh
+++ b/source/blender/blenlib/BLI_hash.hh
@@ -101,6 +101,11 @@ template<typename T> struct DefaultHash {
return value.hash();
}
}
+
+ template<typename U> uint64_t operator()(const U &value) const
+ {
+ return T::hash_as(value);
+ }
};
/**
diff --git a/source/blender/blenlib/BLI_heap_value.hh b/source/blender/blenlib/BLI_heap_value.hh
index c1bdd2799d2..44d47050984 100644
--- a/source/blender/blenlib/BLI_heap_value.hh
+++ b/source/blender/blenlib/BLI_heap_value.hh
@@ -137,6 +137,19 @@ template<typename T> class HeapValue {
return value_;
}
+ uint64_t hash() const
+ {
+ if (value_ != nullptr) {
+ return DefaultHash<T>{}(*value_);
+ }
+ return 0;
+ }
+
+ static uint64_t hash_as(const T &value)
+ {
+ return DefaultHash<T>{}(value);
+ }
+
friend bool operator==(const HeapValue &a, const HeapValue &b)
{
if (a.value_ == nullptr && b.value_ == nullptr) {
@@ -180,19 +193,4 @@ template<typename T> class HeapValue {
}
};
-template<typename T> struct DefaultHash<HeapValue<T>> {
- uint64_t operator()(const HeapValue<T> &value) const
- {
- if (value) {
- return DefaultHash<T>{}(*value);
- }
- return 0;
- }
-
- uint64_t operator()(const T &value) const
- {
- return DefaultHash<T>{}(value);
- }
-};
-
} // namespace blender
More information about the Bf-blender-cvs
mailing list