ae2f::Core
Loading...
Searching...
No Matches
BitVec.hpp
Go to the documentation of this file.
1#include "./BitVec.h"
2
3#if !defined(ae2f_Macro_BitVector_hpp)
4#define ae2f_Macro_BitVector_hpp
5#include <type_traits>
6
7namespace ae2f {
8 namespace Macro {
13 template<typename t>
14 struct rBitVec {
16
19 t obj;
20
21 constexpr rBitVec(const t& obj) noexcept : obj(obj) {
22
23 static_assert(std::is_integral<t>::value, "t is not integer");
24 }
25 constexpr rBitVec(const t&& obj) noexcept : obj(obj) {
26 static_assert(std::is_integral<t>::value, "t is not integer");
27 }
28
29 template<typename T = t>
30 constexpr rBitVec(const rBitVec<T>& vec) noexcept : obj(vec.obj) {
31 static_assert(std::is_integral<t>::value, "t is not integer");
32 static_assert(std::is_integral<T>::value, "T is not integer");
33 }
34
35 template<typename T = t>
36 constexpr rBitVec(const rBitVec<T>&& vec) noexcept : obj(vec.obj) {
37 static_assert(std::is_integral<t>::value, "t is not integer");
38 static_assert(std::is_integral<T>::value, "T is not integer");
39 }
40
41 constexpr static rBitVec<t> Filled(idx_t length) noexcept {
42 return rBitVec(_ae2f_Macro_BitVec_Filled(length, t));
43 }
44
45 constexpr bool Get(idx_t i) const noexcept {
46 return ae2f_Macro_BitVec_Get(obj, i);
47 }
48
49 constexpr rBitVec<t> Get(idx_t start, idx_t end) const noexcept {
50 return ae2f_Macro_BitVec_GetRanged(this->obj, start, end);
51 }
52 constexpr rBitVec<t>& Set(idx_t i, bool val) noexcept {
53 obj = ae2f_Macro_BitVec_Set(this->obj, i, val);
54 return *this;
55 }
56
57 constexpr rBitVec<t> Set(idx_t i, bool val) const noexcept {
58 return ae2f_Macro_BitVec_Set(this->obj, i, val);
59 }
60 constexpr rBitVec<t> Set(idx_t start, idx_t end, rBitVec<t> val) const noexcept {
61 return ae2f_Macro_BitVec_SetRanged(this->obj, start, end, val.obj);
62 }
63 constexpr rBitVec<t>& Set(idx_t start, idx_t end, rBitVec<t> val) noexcept {
64 this->obj = const_cast<const rBitVec<t>*>(this)->Set(start, end, val);
65 return *this;
66 }
67
68 constexpr const idx_t Size(const t V) noexcept {
69 for (idx_t i = (sizeof(t) << 3); i; i--)
70 if (Get(i - 1)) return i;
71 return 0;
72 }
73 };
74 }
75}
76
77#endif // !defined(ae2f_Macro_BitVector_hpp) && defined(__cplusplus)
#define ae2f_Macro_BitVec_SetRanged(vector, start, end, val)
Sets the bits of [vector] from index of [start] and [end] by [val]. It will normalise the values of ...
Definition BitVec.h:65
#define ae2f_Macro_BitVec_Get(vector, idx)
Gets a bit of [vector] from index of [idx].
Definition BitVec.h:45
#define _ae2f_Macro_BitVec_Filled(len, vec_t)
Generates the vector filled in 1.
Definition BitVec.h:15
#define ae2f_Macro_BitVec_GetRanged(vector, start, end)
Gets the bits of [vector] between index of [start] and [end]. It will normalise the values of [start...
Definition BitVec.h:38
uint8_t ae2f_Macro_BitVecI_t
The pre-defined index type for Bit vector.
Definition BitVec.h:10
#define ae2f_Macro_BitVec_Set(vector, idx, val)
Sets a bit of [vector] from index of [idx] by [val].
Definition BitVec.h:72
Definition Alloc.hpp:6
Definition BitVec.hpp:14
static constexpr rBitVec< t > Filled(idx_t length) noexcept
Definition BitVec.hpp:41
constexpr rBitVec< t > Set(idx_t start, idx_t end, rBitVec< t > val) const noexcept
Definition BitVec.hpp:60
constexpr const idx_t Size(const t V) noexcept
Definition BitVec.hpp:68
constexpr rBitVec< t > & Set(idx_t i, bool val) noexcept
Definition BitVec.hpp:52
constexpr rBitVec< t > Set(idx_t i, bool val) const noexcept
Definition BitVec.hpp:57
constexpr bool Get(idx_t i) const noexcept
Definition BitVec.hpp:45
ae2f_Macro_BitVecI_t idx_t
Definition BitVec.hpp:15
t obj
The actual integer.
Definition BitVec.hpp:19
constexpr rBitVec< t > Get(idx_t start, idx_t end) const noexcept
Definition BitVec.hpp:49
constexpr rBitVec(const rBitVec< T > &vec) noexcept
Definition BitVec.hpp:30
constexpr rBitVec< t > & Set(idx_t start, idx_t end, rBitVec< t > val) noexcept
Definition BitVec.hpp:63
constexpr rBitVec(const t &&obj) noexcept
Definition BitVec.hpp:25
constexpr rBitVec(const rBitVec< T > &&vec) noexcept
Definition BitVec.hpp:36
constexpr rBitVec(const t &obj) noexcept
Definition BitVec.hpp:21