MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore::Bitset2D::SetBitIter Struct Reference

Simple bit set iterator that uses next() iteration to return the indices of all set bits. More...

#include <bitset.hpp>

Collaboration diagram for mtcore::Bitset2D::SetBitIter:

Public Member Functions

Optional< std::tuple< size_t, size_t > > next ()
 Gets the next set bit position (if there is one)
 

Public Attributes

const Bitset2Dbs
 
u64 curMask
 
size_t curIndex
 

Detailed Description

Simple bit set iterator that uses next() iteration to return the indices of all set bits.

Definition at line 745 of file bitset.hpp.

Member Function Documentation

◆ next()

Optional< std::tuple< size_t, size_t > > mtcore::Bitset2D::SetBitIter::next ( )
inline

Gets the next set bit position (if there is one)

Returns
the next set position or an empty Optional if there is none

Definition at line 754 of file bitset.hpp.

754 {
755 while (!curMask && ++curIndex < bs.underlying.bits.len) {
756 curMask = bs.underlying.bits[curIndex];
757 }
758 if (curIndex >= bs.underlying.bits.len) {
759 return nullopt;
760 }
761 mtdefer { curMask ^= static_cast<u64>(0x1) << std::countr_zero(curMask); };
762 const size_t pos = 64 * curIndex + std::countr_zero(curMask);
763 size_t row = pos / bs.width;
764 size_t col = pos % bs.width;
765 return std::tuple{row, col};
766 }
constexpr auto nullopt
Placeholder value for an empty Optional.
Definition optional.hpp:409
#define mtdefer
Defer statement that will mtdefer execution until the scope is left, at which point the code will run...
uint64_t u64
Alias for 64-bit unsigned ints.

Member Data Documentation

◆ bs

const Bitset2D& mtcore::Bitset2D::SetBitIter::bs

Definition at line 746 of file bitset.hpp.

◆ curIndex

size_t mtcore::Bitset2D::SetBitIter::curIndex

Definition at line 748 of file bitset.hpp.

◆ curMask

u64 mtcore::Bitset2D::SetBitIter::curMask

Definition at line 747 of file bitset.hpp.


The documentation for this struct was generated from the following file: