#ifndef LIBND4J_MODULARHASHER_H #define LIBND4J_MODULARHASHER_H #include #include #include #include #if defined(__ARM_NEON) #include #elif defined(__AVX2__) #include #elif defined(__SSE4_2__) #include #endif namespace sd { namespace helpers { namespace detail { // Common constants extern const uint64_t GOLDEN_RATIO; extern const uint64_t INITIAL_HASH; // Base template for SIMD operations template struct SIMDHasher { static uint64_t hash_chunk(const T* data, size_t size, uint64_t initial_hash) { uint64_t hash = initial_hash; for (size_t i = 0; i < size; i++) { hash ^= static_cast(data[i]); hash = (hash * GOLDEN_RATIO) ^ (hash >> 32); } return hash; } }; // Template for handling different types of data chunks template class DataChunkHasher { public: static uint64_t hash_data(const T* data, size_t size, uint64_t initial_hash = INITIAL_HASH) { return SIMDHasher::hash_chunk( reinterpret_cast(data), (size * sizeof(T) + 7) / 8, initial_hash ); } }; // Forward declare specializations template<> class DataChunkHasher { public: static uint64_t hash_data(const double* data, size_t size, uint64_t initial_hash = INITIAL_HASH); }; // Main hasher class class ModularHasher { public: template static uint64_t hash_vector(const std::vector& vec, uint64_t initial_hash = INITIAL_HASH) { return DataChunkHasher::hash_data(vec.data(), vec.size(), initial_hash); } static uint64_t combine_hashes(std::initializer_list hashes); static uint64_t hash_scalar(uint64_t value, uint64_t initial_hash = INITIAL_HASH); }; } // namespace detail } // namespace helpers } // namespace sd #endif //LIBND4J_MODULARHASHER_H