Patch level : 12.0 no patch

Files correlati     :
Commento

      Bit array

Aggiunte funzioni insert e pack ai Bit array
This commit is contained in:
Alessandro Bonazzi 2021-01-31 13:44:38 +01:00
parent fd0b2b3299
commit 732003b79f
2 changed files with 29 additions and 0 deletions

View File

@ -837,6 +837,31 @@ TBit_array::~TBit_array()
delete _bit;
}
void TBit_array::insert(long n, bool on)
{
if (n < 0)
n = 0;
const int last = last_one();
if (last >= n)
for (word i = last_one(); i >= n; i--)
set(i + 1, operator [](i));
set(n, on);
}
void TBit_array::pack(long n)
{
if (n < 0)
n = 0;
const int last = last_one();
if (last > n)
for (word i = n; i < last; i++)
set(i, operator [](i + 1));
reset(last);
}
// Certified 100%
void TBit_array::set()
{

View File

@ -396,6 +396,10 @@ public:
// @cmember Not logico del bit n-esimo dell'array
void neg(long n);
// @cmember inserisce e setta il bit n-esimo a seconda del valore passato come secondo elemento
void insert(long n, bool on = false);
// @cmember elimina il bit n-esimo
void pack(long n);
// @cmember Setta il bit n-esimo a seconda del valore passato come secondo elemento
void set(long n, bool on) { on ? set(n) : reset(n); }
// @cmember Setta ad 1 tutti i bit dell'array