diff --git a/src/core/common_code/internal/common_code.inl b/src/core/common_code/internal/common_code.inl index f80f3b6..3b284a9 100644 --- a/src/core/common_code/internal/common_code.inl +++ b/src/core/common_code/internal/common_code.inl @@ -144,7 +144,7 @@ constexpr auto operator<=>(const CommonCode &lhs, const CommonCode &rhs) { namespace std { template <> -struct std::hash { +struct hash { constexpr std::size_t operator()(const klotski::codec::CommonCode &c) const noexcept { return std::hash{}(c.unwrap()); } diff --git a/src/core/group/internal/hash.inl b/src/core/group/internal/hash.inl index aac133c..f6655fa 100644 --- a/src/core/group/internal/hash.inl +++ b/src/core/group/internal/hash.inl @@ -3,7 +3,7 @@ namespace std { template <> -struct std::hash { +struct hash { constexpr std::size_t operator()(const klotski::group::Group &g) const noexcept { // TODO: perf hash alg return std::hash{}(g.type_id() ^ g.pattern_id() ^ (int)g.toward()); @@ -11,14 +11,14 @@ struct std::hash { }; template <> -struct std::hash { +struct hash { constexpr std::size_t operator()(const klotski::group::GroupUnion &gu) const noexcept { return std::hash{}(gu.unwrap()); } }; template <> -struct std::hash { +struct hash { constexpr std::size_t operator()(const klotski::group::CaseInfo &info) const noexcept { // TODO: perf hash alg const auto h1 = std::hash{}(info.group()); diff --git a/src/core/raw_code/internal/raw_code.inl b/src/core/raw_code/internal/raw_code.inl index f7e62c8..43e70d3 100644 --- a/src/core/raw_code/internal/raw_code.inl +++ b/src/core/raw_code/internal/raw_code.inl @@ -100,7 +100,7 @@ constexpr auto operator<=>(const RawCode &lhs, const RawCode &rhs) { namespace std { template <> -struct std::hash { +struct hash { constexpr std::size_t operator()(const klotski::codec::RawCode &r) const noexcept { return std::hash{}(r.unwrap()); } diff --git a/src/core/short_code/internal/short_code.inl b/src/core/short_code/internal/short_code.inl index 1546092..bf428cb 100644 --- a/src/core/short_code/internal/short_code.inl +++ b/src/core/short_code/internal/short_code.inl @@ -122,7 +122,7 @@ constexpr auto operator<=>(const ShortCode &lhs, const ShortCode &rhs) { namespace std { template <> -struct std::hash { +struct hash { constexpr std::size_t operator()(const klotski::codec::ShortCode &s) const noexcept { return std::hash{}(s.unwrap()); } diff --git a/src/core/utils/utility.h b/src/core/utils/utility.h index 35ab59e..5e26c1d 100644 --- a/src/core/utils/utility.h +++ b/src/core/utils/utility.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -32,10 +33,16 @@ #define KLSK_UNREACHABLE __builtin_unreachable() // TODO: using `std::unreachable` /// Force function declaration to be inline. -#define KLSK_INLINE __attribute__ ((always_inline)) +#if defined(__clang__) + #define KLSK_INLINE __attribute__ ((always_inline)) +#else + #define KLSK_INLINE // NOTE: make sure that function can be inline +#endif #define KLSK_INLINE_H KLSK_INLINE inline #define KLSK_INLINE_CE KLSK_INLINE constexpr +// TODO: using `#pragma GCC unroll` + /// Prevent reordering for both compiler and processor. #define KLSK_MEM_BARRIER std::atomic_thread_fence(std::memory_order_seq_cst) diff --git a/src/core_ffi/py_ffi/include/py_ffi/common_code.h b/src/core_ffi/py_ffi/include/py_ffi/common_code.h index 6bb2d90..52ce799 100644 --- a/src/core_ffi/py_ffi/include/py_ffi/common_code.h +++ b/src/core_ffi/py_ffi/include/py_ffi/common_code.h @@ -96,11 +96,15 @@ constexpr auto operator<=>(const PyCommonCode &lhs, const PyCommonCode &rhs) { // ----------------------------------------------------------------------------------------- // +namespace std { + template <> -struct ::std::hash { +struct hash { size_t operator()(const klotski::ffi::PyCommonCode &common_code) const noexcept { return std::hash{}(common_code.value()); } }; +} // namespace std + // ----------------------------------------------------------------------------------------- // diff --git a/src/core_ffi/py_ffi/include/py_ffi/short_code.h b/src/core_ffi/py_ffi/include/py_ffi/short_code.h index 7a43965..385332e 100644 --- a/src/core_ffi/py_ffi/include/py_ffi/short_code.h +++ b/src/core_ffi/py_ffi/include/py_ffi/short_code.h @@ -86,11 +86,15 @@ constexpr auto operator<=>(const PyShortCode &lhs, const PyShortCode &rhs) { // ----------------------------------------------------------------------------------------- // +namespace std { + template <> -struct ::std::hash { +struct hash { size_t operator()(const klotski::ffi::PyShortCode &short_code) const noexcept { return std::hash{}(short_code.value()); } }; +} // namespace std + // ----------------------------------------------------------------------------------------- //