BLI: simplify using DefaultHash
This commit is contained in:
@@ -58,9 +58,7 @@ class NodeTreeEvaluationContext {
|
||||
|
||||
uint64_t hash() const
|
||||
{
|
||||
const uint64_t hash1 = blender::DefaultHash<std::string>{}(object_name_);
|
||||
const uint64_t hash2 = BLI_session_uuid_hash_uint64(&modifier_session_uuid_);
|
||||
return hash1 ^ (hash2 * 33); /* Copied from DefaultHash for std::pair. */
|
||||
return blender::get_default_hash_2(object_name_, modifier_session_uuid_);
|
||||
}
|
||||
|
||||
friend bool operator==(const NodeTreeEvaluationContext &a, const NodeTreeEvaluationContext &b)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -661,7 +661,7 @@ class CPPType : NonCopyable, NonMovable {
|
||||
|
||||
uint64_t hash() const
|
||||
{
|
||||
return DefaultHash<const CPPType *>{}(this);
|
||||
return get_default_hash(this);
|
||||
}
|
||||
|
||||
template<typename T> bool is() const
|
||||
|
||||
@@ -220,7 +220,7 @@ template<typename T> bool is_equal_cb(const void *a, const void *b)
|
||||
template<typename T> uint64_t hash_cb(const void *value)
|
||||
{
|
||||
const T &value_ = *static_cast<const T *>(value);
|
||||
return DefaultHash<T>{}(value_);
|
||||
return get_default_hash(value_);
|
||||
}
|
||||
|
||||
} // namespace blender::fn::cpp_type_util
|
||||
|
||||
@@ -64,7 +64,7 @@ class MultiFunction {
|
||||
|
||||
virtual uint64_t hash() const
|
||||
{
|
||||
return DefaultHash<const MultiFunction *>{}(this);
|
||||
return get_default_hash(this);
|
||||
}
|
||||
|
||||
virtual bool equals(const MultiFunction &UNUSED(other)) const
|
||||
|
||||
@@ -384,7 +384,7 @@ template<typename T> class CustomMF_Constant : public MultiFunction {
|
||||
|
||||
uint64_t hash() const override
|
||||
{
|
||||
return DefaultHash<T>{}(value_);
|
||||
return get_default_hash(value_);
|
||||
}
|
||||
|
||||
bool equals(const MultiFunction &other) const override
|
||||
|
||||
@@ -110,7 +110,7 @@ class MFDataType {
|
||||
|
||||
uint64_t hash() const
|
||||
{
|
||||
return DefaultHash<CPPType>{}(*type_) + static_cast<uint64_t>(category_);
|
||||
return get_default_hash_2(*type_, category_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -261,7 +261,7 @@ inline const NodeRef *DNode::operator->() const
|
||||
|
||||
inline uint64_t DNode::hash() const
|
||||
{
|
||||
return DefaultHash<const DTreeContext *>{}(context_) ^ DefaultHash<const NodeRef *>{}(node_ref_);
|
||||
return get_default_hash_2(context_, node_ref_);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
@@ -316,8 +316,7 @@ inline const SocketRef *DSocket::operator->() const
|
||||
|
||||
inline uint64_t DSocket::hash() const
|
||||
{
|
||||
return DefaultHash<const DTreeContext *>{}(context_) ^
|
||||
DefaultHash<const SocketRef *>{}(socket_ref_);
|
||||
return get_default_hash_2(context_, socket_ref_);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user