almost finish CKGroup

This commit is contained in:
2023-09-01 12:19:06 +08:00
parent 3755a2e148
commit fd69914a25
15 changed files with 310 additions and 88 deletions

View File

@ -0,0 +1,30 @@
#include "XBitArray.hpp"
namespace LibCmo::XContainer::XBitArrayPatch {
template<bool _Cond>
bool GeneralGetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got) {
CK2::CKDWORD counter = 0;
for (size_t i = 0; i < ba.size(); ++i) {
if (ba[i] == _Cond) {
if (counter == n) {
got = static_cast<CK2::CKDWORD>(i);
return true;
} else {
++counter;
}
}
}
return false;
}
bool GetSetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got) {
return GeneralGetBitPosition<true>(ba, n, got);
}
bool GetUnsetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got) {
return GeneralGetBitPosition<false>(ba, n, got);
}
}

View File

@ -0,0 +1,17 @@
#pragma once
#include "XTypes.hpp"
namespace LibCmo::XContainer::XBitArrayPatch {
/**
* @brief Returns the position of the n-th set(1) bit
* @return false if not found.
*/
bool GetSetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got);
/**
* @brief Returns the position of the n-th unset(0) bit
* @return false if not found.
*/
bool GetUnsetBitPosition(XBitArray& ba, CK2::CKDWORD n, CK2::CKDWORD& got);
}