Merge pull request #2065 from js6i/bit-array-fix
Fix MVKBitArray::getIndexOfFirstSetBit() skipping over entries.
This commit is contained in:
commit
abeed4e720
@ -90,7 +90,11 @@ public:
|
|||||||
* and optionally clears that bit. If no bits are set, returns the size() of this bit array.
|
* and optionally clears that bit. If no bits are set, returns the size() of this bit array.
|
||||||
*/
|
*/
|
||||||
size_t getIndexOfFirstSetBit(size_t startIndex, bool shouldClear) {
|
size_t getIndexOfFirstSetBit(size_t startIndex, bool shouldClear) {
|
||||||
size_t startSecIdx = std::max(getIndexOfSection(startIndex), _clearedSectionCount);
|
size_t startSecIdx = getIndexOfSection(startIndex);
|
||||||
|
if (startSecIdx < _clearedSectionCount) {
|
||||||
|
startSecIdx = _clearedSectionCount;
|
||||||
|
startIndex = 0;
|
||||||
|
}
|
||||||
size_t bitIdx = startSecIdx << SectionMaskSize;
|
size_t bitIdx = startSecIdx << SectionMaskSize;
|
||||||
size_t secCnt = getSectionCount();
|
size_t secCnt = getSectionCount();
|
||||||
for (size_t secIdx = startSecIdx; secIdx < secCnt; secIdx++) {
|
for (size_t secIdx = startSecIdx; secIdx < secCnt; secIdx++) {
|
||||||
@ -101,6 +105,7 @@ public:
|
|||||||
if (shouldClear) { clearBit(bitIdx); }
|
if (shouldClear) { clearBit(bitIdx); }
|
||||||
return std::min(bitIdx, _bitCount);
|
return std::min(bitIdx, _bitCount);
|
||||||
}
|
}
|
||||||
|
startIndex = 0;
|
||||||
}
|
}
|
||||||
return std::min(bitIdx, _bitCount);
|
return std::min(bitIdx, _bitCount);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user