#include "MetaCoreFoundation/MetaCoreHash.h" #include #include namespace MetaCore { namespace { constexpr std::uint64_t GMetaCoreFnvOffsetBasis = 1469598103934665603ULL; constexpr std::uint64_t GMetaCoreFnvPrime = 1099511628211ULL; } // namespace std::uint64_t MetaCoreHashBytes(std::span data) { std::uint64_t hashValue = GMetaCoreFnvOffsetBasis; for (std::byte byteValue : data) { hashValue ^= static_cast(std::to_integer(byteValue)); hashValue *= GMetaCoreFnvPrime; } return hashValue; } std::uint64_t MetaCoreHashString(std::string_view value) { const auto* bytes = reinterpret_cast(value.data()); return MetaCoreHashBytes(std::span(bytes, value.size())); } std::optional MetaCoreHashFile(const std::filesystem::path& path) { std::ifstream input(path, std::ios::binary); if (!input.is_open()) { return std::nullopt; } std::array buffer{}; std::uint64_t hashValue = GMetaCoreFnvOffsetBasis; while (input.good()) { input.read(buffer.data(), static_cast(buffer.size())); const std::streamsize readCount = input.gcount(); if (readCount <= 0) { break; } const auto* bytes = reinterpret_cast(buffer.data()); for (std::streamsize index = 0; index < readCount; ++index) { hashValue ^= static_cast(std::to_integer(bytes[index])); hashValue *= GMetaCoreFnvPrime; } } return hashValue; } std::uint64_t MetaCoreHashCombine(std::uint64_t seed, std::uint64_t value) { seed ^= value + 0x9E3779B97F4A7C15ULL + (seed << 6U) + (seed >> 2U); return seed; } } // namespace MetaCore