1 // 2 // hash_util.h 3 // 4 // Copyright © 2024 Apple Inc. All rights reserved. 5 // 6 // Please refer to the license found in the LICENSE file in the root directory of the source tree. 7 8 #pragma once 9 10 #include <functional> 11 #include <type_traits> 12 13 namespace executorchcoreml { hash_combine(size_t & seed,size_t hash)14inline void hash_combine(size_t& seed, size_t hash) { 15 // Combiner taken from boost::hash_combine 16 seed ^= hash + 0x9e3779b9 + (seed << 6) + (seed >> 2); 17 } 18 hash_combine(size_t & seed,T const & v)19template <class T> inline void hash_combine(size_t& seed, T const& v) { hash_combine(seed, std::hash<T> {}(v)); } 20 container_hash(const T & values)21template <class T> inline size_t container_hash(const T& values) { 22 size_t seed = 0; 23 for (auto it = values.begin(); it != values.end(); ++it) { 24 executorchcoreml::hash_combine(seed, *it); 25 } 26 27 return seed; 28 } 29 } 30