#pragma once #include "../tensor.hpp" #include #include namespace infinicore { // Base hash_combine for arithmetic types template std::enable_if_t, void> hash_combine(size_t &seed, const T &value) { seed ^= std::hash{}(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } // Specialization for Tensor inline void hash_combine(size_t &seed, Tensor tensor) { hash_combine(seed, static_cast(tensor->dtype())); for (Size shape : tensor->shape()) { hash_combine(seed, shape); } for (Stride stride : tensor->strides()) { hash_combine(seed, static_cast(stride)); } } // Specialization for optional template inline void hash_combine(size_t &seed, const std::optional &opt) { hash_combine(seed, opt.has_value()); if (opt) { hash_combine(seed, *opt); } } // Specialization for std::string inline void hash_combine(size_t &seed, const std::string &str) { hash_combine(seed, std::hash{}(str)); } // Specialization for const char* inline void hash_combine(size_t &seed, const char *str) { hash_combine(seed, std::string(str)); } // Variadic template for multiple arguments template void hash_combine(size_t &seed, const First &first, const Rest &...rest) { hash_combine(seed, first); hash_combine(seed, rest...); } // Base case for variadic template inline void hash_combine(size_t &seed) { // Base case - do nothing } // Convenience function to hash multiple values template size_t hash_combine(const Types &...values) { size_t seed = 0; hash_combine(seed, values...); return seed; } } // namespace infinicore