30#ifndef ETL_BITSET_NEW_INCLUDED
31#define ETL_BITSET_NEW_INCLUDED
33#include "../platform.h"
34#include "../algorithm.h"
35#include "../iterator.h"
36#include "../integral_limits.h"
37#include "../algorithm.h"
38#include "../nullptr.h"
40#include "../exception.h"
41#include "../integral_limits.h"
43#include "../char_traits.h"
44#include "../static_assert.h"
45#include "../error_handler.h"
55#if defined(ETL_COMPILER_KEIL)
56#pragma diag_suppress 1300
61 #define ETL_STRL(x) L##x
62 #define ETL_STRu(x) u##x
63 #define ETL_STRU(x) U##x
79 template <
typename T =
void>
96 bitset_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
97 :
exception(reason_, file_name_, line_number_)
111 :
bitset_exception(ETL_ERROR_TEXT(
"bitset:type_too_small", ETL_BITSET_FILE_ID
"A"), file_name_, line_number_)
125 :
bitset_exception(ETL_ERROR_TEXT(
"bitset:overflow", ETL_BITSET_FILE_ID
"C"), file_name_, line_number_)
134 template <
typename TElement>
139 typedef typename etl::make_unsigned<TElement>::type element_type;
141 typedef element_type* pointer;
142 typedef const element_type* const_pointer;
146 static ETL_CONSTANT element_type All_Clear_Element = element_type(0);
151 ETL_CONSTEXPR14
size_t count(const_pointer pbuffer,
size_t number_of_elements)
const ETL_NOEXCEPT
155 for (
size_t i = 0UL; i < number_of_elements; ++i)
167 ETL_CONSTEXPR14
bool test(const_pointer pbuffer,
size_t number_of_elements,
size_t position)
const ETL_NOEXCEPT
170 element_type mask = element_type(0);
172 if (number_of_elements == 1U)
175 mask = element_type(1) << position;
180 mask = element_type(1) << (position & (Bits_Per_Element - 1));
183 return (pbuffer[index] & mask) != 0;
190 ETL_CONSTEXPR14
void set(pointer pbuffer,
size_t number_of_elements,
size_t position,
bool value =
true) ETL_NOEXCEPT
193 element_type
bit = 0;
195 if (number_of_elements == 0)
199 else if (number_of_elements == 1U)
202 bit = element_type(1) << position;
207 bit = element_type(1) << (position & (Bits_Per_Element - 1));
212 pbuffer[index] |=
bit;
216 pbuffer[index] &=
~bit;
223 ETL_CONSTEXPR14
void from_string(pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
const char* text) ETL_NOEXCEPT
225 if (text == ETL_NULLPTR)
227 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
232 size_t element_index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
235 while (element_index != number_of_elements)
237 pbuffer[element_index++] = All_Clear_Element;
241 size_t i = etl::min(total_bits, string_length);
245 set(pbuffer, number_of_elements, --i, *text++ == ETL_STR(
'1'));
253 ETL_CONSTEXPR14
void from_string(pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
const wchar_t* text) ETL_NOEXCEPT
255 if (text == ETL_NULLPTR)
257 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
262 size_t element_index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
265 while (element_index != number_of_elements)
267 pbuffer[element_index++] = All_Clear_Element;
271 size_t i = etl::min(total_bits, string_length);
275 set(pbuffer, number_of_elements, --i, *text++ == ETL_STRL(
'1'));
283 ETL_CONSTEXPR14
void from_string(pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
const char16_t* text) ETL_NOEXCEPT
285 if (text == ETL_NULLPTR)
287 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
292 size_t element_index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
295 while (element_index != number_of_elements)
297 pbuffer[element_index++] = All_Clear_Element;
301 size_t i = etl::min(total_bits, string_length);
305 set(pbuffer, number_of_elements, --i, *text++ == ETL_STRu(
'1'));
313 ETL_CONSTEXPR14
void from_string(pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
const char32_t* text) ETL_NOEXCEPT
315 if (text == ETL_NULLPTR)
317 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
322 size_t element_index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
325 while (element_index != number_of_elements)
327 pbuffer[element_index++] = All_Clear_Element;
331 size_t i = etl::min(total_bits, string_length);
335 set(pbuffer, number_of_elements, --i, *text++ == ETL_STRU(
'1'));
343 ETL_CONSTEXPR14
void set(pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
const char* text) ETL_NOEXCEPT
345 from_string(pbuffer, number_of_elements, total_bits, text);
351 ETL_CONSTEXPR14
void set(pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
const wchar_t* text) ETL_NOEXCEPT
353 from_string(pbuffer, number_of_elements, total_bits, text);
359 ETL_CONSTEXPR14
void set(pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
const char16_t* text) ETL_NOEXCEPT
361 from_string(pbuffer, number_of_elements, total_bits, text);
367 ETL_CONSTEXPR14
void set(pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
const char32_t* text) ETL_NOEXCEPT
369 from_string(pbuffer, number_of_elements, total_bits, text);
375 template <
typename T>
378 value(const_pointer pbuffer,
size_t number_of_elements)
const ETL_NOEXCEPT
382 const bool OK = (
sizeof(T) * CHAR_BIT) >= (number_of_elements * Bits_Per_Element);
386 uint_least8_t shift = 0U;
388 for (
size_t i = 0UL; i < number_of_elements; ++i)
390 v |= T(
typename etl::make_unsigned<T>::type(pbuffer[i]) << shift);
391 shift += uint_least8_t(Bits_Per_Element);
401 ETL_CONSTEXPR14
void reset(pointer pbuffer,
size_t number_of_elements,
size_t position) ETL_NOEXCEPT
404 element_type
bit = element_type(0);
406 if (number_of_elements == 0)
410 else if (number_of_elements == 1)
413 bit = element_type(1) << position;
418 bit = element_type(1) << (position & (Bits_Per_Element - 1));
421 pbuffer[index] &=
~bit;
427 ETL_CONSTEXPR14
void flip(pointer pbuffer,
size_t number_of_elements) ETL_NOEXCEPT
429 for (
size_t i = 0UL; i < number_of_elements; ++i)
431 pbuffer[i] = ~pbuffer[i];
438 ETL_CONSTEXPR14
void flip(pointer pbuffer,
size_t number_of_elements,
size_t position) ETL_NOEXCEPT
441 element_type
bit = element_type(0);
443 if (number_of_elements == 0)
447 else if (number_of_elements == 1)
450 bit = element_type(1) << position;
455 bit = element_type(1) << (position & (Bits_Per_Element - 1));
458 pbuffer[index] ^=
bit;
464 ETL_CONSTEXPR14
bool all(const_pointer pbuffer,
size_t number_of_elements, element_type top_mask)
const ETL_NOEXCEPT
466 if (number_of_elements == 0UL)
472 for (
size_t i = 0UL; i < (number_of_elements - 1U); ++i)
474 if (pbuffer[i] != All_Set_Element)
481 if (pbuffer[number_of_elements - 1U] != (All_Set_Element & top_mask))
492 ETL_CONSTEXPR14
bool none(const_pointer pbuffer,
size_t number_of_elements)
const ETL_NOEXCEPT
494 for (
size_t i = 0UL; i < number_of_elements; ++i)
510 ETL_CONSTEXPR14
size_t find_first(const_pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
bool state)
const ETL_NOEXCEPT
512 return find_next(pbuffer, number_of_elements, total_bits, state, 0);
521 ETL_CONSTEXPR14
size_t find_next(const_pointer pbuffer,
size_t number_of_elements,
size_t total_bits,
bool state,
size_t position)
const ETL_NOEXCEPT
525 size_t bit = position & (Bits_Per_Element - 1);
527 element_type mask = 1 <<
bit;
530 while (index < number_of_elements)
532 element_type
value = pbuffer[index];
535 if ((state && (
value != All_Clear_Element)) ||
536 (!state && (
value != All_Set_Element)))
539 while ((
bit < Bits_Per_Element) && (position < total_bits))
542 if (((
value & mask) != 0) == state)
555 position += (Bits_Per_Element -
bit);
571 template <
typename TString>
572 ETL_CONSTEXPR14 TString
to_string(const_pointer pbuffer,
573 size_t number_of_elements,
575 typename TString::value_type zero,
576 typename TString::value_type one)
const
580 result.resize(active_bits,
'\0');
585 for (
size_t i = active_bits; i > 0; --i)
587 result[active_bits - i] =
test(pbuffer, number_of_elements, i - 1) ? one : zero;
596 ETL_CONSTEXPR14
void shift_left_equals(pointer pbuffer,
size_t number_of_elements,
size_t shift) ETL_NOEXCEPT
598 if (number_of_elements == 1U)
601 pbuffer[0] <<= shift;
603 else if ((shift % Bits_Per_Element) == 0U)
606 const size_t element_shift = shift / Bits_Per_Element;
607 etl::copy_backward(pbuffer, pbuffer + number_of_elements - element_shift, pbuffer + number_of_elements);
608 etl::fill_n(pbuffer, element_shift, All_Clear_Element);
613 const size_t split_position = Bits_Per_Element - (shift % Bits_Per_Element);
616 int src_index = int(number_of_elements - (shift / Bits_Per_Element) - 1U);
619 int dst_index = int(number_of_elements - 1U);
622 const size_t lsb_shift = Bits_Per_Element - split_position;
623 const size_t msb_shift = split_position;
627 const element_type lsb_shifted_mask = element_type(
lsb_mask << lsb_shift);
630 element_type lsb = element_type((pbuffer[src_index] &
lsb_mask) << lsb_shift);
631 pbuffer[dst_index] = lsb;
635 while (src_index >= 0)
638 element_type msb = element_type((pbuffer[src_index] &
msb_mask) >> msb_shift);
639 pbuffer[dst_index] = pbuffer[dst_index] | msb;
643 element_type lsb = element_type((pbuffer[src_index] &
lsb_mask) << lsb_shift);
644 pbuffer[dst_index] = lsb;
650 pbuffer[dst_index] &= lsb_shifted_mask;
654 while (dst_index >= 0)
656 pbuffer[dst_index] = 0;
665 ETL_CONSTEXPR14
void shift_right_equals(pointer pbuffer,
size_t number_of_elements,
size_t shift) ETL_NOEXCEPT
667 if (number_of_elements == 1U)
670 pbuffer[0] >>= shift;
672 else if ((shift % Bits_Per_Element) == 0U)
675 const size_t element_shift = (shift / Bits_Per_Element);
676 pointer pzeros_begin = etl::copy(pbuffer + element_shift, pbuffer + number_of_elements, pbuffer);
677 etl::fill_n(pzeros_begin, element_shift, All_Clear_Element);
682 const size_t split_position = shift % Bits_Per_Element;
685 int src_index = int(shift / Bits_Per_Element);
691 const size_t lsb_shift = Bits_Per_Element - split_position;
692 const size_t msb_shift = split_position;
696 const element_type msb_shifted_mask = element_type(
msb_mask >> msb_shift);
699 while (src_index <
int(number_of_elements - 1))
702 element_type msb = element_type((pbuffer[src_index] &
msb_mask) >> msb_shift);
706 element_type lsb = element_type((pbuffer[src_index] &
lsb_mask) << lsb_shift);
709 pbuffer[dst_index] = lsb | msb;
714 element_type msb = element_type((pbuffer[src_index] &
msb_mask) >> msb_shift);
715 pbuffer[dst_index] = msb;
719 pbuffer[dst_index] &= msb_shifted_mask;
723 while (dst_index <
int(number_of_elements))
725 pbuffer[dst_index] = 0;
734 ETL_CONSTEXPR14
void and_equals(pointer pbuffer, const_pointer pbuffer2,
size_t number_of_elements) ETL_NOEXCEPT
736 for (
size_t i = 0U; i < number_of_elements; ++i)
738 pbuffer[i] &= pbuffer2[i];
745 ETL_CONSTEXPR14
void or_equals(pointer pbuffer, const_pointer pbuffer2,
size_t number_of_elements) ETL_NOEXCEPT
747 for (
size_t i = 0U; i < number_of_elements; ++i)
749 pbuffer[i] |= pbuffer2[i];
756 ETL_CONSTEXPR14
void xor_equals(pointer pbuffer, const_pointer pbuffer2,
size_t number_of_elements) ETL_NOEXCEPT
758 for (
size_t i = 0U; i < number_of_elements; ++i)
760 pbuffer[i] ^= pbuffer2[i];
767 ETL_CONSTEXPR14
void initialise(pointer pbuffer,
size_t number_of_elements,
unsigned long long value) ETL_NOEXCEPT
774 pbuffer[0] = element_type(
value);
781 while ((
value != 0) && (i != number_of_elements))
783 pbuffer[i++] =
value & All_Set_Element;
788 while (i != number_of_elements)
790 pbuffer[i++] = All_Clear_Element;
798 ETL_CONSTEXPR14
void swap(pointer pbuffer1, pointer pbuffer2,
size_t number_of_elements)
800 const pointer pbuffer1_end = pbuffer1 + number_of_elements;
802 while (pbuffer1 != pbuffer1_end)
804 element_type temp = *pbuffer1;
805 *pbuffer1 = *pbuffer2;
813 template <
typename TElement>
814 ETL_CONSTANT
size_t bitset_impl<TElement>::Bits_Per_Element;
816 template <
typename TElement>
817 ETL_CONSTANT
typename bitset_impl<TElement>::element_type bitset_impl<TElement>::All_Set_Element;
819 template <
typename TElement>
820 ETL_CONSTANT
typename bitset_impl<TElement>::element_type bitset_impl<TElement>::All_Clear_Element;
823 template <
size_t Active_Bits = 0U,
824 typename TElement = char,
849 template <
size_t Active_Bits,
typename TElement>
855 typedef typename etl::make_unsigned<TElement>::type element_type;
857 typedef element_type* pointer;
858 typedef const element_type* const_pointer;
861 static ETL_CONSTANT
size_t Number_Of_Elements = 1U;
862 static ETL_CONSTANT
size_t Allocated_Bits = Bits_Per_Element;
864 static ETL_CONSTANT element_type All_Clear_Element = element_type(0);
865 static ETL_CONSTANT
size_t Top_Mask_Shift = 0U;
866 static ETL_CONSTANT element_type Top_Mask = All_Set_Element;
883 ETL_CONSTEXPR14 bit_reference(
const bit_reference& other) ETL_NOEXCEPT
884 : p_bitset(other.p_bitset)
885 , position(other.position)
892 ETL_CONSTEXPR14
operator bool() const ETL_NOEXCEPT
894 return p_bitset->test(position);
900 ETL_CONSTEXPR14 bit_reference&
operator = (
bool b) ETL_NOEXCEPT
902 p_bitset->set(position, b);
909 ETL_CONSTEXPR14 bit_reference&
operator = (
const bit_reference& r) ETL_NOEXCEPT
911 p_bitset->set(position,
bool(r));
918 ETL_CONSTEXPR14 bit_reference&
flip() ETL_NOEXCEPT
920 p_bitset->
flip(position);
929 return !p_bitset->test(position);
937 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
938 : p_bitset(ETL_NULLPTR)
947 : p_bitset(&r_bitset)
948 , position(position_)
952 bitset<Active_Bits, TElement, true>* p_bitset;
960 : buffer(All_Clear_Element)
968 : buffer(other.buffer)
976 : buffer(element_type(
value))
983 ETL_CONSTEXPR14
bitset(
const char* text) ETL_NOEXCEPT
984 : buffer(All_Clear_Element)
992 ETL_CONSTEXPR14
bitset(
const wchar_t* text) ETL_NOEXCEPT
993 : buffer(All_Clear_Element)
1001 ETL_CONSTEXPR14
bitset(
const char16_t* text) ETL_NOEXCEPT
1002 : buffer(All_Clear_Element)
1010 ETL_CONSTEXPR14
bitset(
const char32_t* text) ETL_NOEXCEPT
1011 : buffer(All_Clear_Element)
1021 buffer = other.buffer;
1031 buffer = All_Set_Element;
1051 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
1053 const element_type mask = element_type(element_type(1) << position);
1111 if (text == ETL_NULLPTR)
1120 string_length = etl::min(Active_Bits, string_length);
1122 element_type mask = element_type(element_type(1) << (string_length - 1U));
1124 for (
size_t i = 0U; i < string_length; ++i)
1126 if (text[i] == ETL_STR(
'1'))
1147 if (text == ETL_NULLPTR)
1156 string_length = etl::min(Active_Bits, string_length);
1158 element_type mask = element_type(element_type(1) << (string_length - 1U));
1160 for (
size_t i = 0U; i < string_length; ++i)
1162 if (text[i] == ETL_STRL(
'1'))
1183 if (text == ETL_NULLPTR)
1192 string_length = etl::min(Active_Bits, string_length);
1194 element_type mask = element_type(element_type(1) << (string_length - 1U));
1196 for (
size_t i = 0U; i < string_length; ++i)
1198 if (text[i] == ETL_STRu(
'1'))
1219 if (text == ETL_NULLPTR)
1228 string_length = etl::min(Active_Bits, string_length);
1230 element_type mask = element_type(element_type(1) << (string_length - 1U));
1232 for (
size_t i = 0U; i < string_length; ++i)
1234 if (text[i] == ETL_STRU(
'1'))
1253 template <
typename T>
1259 ETL_STATIC_ASSERT((
sizeof(T) * CHAR_BIT) >= (Number_Of_Elements * Bits_Per_Element),
"Integral type too small");
1263 const bool OK = (
sizeof(T) * CHAR_BIT) >= Bits_Per_Element;
1267 v = T(
typename etl::make_unsigned<T>::type(buffer));
1276 ETL_CONSTEXPR14
unsigned long to_ulong() const ETL_NOEXCEPT
1278 return value<unsigned long>();
1284 ETL_CONSTEXPR14
unsigned long long to_ullong() const ETL_NOEXCEPT
1286 return value<unsigned long long>();
1294 buffer = All_Clear_Element;
1304 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
1306 const element_type mask = element_type(element_type(1) << position);
1316 ETL_CONSTEXPR14
bool test(
size_t position)
const
1318 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow),
false);
1320 const element_type mask = element_type(element_type(1) << position);
1321 return (buffer & mask) != 0U;
1329 ETL_CONSTEXPR14
size_t size() const ETL_NOEXCEPT
1337 ETL_CONSTEXPR14
size_t count() const ETL_NOEXCEPT
1345 ETL_CONSTEXPR14
bool all() const ETL_NOEXCEPT
1347 return buffer == All_Set_Element;
1353 ETL_CONSTEXPR14
bool all(element_type mask)
const ETL_NOEXCEPT
1355 return buffer == (All_Set_Element & mask);
1361 ETL_CONSTEXPR14
bool none() const ETL_NOEXCEPT
1363 return buffer == All_Clear_Element;
1369 ETL_CONSTEXPR14
bool none(element_type mask)
const ETL_NOEXCEPT
1371 return (buffer & mask) == All_Clear_Element;
1377 ETL_CONSTEXPR14
bool any() const ETL_NOEXCEPT
1385 ETL_CONSTEXPR14
bool any(element_type mask)
const ETL_NOEXCEPT
1415 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
1417 const element_type mask = element_type(element_type(1) << position);
1426 ETL_CONSTEXPR14
bool operator[] (
size_t position)
const ETL_NOEXCEPT
1428 if (position < Active_Bits)
1430 const element_type mask = element_type(element_type(1) << position);
1431 return (buffer & mask) != 0U;
1440 ETL_CONSTEXPR14 bit_reference
operator [] (
size_t position) ETL_NOEXCEPT
1442 return bit_reference(*
this, position);
1449 template <
typename TString = etl::
string<Active_Bits>>
1451 template <
typename TString>
1453 ETL_CONSTEXPR14 TString
to_string(
typename TString::value_type zero =
typename TString::value_type(
'0'),
1454 typename TString::value_type one =
typename TString::value_type(
'1'))
const
1458 result.resize(Active_Bits,
'\0');
1463 for (
size_t i = Active_Bits; i > 0; --i)
1465 result[Active_Bits - i] =
test(i - 1) ? one : zero;
1487 ETL_CONSTEXPR14
size_t find_next(
bool state,
size_t position)
const ETL_NOEXCEPT
1489 if (position < Active_Bits)
1492 size_t bit = position;
1494 element_type mask = 1U << position;
1497 if ((state && (buffer != All_Clear_Element)) || (!state && (buffer != All_Set_Element)))
1500 while (
bit < Active_Bits)
1503 if (((buffer & mask) != 0) == state)
1535 buffer &= other.buffer;
1557 buffer |= other.buffer;
1579 buffer ^= other.buffer;
1613 if (shift >= Active_Bits)
1642 if (shift >= Active_Bits)
1659 return (lhs.buffer == rhs.buffer);
1667 element_type temp = buffer;
1668 buffer = other.buffer;
1669 other.buffer = temp;
1692 element_type buffer;
1695 template <
size_t Active_Bits,
typename TElement>
1696 ETL_CONSTANT
size_t bitset<Active_Bits, TElement, true>::Bits_Per_Element;
1698 template <
size_t Active_Bits,
typename TElement>
1699 ETL_CONSTANT
size_t bitset<Active_Bits, TElement, true>::Number_Of_Elements;
1701 template <
size_t Active_Bits,
typename TElement>
1702 ETL_CONSTANT
size_t bitset<Active_Bits, TElement, true>::Allocated_Bits;
1704 template <
size_t Active_Bits,
typename TElement>
1705 ETL_CONSTANT
typename bitset<Active_Bits, TElement, true>::element_type bitset<Active_Bits, TElement, true>::All_Set_Element;
1707 template <
size_t Active_Bits,
typename TElement>
1708 ETL_CONSTANT
typename bitset<Active_Bits, TElement, true>::element_type bitset<Active_Bits, TElement, true>::All_Clear_Element;
1710 template <
size_t Active_Bits,
typename TElement>
1711 ETL_CONSTANT
size_t bitset<Active_Bits, TElement, true>::Top_Mask_Shift;
1713 template <
size_t Active_Bits,
typename TElement>
1714 ETL_CONSTANT
typename bitset<Active_Bits, TElement, true>::element_type bitset<Active_Bits, TElement, true>::Top_Mask;
1719 template <
size_t Active_Bits,
typename TElement>
1728 struct select_element_type
1735 typedef typename select_element_type::type element_type;
1736 typedef element_type* pointer;
1737 typedef const element_type* const_pointer;
1740 static ETL_CONSTANT
size_t Number_Of_Elements = (Active_Bits % Bits_Per_Element == 0) ? Active_Bits / Bits_Per_Element : Active_Bits / Bits_Per_Element + 1;
1741 static ETL_CONSTANT
size_t Allocated_Bits = Number_Of_Elements * Bits_Per_Element;
1742 static ETL_CONSTANT
size_t Top_Mask_Shift = ((Bits_Per_Element - (Allocated_Bits - Active_Bits)) % Bits_Per_Element);
1745 static ETL_CONSTANT element_type Top_Mask = element_type(Top_Mask_Shift == 0 ? All_Set_Element : ~(All_Set_Element << Top_Mask_Shift));
1747 static ETL_CONSTANT
size_t ALLOCATED_BITS = Allocated_Bits;
1764 ETL_CONSTEXPR14 bit_reference(
const bit_reference& other) ETL_NOEXCEPT
1765 : p_bitset(other.p_bitset)
1766 , position(other.position)
1773 ETL_CONSTEXPR14
operator bool() const ETL_NOEXCEPT
1775 return p_bitset->test(position);
1783 p_bitset->set(position, b);
1790 ETL_CONSTEXPR14 bit_reference&
operator = (
const bit_reference& r) ETL_NOEXCEPT
1792 p_bitset->set(position,
bool(r));
1799 ETL_CONSTEXPR14 bit_reference&
flip() ETL_NOEXCEPT
1801 p_bitset->
flip(position);
1810 return !p_bitset->test(position);
1818 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
1819 : p_bitset(ETL_NULLPTR)
1828 : p_bitset(&r_bitset)
1829 , position(position_)
1833 bitset<Active_Bits, TElement, false>* p_bitset;
1852 etl::copy_n(other.buffer, Number_Of_Elements, buffer);
1862 clear_unused_bits_in_msb();
1868 ETL_CONSTEXPR14
bitset(
const char* text) ETL_NOEXCEPT
1871 ibitset.
set(buffer, Number_Of_Elements, Active_Bits, text);
1872 clear_unused_bits_in_msb();
1878 ETL_CONSTEXPR14
bitset(
const wchar_t* text) ETL_NOEXCEPT
1881 ibitset.
set(buffer, Number_Of_Elements, Active_Bits, text);
1882 clear_unused_bits_in_msb();
1888 ETL_CONSTEXPR14
bitset(
const char16_t* text) ETL_NOEXCEPT
1891 ibitset.
set(buffer, Number_Of_Elements, Active_Bits, text);
1892 clear_unused_bits_in_msb();
1898 ETL_CONSTEXPR14
bitset(
const char32_t* text) ETL_NOEXCEPT
1901 ibitset.
set(buffer, Number_Of_Elements, Active_Bits, text);
1902 clear_unused_bits_in_msb();
1910 etl::copy_n(other.buffer, Number_Of_Elements, buffer);
1920 etl::fill_n(buffer, Number_Of_Elements, All_Set_Element);
1921 clear_unused_bits_in_msb();
1931 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
1934 clear_unused_bits_in_msb();
1944 ibitset.
set(buffer, Number_Of_Elements, Active_Bits, text);
1954 ibitset.
set(buffer, Number_Of_Elements, Active_Bits, text);
1964 ibitset.
set(buffer, Number_Of_Elements, Active_Bits, text);
1974 ibitset.
set(buffer, Number_Of_Elements, Active_Bits, text);
2022 template <
typename T>
2028 ETL_STATIC_ASSERT((
sizeof(T) * CHAR_BIT) >= (Number_Of_Elements * Bits_Per_Element),
"Type too small");
2030 return ibitset.template value<T>(buffer, Number_Of_Elements);
2036 ETL_CONSTEXPR14
unsigned long to_ulong() const ETL_NOEXCEPT
2038 return value<unsigned long>();
2044 ETL_CONSTEXPR14
unsigned long long to_ullong() const ETL_NOEXCEPT
2046 return value<unsigned long long>();
2053 etl::fill_n(buffer, Number_Of_Elements, All_Clear_Element);
2063 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
2074 ETL_CONSTEXPR14
bool test(
size_t position)
const
2076 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow),
false);
2078 return ibitset.
test(buffer, Number_Of_Elements, position);
2084 ETL_CONSTEXPR14
size_t size() const ETL_NOEXCEPT
2092 ETL_CONSTEXPR14
size_t count() const ETL_NOEXCEPT
2100 ETL_CONSTEXPR14
bool all() const ETL_NOEXCEPT
2102 return ibitset.all(buffer, Number_Of_Elements, Top_Mask);
2108 ETL_CONSTEXPR14
bool none() const ETL_NOEXCEPT
2116 ETL_CONSTEXPR14
bool any() const ETL_NOEXCEPT
2127 clear_unused_bits_in_msb();
2137 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
2139 ibitset.
flip(buffer, Number_Of_Elements, position);
2147 ETL_CONSTEXPR14
bool operator[] (
size_t position)
const ETL_NOEXCEPT
2149 return ibitset.
test(buffer, Number_Of_Elements, position);
2155 ETL_CONSTEXPR14 bit_reference
operator [] (
size_t position) ETL_NOEXCEPT
2157 return bit_reference(*
this, position);
2164 template <
typename TString = etl::
string<Active_Bits>>
2166 template <
typename TString>
2168 ETL_CONSTEXPR14 TString
to_string(
typename TString::value_type zero =
typename TString::value_type(
'0'),
2169 typename TString::value_type one =
typename TString::value_type(
'1'))
const
2171 return ibitset.template to_string<TString>(buffer, Number_Of_Elements, Active_Bits, zero, one);
2181 return ibitset.
find_next(buffer, Number_Of_Elements, Active_Bits, state, 0);
2190 ETL_CONSTEXPR14
size_t find_next(
bool state,
size_t position)
const ETL_NOEXCEPT
2192 return ibitset.
find_next(buffer, Number_Of_Elements, Active_Bits, state, position);
2212 ibitset.and_equals(&buffer[0], &other.buffer[0], Number_Of_Elements);
2234 ibitset.or_equals(&buffer[0], &other.buffer[0], Number_Of_Elements);
2256 ibitset.xor_equals(&buffer[0], &other.buffer[0], Number_Of_Elements);
2290 if (shift >= Active_Bits)
2296 ibitset.shift_left_equals(buffer, Number_Of_Elements, shift);
2297 clear_unused_bits_in_msb();
2320 if (shift >= Active_Bits)
2326 ibitset.shift_right_equals(buffer, Number_Of_Elements, shift);
2337 return etl::equal(lhs.buffer,
2338 lhs.buffer + lhs.Number_Of_Elements,
2347 ibitset.
swap(buffer, other.buffer, Number_Of_Elements);
2356 return span_type(buffer, Number_Of_Elements);
2373 ETL_CONSTEXPR14
void clear_unused_bits_in_msb() ETL_NOEXCEPT
2375 buffer[Number_Of_Elements - 1U] &= Top_Mask;
2380 element_type buffer[Number_Of_Elements > 0U ? Number_Of_Elements : 1U];
2383 template <
size_t Active_Bits,
typename TElement>
2384 ETL_CONSTANT
size_t bitset<Active_Bits, TElement, false>::Bits_Per_Element;
2386 template <
size_t Active_Bits,
typename TElement>
2387 ETL_CONSTANT
size_t bitset<Active_Bits, TElement, false>::Number_Of_Elements;
2389 template <
size_t Active_Bits,
typename TElement>
2390 ETL_CONSTANT
size_t bitset<Active_Bits, TElement, false>::Allocated_Bits;
2392 template <
size_t Active_Bits,
typename TElement>
2393 ETL_CONSTANT
typename bitset<Active_Bits, TElement, false>::element_type bitset<Active_Bits, TElement, false>::All_Set_Element;
2395 template <
size_t Active_Bits,
typename TElement>
2396 ETL_CONSTANT
typename bitset<Active_Bits, TElement, false>::element_type bitset<Active_Bits, TElement, false>::All_Clear_Element;
2398 template <
size_t Active_Bits,
typename TElement>
2399 ETL_CONSTANT
size_t bitset<Active_Bits, TElement, false>::Top_Mask_Shift;
2401 template <
size_t Active_Bits,
typename TElement>
2402 ETL_CONSTANT
typename bitset<Active_Bits, TElement, false>::element_type bitset<Active_Bits, TElement, false>::Top_Mask;
2408 template <
size_t Active_Bits,
typename TElement,
bool IsSingleElement>
2420 template<
size_t Active_Bits,
typename TElement,
bool IsSingleElement>
2432 template<
size_t Active_Bits,
typename TElement,
bool IsSingleElement>
2444 template<
size_t Active_Bits,
typename TElement,
bool IsSingleElement>
2447 return !(lhs == rhs);
2454template <
size_t Active_Bits,
typename TElement,
bool IsSingleElement>
2466 template <
size_t Active_Bits = 0U,
2467 typename TElement = char,
2492 template <
size_t Active_Bits,
typename TElement>
2498 typedef typename etl::make_unsigned<TElement>::type element_type;
2500 typedef element_type* pointer;
2501 typedef const element_type* const_pointer;
2504 static ETL_CONSTANT
size_t Number_Of_Elements = 1U;
2505 static ETL_CONSTANT
size_t Allocated_Bits = Bits_Per_Element;
2507 static ETL_CONSTANT element_type All_Clear_Element = element_type(0);
2508 static ETL_CONSTANT
size_t Top_Mask_Shift = 0U;
2509 static ETL_CONSTANT element_type Top_Mask = All_Set_Element;
2514 typedef element_type buffer_type;
2528 ETL_CONSTEXPR14 bit_reference(
const bit_reference& other) ETL_NOEXCEPT
2529 : p_bitset(other.p_bitset)
2530 , position(other.position)
2537 ETL_CONSTEXPR14
operator bool() const ETL_NOEXCEPT
2539 return p_bitset->test(position);
2545 ETL_CONSTEXPR14 bit_reference& operator = (
bool b) ETL_NOEXCEPT
2547 p_bitset->set(position, b);
2554 ETL_CONSTEXPR14 bit_reference& operator = (
const bit_reference& r) ETL_NOEXCEPT
2556 p_bitset->set(position,
bool(r));
2563 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
2565 p_bitset->flip(position);
2574 return !p_bitset->test(position);
2582 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
2583 : p_bitset(ETL_NULLPTR)
2592 : p_bitset(&r_bitset)
2593 , position(position_)
2597 bitset_ext<Active_Bits, TElement, true>* p_bitset;
2607 *pbuffer = All_Clear_Element;
2616 *pbuffer = All_Clear_Element;
2625 *pbuffer = *other.pbuffer;
2634 *pbuffer = *other.pbuffer;
2645 ETL_CONSTEXPR14
bitset_ext(
unsigned long long value, element_type* pbuffer_) ETL_NOEXCEPT
2648 *pbuffer = element_type(value);
2654 ETL_CONSTEXPR14
bitset_ext(
unsigned long long value, buffer_type& buffer) ETL_NOEXCEPT
2657 *pbuffer = element_type(value);
2663 ETL_CONSTEXPR14
bitset_ext(
const char* text, element_type* pbuffer_) ETL_NOEXCEPT
2666 *pbuffer = All_Clear_Element;
2673 ETL_CONSTEXPR14
bitset_ext(
const char* text, buffer_type& buffer) ETL_NOEXCEPT
2676 *pbuffer = All_Clear_Element;
2683 ETL_CONSTEXPR14
bitset_ext(
const wchar_t* text, element_type* pbuffer_) ETL_NOEXCEPT
2686 *pbuffer = All_Clear_Element;
2693 ETL_CONSTEXPR14
bitset_ext(
const wchar_t* text, buffer_type& buffer) ETL_NOEXCEPT
2696 *pbuffer = All_Clear_Element;
2703 ETL_CONSTEXPR14
bitset_ext(
const char16_t* text, element_type* pbuffer_) ETL_NOEXCEPT
2706 *pbuffer = All_Clear_Element;
2713 ETL_CONSTEXPR14
bitset_ext(
const char16_t* text, buffer_type& buffer) ETL_NOEXCEPT
2716 *pbuffer = All_Clear_Element;
2723 ETL_CONSTEXPR14
bitset_ext(
const char32_t* text, element_type* pbuffer_) ETL_NOEXCEPT
2726 *pbuffer = All_Clear_Element;
2733 ETL_CONSTEXPR14
bitset_ext(
const char32_t* text, buffer_type& buffer) ETL_NOEXCEPT
2736 *pbuffer = All_Clear_Element;
2745 *pbuffer = *other.pbuffer;
2755 *pbuffer = All_Set_Element;
2765 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
2767 const element_type mask = element_type(element_type(1) << position);
2825 if (text == ETL_NULLPTR)
2834 string_length = etl::min(Active_Bits, string_length);
2836 element_type mask = element_type(element_type(1) << (string_length - 1U));
2838 for (
size_t i = 0U; i < string_length; ++i)
2840 if (text[i] == ETL_STR(
'1'))
2861 if (text == ETL_NULLPTR)
2870 string_length = etl::min(Active_Bits, string_length);
2872 element_type mask = element_type(element_type(1) << (string_length - 1U));
2874 for (
size_t i = 0U; i < string_length; ++i)
2876 if (text[i] == ETL_STRL(
'1'))
2897 if (text == ETL_NULLPTR)
2906 string_length = etl::min(Active_Bits, string_length);
2908 element_type mask = element_type(element_type(1) << (string_length - 1U));
2910 for (
size_t i = 0U; i < string_length; ++i)
2912 if (text[i] == ETL_STRu(
'1'))
2933 if (text == ETL_NULLPTR)
2942 string_length = etl::min(Active_Bits, string_length);
2944 element_type mask = element_type(element_type(1) << (string_length - 1U));
2946 for (
size_t i = 0U; i < string_length; ++i)
2948 if (text[i] == ETL_STRU(
'1'))
2967 template <
typename T>
2973 ETL_STATIC_ASSERT((
sizeof(T) * CHAR_BIT) >= (Number_Of_Elements * Bits_Per_Element),
"Integral type too small");
2977 const bool OK = (
sizeof(T) * CHAR_BIT) >= Bits_Per_Element;
2981 v = T(
typename etl::make_unsigned<T>::type(*pbuffer));
2990 ETL_CONSTEXPR14
unsigned long to_ulong() const ETL_NOEXCEPT
2992 return value<unsigned long>();
2998 ETL_CONSTEXPR14
unsigned long long to_ullong() const ETL_NOEXCEPT
3000 return value<unsigned long long>();
3008 *pbuffer = All_Clear_Element;
3018 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
3020 const element_type mask = element_type(element_type(1) << position);
3030 ETL_CONSTEXPR14
bool test(
size_t position)
const
3032 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow),
false);
3034 const element_type mask = element_type(element_type(1) << position);
3035 return (*pbuffer & mask) != 0U;
3043 ETL_CONSTEXPR14
size_t size() const ETL_NOEXCEPT
3051 ETL_CONSTEXPR14
size_t count() const ETL_NOEXCEPT
3059 ETL_CONSTEXPR14
bool all() const ETL_NOEXCEPT
3061 return *pbuffer == All_Set_Element;
3067 ETL_CONSTEXPR14
bool all(element_type mask)
const ETL_NOEXCEPT
3069 return *pbuffer == (All_Set_Element & mask);
3075 ETL_CONSTEXPR14
bool none() const ETL_NOEXCEPT
3077 return *pbuffer == All_Clear_Element;
3083 ETL_CONSTEXPR14
bool none(element_type mask)
const ETL_NOEXCEPT
3085 return (*pbuffer & mask) == All_Clear_Element;
3091 ETL_CONSTEXPR14
bool any() const ETL_NOEXCEPT
3099 ETL_CONSTEXPR14
bool any(element_type mask)
const ETL_NOEXCEPT
3109 *pbuffer = ~*pbuffer;
3129 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
3131 const element_type mask = element_type(element_type(1) << position);
3140 ETL_CONSTEXPR14
bool operator[] (
size_t position)
const ETL_NOEXCEPT
3142 if (position < Active_Bits)
3144 const element_type mask = element_type(element_type(1) << position);
3145 return (*pbuffer & mask) != 0U;
3154 ETL_CONSTEXPR14 bit_reference operator [] (
size_t position) ETL_NOEXCEPT
3156 return bit_reference(*
this, position);
3163 template <
typename TString = etl::
string<Active_Bits>>
3165 template <
typename TString>
3167 ETL_CONSTEXPR14 TString
to_string(
typename TString::value_type zero =
typename TString::value_type(
'0'),
3168 typename TString::value_type one =
typename TString::value_type(
'1'))
const
3172 result.resize(Active_Bits,
'\0');
3177 for (
size_t i = Active_Bits; i > 0; --i)
3179 result[Active_Bits - i] = test(i - 1) ? one : zero;
3190 ETL_CONSTEXPR14
size_t find_first(
bool state)
const ETL_NOEXCEPT
3192 return find_next(state, 0U);
3201 ETL_CONSTEXPR14
size_t find_next(
bool state,
size_t position)
const ETL_NOEXCEPT
3203 if (position < Active_Bits)
3206 size_t bit = position;
3208 element_type mask = 1U << position;
3211 if ((state && (*pbuffer != All_Clear_Element)) || (!state && (*pbuffer != All_Set_Element)))
3214 while (
bit < Active_Bits)
3217 if (((*pbuffer & mask) != 0) == state)
3237 *pbuffer &= *other.pbuffer;
3247 *pbuffer |= *other.pbuffer;
3257 *pbuffer ^= *other.pbuffer;
3267 if (shift >= Active_Bits)
3284 if (shift >= Active_Bits)
3301 return (*lhs.pbuffer == *rhs.pbuffer);
3309 element_type temp = *pbuffer;
3310 *pbuffer = *other.pbuffer;
3311 *other.pbuffer = temp;
3334 element_type* pbuffer;
3337 template <
size_t Active_Bits,
typename TElement>
3338 ETL_CONSTANT
size_t bitset_ext<Active_Bits, TElement, true>::Bits_Per_Element;
3340 template <
size_t Active_Bits,
typename TElement>
3341 ETL_CONSTANT
size_t bitset_ext<Active_Bits, TElement, true>::Number_Of_Elements;
3343 template <
size_t Active_Bits,
typename TElement>
3344 ETL_CONSTANT
size_t bitset_ext<Active_Bits, TElement, true>::Allocated_Bits;
3346 template <
size_t Active_Bits,
typename TElement>
3347 ETL_CONSTANT
typename bitset_ext<Active_Bits, TElement, true>::element_type bitset_ext<Active_Bits, TElement, true>::All_Set_Element;
3349 template <
size_t Active_Bits,
typename TElement>
3350 ETL_CONSTANT
typename bitset_ext<Active_Bits, TElement, true>::element_type bitset_ext<Active_Bits, TElement, true>::All_Clear_Element;
3352 template <
size_t Active_Bits,
typename TElement>
3353 ETL_CONSTANT
size_t bitset_ext<Active_Bits, TElement, true>::Top_Mask_Shift;
3355 template <
size_t Active_Bits,
typename TElement>
3356 ETL_CONSTANT
typename bitset_ext<Active_Bits, TElement, true>::element_type bitset_ext<Active_Bits, TElement, true>::Top_Mask;
3361 template <
size_t Active_Bits,
typename TElement>
3370 struct select_element_type
3377 typedef typename select_element_type::type element_type;
3378 typedef element_type* pointer;
3379 typedef const element_type* const_pointer;
3382 static ETL_CONSTANT
size_t Number_Of_Elements = (Active_Bits % Bits_Per_Element == 0) ? Active_Bits / Bits_Per_Element : Active_Bits / Bits_Per_Element + 1;
3383 static ETL_CONSTANT
size_t Allocated_Bits = Number_Of_Elements * Bits_Per_Element;
3384 static ETL_CONSTANT
size_t Top_Mask_Shift = ((Bits_Per_Element - (Allocated_Bits - Active_Bits)) % Bits_Per_Element);
3387 static ETL_CONSTANT element_type Top_Mask = element_type(Top_Mask_Shift == 0 ? All_Set_Element : ~(All_Set_Element << Top_Mask_Shift));
3389 static ETL_CONSTANT
size_t ALLOCATED_BITS = Allocated_Bits;
3408 ETL_CONSTEXPR14 bit_reference(
const bit_reference& other) ETL_NOEXCEPT
3409 : p_bitset(other.p_bitset)
3410 , position(other.position)
3417 ETL_CONSTEXPR14
operator bool() const ETL_NOEXCEPT
3419 return p_bitset->test(position);
3425 ETL_CONSTEXPR14 bit_reference& operator = (
bool b) ETL_NOEXCEPT
3427 p_bitset->set(position, b);
3434 ETL_CONSTEXPR14 bit_reference& operator = (
const bit_reference& r) ETL_NOEXCEPT
3436 p_bitset->set(position,
bool(r));
3443 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
3445 p_bitset->flip(position);
3454 return !p_bitset->test(position);
3462 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
3463 : p_bitset(ETL_NULLPTR)
3472 : p_bitset(&r_bitset)
3473 , position(position_)
3477 bitset_ext<Active_Bits, TElement, false>* p_bitset;
3494 : pbuffer(buffer.data())
3505 etl::copy_n(other.pbuffer, Number_Of_Elements, pbuffer);
3512 : pbuffer(buffer.data())
3514 etl::copy_n(other.pbuffer, Number_Of_Elements, pbuffer);
3525 ETL_CONSTEXPR14
bitset_ext(
unsigned long long value, element_type* pbuffer_) ETL_NOEXCEPT
3529 clear_unused_bits_in_msb();
3536 : pbuffer(buffer.data())
3539 clear_unused_bits_in_msb();
3545 ETL_CONSTEXPR14
bitset_ext(
const char* text, element_type* pbuffer_) ETL_NOEXCEPT
3548 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3549 clear_unused_bits_in_msb();
3556 : pbuffer(buffer.data())
3558 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3559 clear_unused_bits_in_msb();
3565 ETL_CONSTEXPR14
bitset_ext(
const wchar_t* text, element_type* pbuffer_) ETL_NOEXCEPT
3568 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3569 clear_unused_bits_in_msb();
3576 : pbuffer(buffer.data())
3578 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3579 clear_unused_bits_in_msb();
3585 ETL_CONSTEXPR14
bitset_ext(
const char16_t* text, element_type* pbuffer_) ETL_NOEXCEPT
3588 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3589 clear_unused_bits_in_msb();
3596 : pbuffer(buffer.data())
3598 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3599 clear_unused_bits_in_msb();
3605 ETL_CONSTEXPR14
bitset_ext(
const char32_t* text, element_type* pbuffer_) ETL_NOEXCEPT
3608 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3609 clear_unused_bits_in_msb();
3616 : pbuffer(buffer.data())
3618 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3619 clear_unused_bits_in_msb();
3627 etl::copy_n(other.pbuffer, Number_Of_Elements, pbuffer);
3637 etl::fill_n(pbuffer, Number_Of_Elements, All_Set_Element);
3638 clear_unused_bits_in_msb();
3648 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
3650 ibitset.
set(pbuffer, Number_Of_Elements, position, value);
3651 clear_unused_bits_in_msb();
3661 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3671 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3681 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3691 ibitset.
set(pbuffer, Number_Of_Elements, Active_Bits, text);
3739 template <
typename T>
3745 ETL_STATIC_ASSERT((
sizeof(T) * CHAR_BIT) >= (Number_Of_Elements * Bits_Per_Element),
"Type too small");
3747 return ibitset.template value<T>(pbuffer, Number_Of_Elements);
3753 ETL_CONSTEXPR14
unsigned long to_ulong() const ETL_NOEXCEPT
3755 return value<unsigned long>();
3761 ETL_CONSTEXPR14
unsigned long long to_ullong() const ETL_NOEXCEPT
3763 return value<unsigned long long>();
3770 etl::fill_n(pbuffer, Number_Of_Elements, All_Clear_Element);
3780 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
3791 ETL_CONSTEXPR14
bool test(
size_t position)
const
3793 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow),
false);
3795 return ibitset.
test(pbuffer, Number_Of_Elements, position);
3801 ETL_CONSTEXPR14
size_t size() const ETL_NOEXCEPT
3809 ETL_CONSTEXPR14
size_t count() const ETL_NOEXCEPT
3817 ETL_CONSTEXPR14
bool all() const ETL_NOEXCEPT
3819 return ibitset.all(pbuffer, Number_Of_Elements, Top_Mask);
3825 ETL_CONSTEXPR14
bool none() const ETL_NOEXCEPT
3833 ETL_CONSTEXPR14
bool any() const ETL_NOEXCEPT
3844 clear_unused_bits_in_msb();
3854 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
3856 ibitset.
flip(pbuffer, Number_Of_Elements, position);
3864 ETL_CONSTEXPR14
bool operator[] (
size_t position)
const ETL_NOEXCEPT
3866 return ibitset.
test(pbuffer, Number_Of_Elements, position);
3872 ETL_CONSTEXPR14 bit_reference operator [] (
size_t position) ETL_NOEXCEPT
3874 return bit_reference(*
this, position);
3881 template <
typename TString = etl::
string<Active_Bits>>
3883 template <
typename TString>
3885 ETL_CONSTEXPR14 TString
to_string(
typename TString::value_type zero =
typename TString::value_type(
'0'),
3886 typename TString::value_type one =
typename TString::value_type(
'1'))
const
3888 return ibitset.template to_string<TString>(pbuffer, Number_Of_Elements, Active_Bits, zero, one);
3896 ETL_CONSTEXPR14
size_t find_first(
bool state)
const ETL_NOEXCEPT
3898 return ibitset.
find_next(pbuffer, Number_Of_Elements, Active_Bits, state, 0);
3907 ETL_CONSTEXPR14
size_t find_next(
bool state,
size_t position)
const ETL_NOEXCEPT
3909 return ibitset.
find_next(pbuffer, Number_Of_Elements, Active_Bits, state, position);
3917 ibitset.and_equals(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3927 ibitset.or_equals(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3937 ibitset.xor_equals(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3947 if (shift >= Active_Bits)
3953 ibitset.shift_left_equals(pbuffer, Number_Of_Elements, shift);
3954 clear_unused_bits_in_msb();
3965 if (shift >= Active_Bits)
3971 ibitset.shift_right_equals(pbuffer, Number_Of_Elements, shift);
3982 return etl::equal(lhs.pbuffer,
3983 lhs.pbuffer + lhs.Number_Of_Elements,
3992 ibitset.
swap(pbuffer, other.pbuffer, Number_Of_Elements);
4001 return span_type(pbuffer, Number_Of_Elements);
4018 ETL_CONSTEXPR14
void clear_unused_bits_in_msb() ETL_NOEXCEPT
4020 pbuffer[Number_Of_Elements - 1U] &= Top_Mask;
4024 element_type* pbuffer;
4027 template <
size_t Active_Bits,
typename TElement>
4028 ETL_CONSTANT
size_t bitset_ext<Active_Bits, TElement, false>::Bits_Per_Element;
4030 template <
size_t Active_Bits,
typename TElement>
4031 ETL_CONSTANT
size_t bitset_ext<Active_Bits, TElement, false>::Number_Of_Elements;
4033 template <
size_t Active_Bits,
typename TElement>
4034 ETL_CONSTANT
size_t bitset_ext<Active_Bits, TElement, false>::Allocated_Bits;
4036 template <
size_t Active_Bits,
typename TElement>
4037 ETL_CONSTANT
typename bitset_ext<Active_Bits, TElement, false>::element_type bitset_ext<Active_Bits, TElement, false>::All_Set_Element;
4039 template <
size_t Active_Bits,
typename TElement>
4040 ETL_CONSTANT
typename bitset_ext<Active_Bits, TElement, false>::element_type bitset_ext<Active_Bits, TElement, false>::All_Clear_Element;
4042 template <
size_t Active_Bits,
typename TElement>
4043 ETL_CONSTANT
size_t bitset_ext<Active_Bits, TElement, false>::Top_Mask_Shift;
4045 template <
size_t Active_Bits,
typename TElement>
4046 ETL_CONSTANT
typename bitset_ext<Active_Bits, TElement, false>::element_type bitset_ext<Active_Bits, TElement, false>::Top_Mask;
4052 template<
size_t Active_Bits,
typename TElement,
bool IsSingleElement>
4055 return !(lhs == rhs);
4062template <
size_t Active_Bits,
typename TElement,
bool IsSingleElement>
ETL_CONSTEXPR14 void swap(etl::bitset< Active_Bits, TElement, IsSingleElement > &lhs, etl::bitset< Active_Bits, TElement, IsSingleElement > &rhs) ETL_NOEXCEPT
swap
Definition: bitset_new.h:2455
The specialisation that uses an array of the default element type.
Definition: bitset_new.h:1721
ETL_CONSTEXPR14 bitset< Active_Bits, TElement, false > & flip() ETL_NOEXCEPT
Flip all of the bits.
Definition: bitset_new.h:2124
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value, T >::type value() const ETL_NOEXCEPT
Get as an integral value.
Definition: bitset_new.h:2025
Definition: bitset_new.h:851
ETL_CONSTEXPR14 bitset< Active_Bits, TElement, true > & flip() ETL_NOEXCEPT
Flip all of the bits.
Definition: bitset_new.h:1393
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value, T >::type value() const ETL_NOEXCEPT
Get as an integral value.
Definition: bitset_new.h:1256
The specialisation that uses an array of the default element type.
Definition: bitset_new.h:3363
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value, T >::type value() const ETL_NOEXCEPT
Get as an integral value.
Definition: bitset_new.h:3742
Definition: bitset_new.h:2494
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value, T >::type value() const ETL_NOEXCEPT
Get as an integral value.
Definition: bitset_new.h:2970
Definition: bitset_new.h:2469
bool operator~() const
Return the logical inverse of the bit.
Definition: bitset_legacy.h:225
bit_reference & operator=(bool b)
Assignment operator.
Definition: bitset_legacy.h:198
bit_reference & flip()
Flip the bit.
Definition: bitset_legacy.h:216
Definition: binary.h:2211
Definition: binary.h:2233
A templated set implementation that uses a fixed size buffer.
Definition: set.h:2502
Span - Fixed Extent.
Definition: span.h:62
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value &&etl::is_unsigned< T >::value &&(etl::integral_limits< T >::bits==16U), uint_least8_t >::type count_bits(T value)
Definition: binary.h:956
ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t number_of_elements, size_t position) const ETL_NOEXCEPT
Definition: bitset_new.h:167
ibitset & set()
Set all bits.
Definition: bitset_legacy.h:312
ibitset & reset()
Resets the bitset.
Definition: bitset_legacy.h:513
bitset< MaxN > & operator&=(const bitset< MaxN > &other)
operator &=
Definition: bitset_legacy.h:1367
size_t find_first(bool state) const
Definition: bitset_legacy.h:653
size_t find_next(bool state, size_t position) const
Definition: bitset_legacy.h:664
ibitset & initialise(unsigned long long value)
Initialise from an unsigned long long.
Definition: bitset_legacy.h:983
ETL_CONSTEXPR14 void flip(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Flip all of the bits.
Definition: bitset_new.h:427
bool any() const
Are any of the bits set?
Definition: bitset_legacy.h:627
ETL_CONSTEXPR14 TString to_string(const_pointer pbuffer, size_t number_of_elements, size_t active_bits, typename TString::value_type zero, typename TString::value_type one) const
Returns a string representing the bitset.
Definition: bitset_new.h:572
friend bool operator==(const bitset< MaxN > &lhs, const bitset< MaxN > &rhs)
operator ==
Definition: bitset_legacy.h:1448
ETL_CONSTEXPR14 size_t find_next(const_pointer pbuffer, size_t number_of_elements, size_t total_bits, bool state, size_t position) const ETL_NOEXCEPT
Definition: bitset_new.h:521
ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t number_of_elements) const ETL_NOEXCEPT
Count the number of bits set.
Definition: bitset_new.h:151
bitset< MaxN > & flip()
Flip all of the bits.
Definition: bitset_legacy.h:1312
ibitset(size_t nbits_, size_t size_, element_type *pdata_)
Constructor.
Definition: bitset_legacy.h:1034
ETL_CONSTEXPR14 void swap(pointer pbuffer1, pointer pbuffer2, size_t number_of_elements)
Swap bitset buffers.
Definition: bitset_new.h:798
ETL_CONSTEXPR14 void or_equals(pointer pbuffer, const_pointer pbuffer2, size_t number_of_elements) ETL_NOEXCEPT
or_equals
Definition: bitset_new.h:745
void swap(ibitset &other)
swap
Definition: bitset_legacy.h:953
bitset< MaxN > & reset()
Reset all of the bits.
Definition: bitset_legacy.h:1294
etl::enable_if< etl::is_integral< T >::value, T >::type value() const
Put to a value.
Definition: bitset_legacy.h:1283
ETL_CONSTEXPR14 void and_equals(pointer pbuffer, const_pointer pbuffer2, size_t number_of_elements) ETL_NOEXCEPT
and_equals
Definition: bitset_new.h:734
size_t count() const
Count the number of bits set.
Definition: bitset_legacy.h:265
TString to_string(typename TString::value_type zero=typename TString::value_type('0'), typename TString::value_type one=typename TString::value_type('1')) const
Returns a string representing the bitset.
Definition: bitset_legacy.h:1335
ETL_CONSTEXPR14 void xor_equals(pointer pbuffer, const_pointer pbuffer2, size_t number_of_elements) ETL_NOEXCEPT
xor_equals
Definition: bitset_new.h:756
ETL_CONSTEXPR14 void set(pointer pbuffer, size_t number_of_elements, size_t position, bool value=true) ETL_NOEXCEPT
Set the bit at the position.
Definition: bitset_new.h:190
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value, T >::type value(const_pointer pbuffer, size_t number_of_elements) const ETL_NOEXCEPT
Get as a value.
Definition: bitset_new.h:378
ibitset & flip()
Flip all of the bits.
Definition: bitset_legacy.h:555
ETL_CONSTEXPR14 void reset(pointer pbuffer, size_t number_of_elements, size_t position) ETL_NOEXCEPT
Reset the bit at the position.
Definition: bitset_new.h:401
bitset< MaxN > & operator<<=(size_t shift)
operator <<=
Definition: bitset_legacy.h:1418
bitset< MaxN > operator<<(size_t shift) const
operator <<
Definition: bitset_legacy.h:1406
unsigned long to_ulong() const
Put to a unsigned long.
Definition: bitset_legacy.h:497
bool operator[](size_t position) const
Read [] operator.
Definition: bitset_legacy.h:729
unsigned long long to_ullong() const
Put to a unsigned long long.
Definition: bitset_legacy.h:505
bitset< MaxN > & operator|=(const bitset< MaxN > &other)
operator |=
Definition: bitset_legacy.h:1376
bitset()
Default constructor.
Definition: bitset_legacy.h:1116
bitset< MaxN > operator~() const
operator ~
Definition: bitset_legacy.h:1394
ETL_CONSTEXPR14 void initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
Initialise from an unsigned long long.
Definition: bitset_new.h:767
bitset< MaxN > operator>>(size_t shift) const
operator >>
Definition: bitset_legacy.h:1427
ETL_CONSTEXPR14 void shift_left_equals(pointer pbuffer, size_t number_of_elements, size_t shift) ETL_NOEXCEPT
shift_left_equals
Definition: bitset_new.h:596
ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t number_of_elements) const ETL_NOEXCEPT
Are none of the bits set?
Definition: bitset_new.h:492
ibitset & from_string(const char *text)
Set from a string.
Definition: bitset_legacy.h:362
bitset< MaxN > & operator=(const bitset< MaxN > &other)
operator =
Definition: bitset_legacy.h:1354
bitset< MaxN > & operator^=(const bitset< MaxN > &other)
operator ^=
Definition: bitset_legacy.h:1385
ETL_CONSTEXPR14 size_t find_first(const_pointer pbuffer, size_t number_of_elements, size_t total_bits, bool state) const ETL_NOEXCEPT
Definition: bitset_new.h:510
bool none() const
Are none of the bits set?
Definition: bitset_legacy.h:635
bool test(size_t position) const
Definition: bitset_legacy.h:281
size_t size() const
The number of bits in the bitset.
Definition: bitset_legacy.h:257
ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char *text) ETL_NOEXCEPT
Set from a string.
Definition: bitset_new.h:223
ETL_CONSTEXPR14 void shift_right_equals(pointer pbuffer, size_t number_of_elements, size_t shift) ETL_NOEXCEPT
shift_right_equals
Definition: bitset_new.h:665
bitset< MaxN > & set()
Set all of the bits.
Definition: bitset_legacy.h:1179
bitset< MaxN > & operator>>=(size_t shift)
operator >>=
Definition: bitset_legacy.h:1439
bitset< MaxN > & from_string(const char *text)
Set from a string.
Definition: bitset_legacy.h:1241
Definition: bitset_legacy.h:1102
Definition: bitset_legacy.h:85
Definition: bitset_new.h:136
Definition: bitset_legacy.h:127
Definition: bitset_new.h:107
Definition: bitset_legacy.h:141
Definition: exception.h:47
Definition: integral_limits.h:468
enable_if
Definition: type_traits_generator.h:1191
is_integral
Definition: type_traits_generator.h:1001
make_unsigned
Definition: type_traits_generator.h:1181
bitset_ext
Definition: absolute.h:38
etl::byte operator~(etl::byte b)
Not.
Definition: byte.h:313
etl::byte & operator^=(etl::byte &lhs, etl::byte rhs)
Exclusive or equals.
Definition: byte.h:305
etl::enable_if< etl::is_integral< TInteger >::value, etl::byte & >::type operator<<=(etl::byte &b, TInteger shift)
Shift left equals.
Definition: byte.h:243
etl::byte operator|(etl::byte lhs, etl::byte rhs)
Or.
Definition: byte.h:265
etl::byte & operator|=(etl::byte &lhs, etl::byte rhs)
Or equals.
Definition: byte.h:289
etl::byte operator&(etl::byte lhs, etl::byte rhs)
And.
Definition: byte.h:273
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:645
etl::enable_if<!etl::is_same< T, etl::istring >::value &&!etl::is_same< T, etl::string_view >::value, constetl::istring & >::type to_string(const T value, etl::istring &str, bool append=false)
Definition: to_string.h:50
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition: array.h:621
etl::byte operator^(etl::byte lhs, etl::byte rhs)
Exclusive Or.
Definition: byte.h:281
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:633
etl::enable_if< etl::is_integral< TInteger >::value, etl::byte & >::type operator>>=(etl::byte &b, TInteger shift)
Shift right equals.
Definition: byte.h:255
etl::byte & operator&=(etl::byte &lhs, etl::byte rhs)
And equals.
Definition: byte.h:297
ETL_CONSTEXPR size_t strlen(const T *t)
Alternative strlen for all character types.
Definition: char_traits.h:267
Definition: bitset_new.h:81