diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-07-26 01:47:32 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-07-26 01:47:32 +0100 |
| commit | c52dbf5513ae7f106634967162da5cfb01dc5af3 (patch) | |
| tree | b6715d0fdacebd48491b9b05cf85f1d92028f84b /dev/lib/logic/equiv.hpp | |
| parent | 01565adb9cf5ef991196f56c7f5f7b6161daa005 (diff) | |
feat: SOCL v1.0.2, changelog soon!v1.0.2
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/lib/logic/equiv.hpp')
| -rw-r--r-- | dev/lib/logic/equiv.hpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/dev/lib/logic/equiv.hpp b/dev/lib/logic/equiv.hpp new file mode 100644 index 0000000..4bb5904 --- /dev/null +++ b/dev/lib/logic/equiv.hpp @@ -0,0 +1,102 @@ +/* + * File: equiv.hpp + * Purpose: Equivalence runtime c++ header. + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. + */ + +#pragma once + +namespace snu::equiv +{ + template <typename T> + struct basic_hash_trait + { + /// @brief hash from T's result. + static typename T::result hash() + { + static T val; + return val.hash(); + } + }; + + template <typename T, typename U> + struct is_same + { + static constexpr bool value = false; + + /// @brief check if hash matches what we expect. + constexpr bool operator()() noexcept + { + return T::hash() == U::hash(); + } + }; + + template <typename T> + struct is_same<T, T> + { + static constexpr bool value = true; + }; + + template <typename T, typename U> + struct is_not_same + { + static constexpr bool value = true; + + constexpr bool operator()() noexcept + { + return T::hash() != U::hash(); + } + }; + + template <typename T> + struct is_not_same<T, T> + { + static constexpr bool value = false; + }; + + template <typename T> + struct equiv_is_int8 + { + private: + T left_ = 255, right_ = 255; + + public: + using result = T; + + constexpr result hash() + { + return (left_ + right_) < 1; + } + }; + + template <typename T> + struct equiv_not_int8 + { + private: + T left_ = 255, right_ = 255; + + public: + using result = T; + + constexpr result hash() + { + return (left_ + right_) > 0; + } + }; + + template <typename T> + struct equiv_is_real + { + private: + T left_ = 5, right_ = 3; + + public: + using result = T; + + constexpr result hash() + { + return left_ / right_; + } + }; +} // namespace snu::equiv
\ No newline at end of file |
