From b7da2f3d32da13b0beb4f2957d476197d60c36ae Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Wed, 8 Jul 2026 00:20:52 +0200 Subject: [PATCH] feat: add missing furlang/utility/hash.hpp I forgot to stage it from untracked lol --- furlang/include/furlang/utility/hash.hpp | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 furlang/include/furlang/utility/hash.hpp diff --git a/furlang/include/furlang/utility/hash.hpp b/furlang/include/furlang/utility/hash.hpp new file mode 100644 index 0000000..a01aed6 --- /dev/null +++ b/furlang/include/furlang/utility/hash.hpp @@ -0,0 +1,47 @@ +#ifndef FURLANG_UTILITY_HASH_HPP +#define FURLANG_UTILITY_HASH_HPP + +#include +#include + +namespace furlang { +namespace utility { + +// Source - https://stackoverflow.com/a/27952689 +// Posted by Yakk - Adam Nevraumont, modified by community. See post 'Timeline' for change history +// Retrieved 2026-07-07, License - CC BY-SA 4.0 +static inline std::size_t hash_combine(std::size_t lhs, std::size_t rhs) { + if constexpr (sizeof(std::size_t) >= 8) { + lhs ^= rhs + 0x517cc1b727220a95 + (lhs << 6) + (lhs >> 2); + } else { + lhs ^= rhs + 0x9e3779b9 + (lhs << 6) + (lhs >> 2); + } + + return lhs; +} + +// Source - https://stackoverflow.com/a/20602159 +// Posted by Casey, modified by community. See post 'Timeline' for change history +// Retrieved 2026-07-07, License - CC BY-SA 3.0 +template , typename SecondHash = std::hash> +struct pair_hash { + std::size_t operator()(const std::pair& pair) const { + return hash_combine(FirstHash()(pair.first), SecondHash()(pair.second)); + } +}; + +template > +struct vector_hash { + std::size_t operator()(const std::vector& vec) const { + std::size_t seed = 0; + for (const auto& element : vec) { + hash_combine(seed, Hash()(element)); + } + return seed; + } +}; + +} // namespace utility +} // namespace furlang + +#endif // FURLANG_UTILITY_HASH_HPP