diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-08 16:04:28 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-08 16:10:30 +0300 |
commit | 34d175f3721521c35d333d676493848a02a96366 (patch) | |
tree | 1cf04954f4505f63bf48c0e1ff5df729bb6d43d5 /source/blender/functions/intern | |
parent | 840941215d42bb48fdc4724ed4d7058d275df740 (diff) |
Functions: initial hash/equals implementation for constant multi-functions
Diffstat (limited to 'source/blender/functions/intern')
-rw-r--r-- | source/blender/functions/intern/multi_function_builder.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/functions/intern/multi_function_builder.cc b/source/blender/functions/intern/multi_function_builder.cc index 1ada810a301..0a640b009cd 100644 --- a/source/blender/functions/intern/multi_function_builder.cc +++ b/source/blender/functions/intern/multi_function_builder.cc @@ -14,8 +14,12 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "FN_cpp_types.hh" #include "FN_multi_function_builder.hh" +#include "BLI_float3.hh" +#include "BLI_hash.hh" + namespace blender::fn { CustomMF_GenericConstant::CustomMF_GenericConstant(const CPPType &type, const void *value) @@ -35,6 +39,47 @@ void CustomMF_GenericConstant::call(IndexMask mask, type_.fill_uninitialized_indices(value_, output.buffer(), mask); } +uint CustomMF_GenericConstant::hash() const +{ + if (type_ == CPPType_float3) { + return DefaultHash<float3>{}(*(float3 *)value_); + } + if (type_ == CPPType_int32) { + return DefaultHash<int32_t>{}(*(int32_t *)value_); + } + if (type_ == CPPType_float) { + return DefaultHash<float>{}(*(float *)value_); + } + return MultiFunction::hash(); +} + +/* This should be moved into CPPType. */ +bool generic_values_are_equal(const CPPType &type, const void *a, const void *b) +{ + if (type == CPPType_float3) { + return *(float3 *)a == *(float3 *)b; + } + if (type == CPPType_int32) { + return *(int *)a == *(int *)b; + } + if (type == CPPType_float) { + return *(float *)a == *(float *)b; + } + return false; +} + +bool CustomMF_GenericConstant::equals(const MultiFunction &other) const +{ + const CustomMF_GenericConstant *_other = dynamic_cast<const CustomMF_GenericConstant *>(&other); + if (_other == nullptr) { + return false; + } + if (type_ != _other->type_) { + return false; + } + return generic_values_are_equal(type_, value_, _other->value_); +} + static std::string gspan_to_string(GSpan array) { std::stringstream ss; |