27#include <dynamic_bitset.h>
33#if defined( _MSC_VER )
38typedef SSIZE_T ssize_t;
54 bool operator*()
const {
return m_set->test( m_pos ); }
85 bool operator*()
const {
return m_set->test( m_pos ); }
111 BASE_SET(
size_t size = 64 ) : sul::dynamic_bitset<uint64_t>( size ) {}
119 sul::dynamic_bitset<uint64_t>::resize( pos + 1 );
121 sul::dynamic_bitset<uint64_t>::set(pos);
129 sul::dynamic_bitset<uint64_t>::resize( pos + 1 );
131 sul::dynamic_bitset<uint64_t>::set(pos, value);
138 sul::dynamic_bitset<uint64_t>::set();
146 sul::dynamic_bitset<uint64_t>::resize( pos + 1 );
148 sul::dynamic_bitset<uint64_t>::reset(pos);
155 sul::dynamic_bitset<uint64_t>::reset();
163 sul::dynamic_bitset<uint64_t>::resize( pos + 1 );
165 sul::dynamic_bitset<uint64_t>::flip(pos);
172 sul::dynamic_bitset<uint64_t>::flip();
189 sul::dynamic_bitset<uint64_t>::operator&=(other);
196 sul::dynamic_bitset<uint64_t>::operator|=(other);
203 sul::dynamic_bitset<uint64_t>::operator^=(other);
226 int bit_count = size();
228 for(
int bit=0; bit<bit_count; ++bit )
234 else if( !( bit % 4 ) )
238 ret += (*this)[bit] ?
'1' :
'0';
242 return std::string( ret.rbegin(), ret.rend() );
252 static const char hex[] =
"0123456789abcdef";
254 size_t nibble_count = ( size() + 3 ) / 4;
256 for(
size_t nibble = 0; nibble < nibble_count; ++nibble )
258 unsigned int ndx = 0;
261 for(
size_t nibble_bit = 0; nibble_bit < 4; ++nibble_bit )
263 size_t nibble_pos = nibble_bit + ( nibble * 4 );
266 if( nibble_pos >= size() )
269 if( ( *
this )[nibble_pos] )
270 ndx |= ( 1 << nibble_bit );
273 if( nibble && !( nibble % 8 ) )
282 return std::string( ret.rbegin(), ret.rend() );
296 return ParseHex( str.c_str(), str.length() );
312 const char* rstart = aStart + aCount - 1;
313 const char* rend = aStart - 1;
315 const int bitcount = size();
319 while( rstart > rend )
328 if( cc >=
'0' && cc <=
'9' )
330 else if( cc >=
'a' && cc <=
'f' )
331 nibble = cc -
'a' + 10;
332 else if( cc >=
'A' && cc <=
'F' )
333 nibble = cc -
'A' + 10;
337 int bit = nibble_ndx * 4;
339 for(
int ndx=0; bit<bitcount && ndx<4; ++bit, ++ndx )
340 if( nibble & (1<<ndx) )
343 if( bit >= bitcount )
349 int byte_count = aStart + aCount - 1 - rstart;
351 assert( byte_count >= 0 );
370 m_baseSet( baseSet ), m_index( index )
372 advance_to_next_set_bit();
380 advance_to_next_set_bit();
391 while( m_index < m_baseSet.size() && !m_baseSet.test( m_index ) )
410 m_baseSet( baseSet ), m_index( index )
412 advance_to_previous_set_bit();
420 advance_to_previous_set_bit();
426 return m_index != other.
m_index;
431 return m_index == other.
m_index;
437 while( m_index >= 0 && !m_baseSet.test( m_index ) )
491 for(
const auto& bit : bs )
492 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