MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore::Bitset::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::Bitset::SetBitIter:

Public Member Functions

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

Public Attributes

const Bitsetbs
 
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 320 of file bitset.hpp.

Member Function Documentation

◆ next()

Optional< size_t > mtcore::Bitset::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 329 of file bitset.hpp.

329 {
330 while (!curMask && ++curIndex < bs.bits.len) {
331 curMask = bs.bits[curIndex];
332 }
333 if (curIndex >= bs.bits.len) {
334 return nullopt;
335 }
336 mtdefer { curMask ^= static_cast<u64>(0x1) << std::countr_zero(curMask); };
337 const size_t res = 64 * curIndex + std::countr_zero(curMask);
338 return res;
339 }
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 Bitset& mtcore::Bitset::SetBitIter::bs

Definition at line 321 of file bitset.hpp.

◆ curIndex

size_t mtcore::Bitset::SetBitIter::curIndex

Definition at line 323 of file bitset.hpp.

◆ curMask

u64 mtcore::Bitset::SetBitIter::curMask

Definition at line 322 of file bitset.hpp.


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