30#if defined( __GNUC__ ) && !defined( __clang__ )
31#pragma GCC diagnostic push
32#pragma GCC diagnostic ignored "-Wunused-function"
34#include <dynamic_bitset.h>
35#if defined( __GNUC__ ) && !defined( __clang__ )
36#pragma GCC diagnostic pop
43#if defined( _MSC_VER )
48typedef SSIZE_T ssize_t;
121 BASE_SET(
size_t size = 64 ) : sul::dynamic_bitset<uint64_t>( size ) {}
129 sul::dynamic_bitset<uint64_t>::resize( pos + 1 );
131 sul::dynamic_bitset<uint64_t>::set(pos);
139 sul::dynamic_bitset<uint64_t>::resize( pos + 1 );
141 sul::dynamic_bitset<uint64_t>::set(pos, value);
148 sul::dynamic_bitset<uint64_t>::set();
156 sul::dynamic_bitset<uint64_t>::resize( pos + 1 );
158 sul::dynamic_bitset<uint64_t>::reset(pos);
165 sul::dynamic_bitset<uint64_t>::reset();
173 sul::dynamic_bitset<uint64_t>::resize( pos + 1 );
175 sul::dynamic_bitset<uint64_t>::flip(pos);
182 sul::dynamic_bitset<uint64_t>::flip();
199 size_t my_size = size();
200 size_t other_size = other.size();
202 if( my_size == other_size )
204 sul::dynamic_bitset<uint64_t>::operator&=(other);
206 else if( my_size < other_size )
208 sul::dynamic_bitset<uint64_t>::resize( other_size );
209 sul::dynamic_bitset<uint64_t>::operator&=( other );
214 tmp.resize( my_size );
215 sul::dynamic_bitset<uint64_t>::operator&=( tmp );
224 size_t my_size = size();
225 size_t other_size = other.size();
227 if( my_size == other_size )
229 sul::dynamic_bitset<uint64_t>::operator|=(other);
231 else if( my_size < other_size )
233 sul::dynamic_bitset<uint64_t>::resize( other_size );
234 sul::dynamic_bitset<uint64_t>::operator|=( other );
239 tmp.resize( my_size );
240 sul::dynamic_bitset<uint64_t>::operator|=( tmp );
249 size_t my_size = size();
250 size_t other_size = other.size();
252 if( my_size == other_size )
254 sul::dynamic_bitset<uint64_t>::operator^=(other);
256 else if( my_size < other_size )
258 sul::dynamic_bitset<uint64_t>::resize( other_size );
259 sul::dynamic_bitset<uint64_t>::operator^=( other );
264 tmp.resize( my_size );
265 sul::dynamic_bitset<uint64_t>::operator^=( tmp );
290 int bit_count =
static_cast<int>( size() );
292 for(
int bit=0; bit<bit_count; ++bit )
298 else if( !( bit % 4 ) )
302 ret += (*this)[bit] ?
'1' :
'0';
306 return std::string( ret.rbegin(), ret.rend() );
316 static const char hex[] =
"0123456789abcdef";
318 size_t nibble_count = ( size() + 3 ) / 4;
320 for(
size_t nibble = 0; nibble < nibble_count; ++nibble )
322 unsigned int ndx = 0;
325 for(
size_t nibble_bit = 0; nibble_bit < 4; ++nibble_bit )
327 size_t nibble_pos = nibble_bit + ( nibble * 4 );
330 if( nibble_pos >= size() )
333 if( ( *
this )[nibble_pos] )
334 ndx |= ( 1 << nibble_bit );
337 if( nibble && !( nibble % 8 ) )
346 return std::string( ret.rbegin(), ret.rend() );
360 return ParseHex( str.c_str(),
static_cast<int>( str.length() ) );
376 const char* rstart = aStart + aCount - 1;
377 const char* rend = aStart - 1;
379 const int bitcount =
static_cast<const int>( size() );
383 while( rstart > rend )
392 if( cc >=
'0' && cc <=
'9' )
394 else if( cc >=
'a' && cc <=
'f' )
395 nibble = cc -
'a' + 10;
396 else if( cc >=
'A' && cc <=
'F' )
397 nibble = cc -
'A' + 10;
401 int bit = nibble_ndx * 4;
403 for(
int ndx=0; bit<bitcount && ndx<4; ++bit, ++ndx )
404 if( nibble & (1<<ndx) )
407 if( bit >= bitcount )
413 int byte_count =
static_cast<int>( aStart + aCount - 1 - rstart );
415 assert( byte_count >= 0 );
555 for(
const auto& bit : bs )
556 hashVal = hashVal * 31 + std::hash<int>()( bit );
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
BASE_SET operator|(const BASE_SET &lhs, const BASE_SET &rhs)
BASE_SET operator^(const BASE_SET &lhs, const BASE_SET &rhs)
BASE_SET operator&(const BASE_SET &lhs, const BASE_SET &rhs)
auto operator<=>(const const_iterator &) const =default
std::random_access_iterator_tag iterator_category
const_iterator operator+(difference_type n) const
const_iterator(const BASE_SET *set, size_t pos)
difference_type operator-(const const_iterator &other) const
std::ptrdiff_t difference_type
const_iterator & operator++()
auto operator<=>(const iterator &) const =default
difference_type operator-(const iterator &other) const
iterator(BASE_SET *set, size_t pos)
std::ptrdiff_t difference_type
std::random_access_iterator_tag iterator_category
iterator operator+(difference_type n) const
set_bits_iterator & operator++()
void advance_to_next_set_bit()
std::forward_iterator_tag iterator_category
bool operator!=(const set_bits_iterator &other) const
bool operator==(const set_bits_iterator &other) const
const BASE_SET & m_baseSet
std::ptrdiff_t difference_type
set_bits_iterator(const BASE_SET &baseSet, size_t index)
std::ptrdiff_t difference_type
const ssize_t & reference
void advance_to_previous_set_bit()
const BASE_SET & m_baseSet
set_bits_reverse_iterator & operator++()
set_bits_reverse_iterator(const BASE_SET &baseSet, ssize_t index)
bool operator==(const set_bits_reverse_iterator &other) const
ssize_t operator*() const
std::bidirectional_iterator_tag iterator_category
bool operator!=(const set_bits_reverse_iterator &other) const
std::string FmtBin() const
Return a binary string showing contents of this set.
set_bits_reverse_iterator set_bits_rbegin() const
int ParseHex(const std::string &str)
Convert the output of FmtHex() and replaces this set's values with those given in the input string.
const_iterator end() const
bool operator<(const BASE_SET &other) const
int ParseHex(const char *aStart, int aCount)
Convert the output of FmtHex() and replaces this set's values with those given in the input string.
set_bits_iterator set_bits_end() const
BASE_SET & reset(size_t pos)
BASE_SET & operator^=(const BASE_SET &other)
BASE_SET & flip(size_t pos)
BASE_SET & set(size_t pos, bool value)
BASE_SET operator~() const
set_bits_reverse_iterator set_bits_rend() const
int compare(const BASE_SET &other) const
BASE_SET & set(size_t pos)
const_iterator begin() const
set_bits_iterator set_bits_begin() const
std::string FmtHex() const
Return a hex string showing contents of this set.
BASE_SET & operator|=(const BASE_SET &other)
BASE_SET & operator&=(const BASE_SET &other)
int lexicographical_compare_three_way(Container1Iter aC1_first, Container1Iter aC1_last, Container2Iter aC2_first, Container2Iter aC2_last)
Compares two containers lexicographically.
size_t operator()(const BASE_SET &bs) const
wxString result
Test unit parsing edge cases and error handling.