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

Public Member Functions

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

Public Attributes

const BitsetFixedbs
 
u64 curMask
 
size_t curIndex
 

Detailed Description

template<size_t NumBits = 64>
struct mtcore::BitsetFixed< NumBits >::SetBitIter

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

Definition at line 999 of file bitset.hpp.

Member Function Documentation

◆ next()

template<size_t NumBits = 64>
Optional< size_t > mtcore::BitsetFixed< NumBits >::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 1008 of file bitset.hpp.

1008 {
1009 while (!curMask && ++curIndex < bs.bits.len) {
1010 curMask = bs.bits[curIndex];
1011 }
1012 if (curIndex >= bs.bits.len) {
1013 return nullopt;
1014 }
1015 mtdefer { curMask ^= static_cast<u64>(0x1) << std::countr_zero(curMask); };
1016 const size_t res = 64 * curIndex + std::countr_zero(curMask);
1017 return res;
1018 }
Represents a bitset with dynamically allocated memory (using an mtcore allocator) Allows operating on...
Definition bitset.hpp:826

Member Data Documentation

◆ bs

template<size_t NumBits = 64>
const BitsetFixed& mtcore::BitsetFixed< NumBits >::SetBitIter::bs

Definition at line 1000 of file bitset.hpp.

◆ curIndex

template<size_t NumBits = 64>
size_t mtcore::BitsetFixed< NumBits >::SetBitIter::curIndex

Definition at line 1002 of file bitset.hpp.

◆ curMask

template<size_t NumBits = 64>
u64 mtcore::BitsetFixed< NumBits >::SetBitIter::curMask

Definition at line 1001 of file bitset.hpp.


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