Skip to content

Commit

Permalink
all tests are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Футин Даниил Евгеньевич committed Oct 11, 2019
1 parent 595c461 commit b5b3997
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
16 changes: 9 additions & 7 deletions src/tbitfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ TBitField TBitField::operator|(const TBitField &bf) // операция "или"
int tempLen = BitLen;
if (bf.BitLen > BitLen) tempLen = bf.BitLen;
TBitField result(tempLen);
for (int i = 0; i < MemLen; i++) result.pMem[i] = pMem[i];
for (int i = 0; i < result.MemLen; i++) result.pMem[i] = result.pMem[i] | bf.pMem[i];
// for (int i = 0; i < MemLen; i++) result.pMem[i] = pMem[i];
for (int i = 0; i < result.MemLen; i++) result.pMem[i] = pMem[i] | bf.pMem[i];
return result;
}

Expand All @@ -139,24 +139,26 @@ TBitField TBitField::operator&(const TBitField &bf) // операция "и"
int tempLen = BitLen;
if (bf.BitLen > BitLen) tempLen = bf.BitLen;
TBitField result(tempLen);
for (int i = 0; i < MemLen; i++) result.pMem[i] = pMem[i];
for (int i = 0; i < result.MemLen; i++) result.pMem[i] = result.pMem[i] & bf.pMem[i];
// for (int i = 0; i < MemLen; i++) result.pMem[i] = pMem[i];
for (int i = 0; i < result.MemLen; i++) result.pMem[i] = pMem[i] & bf.pMem[i];
return result;
}

TBitField TBitField::operator~(void) // отрицание
{
TBitField result(BitLen);
for (int i = 0; i < MemLen; i++) {
for (int k = 0; k < BitLen; k++) {
int cnt = (BitLen / 32);
for (int i = 0; i < cnt; i++)
result.pMem[i] = ~pMem[i];

for (int k = cnt * 32; k < BitLen; k++) {
if (GetBit(k) == 0) {
result.SetBit(k);
}
else {
result.ClrBit(k);
}
}
}
return result;
}

Expand Down
20 changes: 5 additions & 15 deletions src/tset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TSet::TSet(int mp) : BitField(mp)
}

// конструктор копирования
TSet::TSet(const TSet &s) : BitField(s.MaxPower)
TSet::TSet(const TSet &s) : BitField(s.BitField)
{
if (s.MaxPower > -1) {
MaxPower = s.MaxPower;
Expand Down Expand Up @@ -89,6 +89,7 @@ int TSet::operator!=(const TSet &s) const // сравнение

TSet TSet::operator+(const TSet &s) // объединение
{
if (s.MaxPower > MaxPower) MaxPower = s.MaxPower;
TSet result(MaxPower);
result.BitField = BitField | s.BitField;
return result;
Expand All @@ -98,20 +99,9 @@ TSet TSet::operator+(const int Elem) // объединение с элемент
{
//СЕМЬ БЕД - ОДИН ОТВЕТ
//ВСТАВЬ КОСТЫЛЬ, ИЗОБРЕТИ ВЕЛОСИПЕД
if ((Elem > -1) && (Elem < BitField.GetLength())) {
TBitField E(Elem); //Битовое поле для Elem
TELEM mask = 1;
for (int i = 0; i < Elem; i++) {
mask = 1;
mask = mask << (i & 31);
if ((Elem & mask) != 0) { E.SetBit(i); cout << "done"; }
}
TSet E1(E);
TSet result(MaxPower);
result = *this + E1;
return result;
}
else throw - 1;
TSet res(*this);
res.BitField.SetBit(Elem);
return res;
}

TSet TSet::operator-(const int Elem) // разность с элементом
Expand Down

0 comments on commit b5b3997

Please sign in to comment.