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 size_t my_size = size();
190 size_t other_size = other.size();
192 if( my_size == other_size )
194 sul::dynamic_bitset<uint64_t>::operator&=(other);
196 else if( my_size < other_size )
198 sul::dynamic_bitset<uint64_t>::resize( other_size );
199 sul::dynamic_bitset<uint64_t>::operator&=( other );
204 tmp.resize( my_size );
205 sul::dynamic_bitset<uint64_t>::operator&=( tmp );
214 size_t my_size = size();
215 size_t other_size = other.size();
217 if( my_size == other_size )
219 sul::dynamic_bitset<uint64_t>::operator|=(other);
221 else if( my_size < other_size )
223 sul::dynamic_bitset<uint64_t>::resize( other_size );
224 sul::dynamic_bitset<uint64_t>::operator|=( other );
229 tmp.resize( my_size );
230 sul::dynamic_bitset<uint64_t>::operator|=( tmp );
239 size_t my_size = size();
240 size_t other_size = other.size();
242 if( my_size == other_size )
244 sul::dynamic_bitset<uint64_t>::operator^=(other);
246 else if( my_size < other_size )
248 sul::dynamic_bitset<uint64_t>::resize( other_size );
249 sul::dynamic_bitset<uint64_t>::operator^=( other );
254 tmp.resize( my_size );
255 sul::dynamic_bitset<uint64_t>::operator^=( tmp );
280 int bit_count = size();
282 for(
int bit=0; bit<bit_count; ++bit )
288 else if( !( bit % 4 ) )
292 ret += (*this)[bit] ?
'1' :
'0';
296 return std::string( ret.rbegin(), ret.rend() );
306 static const char hex[] =
"0123456789abcdef";
308 size_t nibble_count = ( size() + 3 ) / 4;
310 for(
size_t nibble = 0; nibble < nibble_count; ++nibble )
312 unsigned int ndx = 0;
315 for(
size_t nibble_bit = 0; nibble_bit < 4; ++nibble_bit )
317 size_t nibble_pos = nibble_bit + ( nibble * 4 );
320 if( nibble_pos >= size() )
323 if( ( *
this )[nibble_pos] )
324 ndx |= ( 1 << nibble_bit );
327 if( nibble && !( nibble % 8 ) )
336 return std::string( ret.rbegin(), ret.rend() );
350 return ParseHex( str.c_str(), str.length() );
366 const char* rstart = aStart + aCount - 1;
367 const char* rend = aStart - 1;
369 const int bitcount = size();
373 while( rstart > rend )
382 if( cc >=
'0' && cc <=
'9' )
384 else if( cc >=
'a' && cc <=
'f' )
385 nibble = cc -
'a' + 10;
386 else if( cc >=
'A' && cc <=
'F' )
387 nibble = cc -
'A' + 10;
391 int bit = nibble_ndx * 4;
393 for(
int ndx=0; bit<bitcount && ndx<4; ++bit, ++ndx )
394 if( nibble & (1<<ndx) )
397 if( bit >= bitcount )
403 int byte_count = aStart + aCount - 1 - rstart;
405 assert( byte_count >= 0 );
424 m_baseSet( baseSet ), m_index( index )
426 advance_to_next_set_bit();
434 advance_to_next_set_bit();
445 while( m_index < m_baseSet.size() && !m_baseSet.test( m_index ) )
464 m_baseSet( baseSet ), m_index( index )
466 advance_to_previous_set_bit();
474 advance_to_previous_set_bit();
480 return m_index != other.
m_index;
485 return m_index == other.
m_index;
491 while( m_index >= 0 && !m_baseSet.test( m_index ) )
545 for(
const auto& bit : bs )
546 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