Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: CMake on a single platform

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: ls
run: ls

# Runs a set of commands using the runners shell
- name: test
run: ./build/bin/test_set

#- name: Test
#working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
#run: ctest -C ${{env.BUILD_TYPE}}

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.5)

set(PROJECT_NAME set)
project(${PROJECT_NAME})
Expand Down
4 changes: 2 additions & 2 deletions include/tbitfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ typedef unsigned int TELEM;
class TBitField
{
private:
int BitLen; // длина битового поля - макс. к-во битов
int bitLen; // длина битового поля - макс. к-во битов
TELEM *pMem; // память для представления битового поля
int MemLen; // к-во эл-тов Мем для представления бит.поля
int memLen; // к-во эл-тов Мем для представления бит.поля

// методы реализации
int GetMemIndex(const int n) const; // индекс в pМем для бита n (#О2)
Expand Down
14 changes: 7 additions & 7 deletions include/tset.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
class TSet
{
private:
int MaxPower; // максимальная мощность множества
TBitField BitField; // битовое поле для хранения характеристического вектора
int maxPower; // максимальная мощность множества
TBitField bitField; // битовое поле для хранения характеристического вектора
public:
TSet(int mp);
TSet(const TSet &s); // конструктор копирования
TSet(const TBitField &bf); // конструктор преобразования типа
operator TBitField(); // преобразование типа к битовому полю
// доступ к битам
int GetMaxPower(void) const; // максимальная мощность множества
void InsElem(const int Elem); // включить элемент в множество
void DelElem(const int Elem); // удалить элемент из множества
int IsMember(const int Elem) const; // проверить наличие элемента в множестве
void InsElem(const int elem); // включить элемент в множество
void DelElem(const int elem); // удалить элемент из множества
int IsMember(const int elem) const; // проверить наличие элемента в множестве
// теоретико-множественные операции
int operator== (const TSet &s) const; // сравнение
int operator!= (const TSet &s) const; // сравнение
TSet& operator=(const TSet &s); // присваивание
TSet operator+ (const int Elem); // объединение с элементом
TSet operator+ (const int elem); // объединение с элементом
// элемент должен быть из того же универса
TSet operator- (const int Elem); // разность с элементом
TSet operator- (const int elem); // разность с элементом
// элемент должен быть из того же универса
TSet operator+ (const TSet &s); // объединение
TSet operator* (const TSet &s); // пересечение
Expand Down
107 changes: 94 additions & 13 deletions src/tbitfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,93 +6,174 @@
// Битовое поле

#include "tbitfield.h"
#include <cmath>

// Fake variables used as placeholders in tests
static const int FAKE_INT = -1;
static TBitField FAKE_BITFIELD(1);
static const int SIZE = sizeof(TELEM)*8;

TBitField::TBitField(int len)
{
if (len < 0)
throw "bad length!";
bitLen = len;
memLen = bitLen / SIZE;
pMem = new TELEM(memLen);
for (int i = 0; i < memLen; ++i)
pMem[i] = 0;
}

TBitField::TBitField(const TBitField &bf) // конструктор копирования
{
bitLen = bf.GetLength();
memLen = bitLen / SIZE;
pMem = new TELEM(memLen);
for (int i = 0; i < memLen; ++i)
pMem[i] = bf.pMem[i];
}

TBitField::~TBitField()
{
if (pMem != nullptr)
delete pMem;
}

int TBitField::GetMemIndex(const int n) const // индекс Мем для бита n
int TBitField::GetMemIndex(const int n) const // индекс элемента в массиве в котором хранится бит
{
return FAKE_INT;
return n / SIZE;
}

TELEM TBitField::GetMemMask(const int n) const // битовая маска для бита n
{
return FAKE_INT;
return std::pow(2, n % SIZE);
//return std::pow(2, n-GetMemIndex(n)*SIZE);
//TELEM mask = 0;
//mask >> (n & ((1 << 32) - 1));
//return mask;
}

// доступ к битам битового поля

int TBitField::GetLength(void) const // получить длину (к-во битов)
{
return FAKE_INT;
return bitLen;
}

void TBitField::SetBit(const int n) // установить бит
{
if ((n > bitLen) || (n < 0))
throw "bad index";
int pos = GetMemIndex(n);
TELEM aboba = GetMemMask(n);
//std::cout << "Mask: " << aboba << std::endl;
pMem[pos] = pMem[pos] | aboba;
}

void TBitField::ClrBit(const int n) // очистить бит
{
if ((n > bitLen) || (n < 0))
throw "bad index";
int pos = GetMemIndex(n);
TELEM aboba = GetMemMask(n);
pMem[pos] = pMem[pos] & ~aboba;
}

int TBitField::GetBit(const int n) const // получить значение бита
{
return FAKE_INT;
if ((n > bitLen) || (n < 0))
throw "bad index";
int pos = GetMemIndex(n);
TELEM aboba = GetMemMask(n);
if ((pMem[pos] & aboba) != 0)
return 1;
return 0;
}

// битовые операции

TBitField& TBitField::operator=(const TBitField &bf) // присваивание
{
return FAKE_BITFIELD;
if (pMem != nullptr)
delete[] pMem;
bitLen = bf.GetLength();
memLen = bitLen / SIZE + 1;
pMem = new TELEM(memLen);
for (int i = 0; i < memLen; i++)
pMem[i] = bf.pMem[i];
return *this;
}

int TBitField::operator==(const TBitField &bf) const // сравнение
{
return FAKE_INT;
if (bitLen != bf.GetLength())
return 0;

for(int i = 0; i < memLen; i++)
if (pMem[i] != bf.pMem[i])
return 0;

return 1;
}

int TBitField::operator!=(const TBitField &bf) const // сравнение
{
return FAKE_INT;
//return !(*this == bf);
if (bitLen != bf.GetLength())
return 1;

for(int i = 0; i < bitLen; i++)
if (GetBit(i) != bf.GetBit(i))
return 1;

return 0;
}

TBitField TBitField::operator|(const TBitField &bf) // операция "или"
{
return FAKE_BITFIELD;
TBitField aboba(std::max(bitLen, bf.GetLength()));
for (int i = 0; i < aboba.GetLength()/SIZE; i++)
aboba.pMem[i] = pMem[i] | bf.pMem[i];
return aboba;
}

TBitField TBitField::operator&(const TBitField &bf) // операция "и"
{
return FAKE_BITFIELD;
TBitField aboba(std::max(bitLen, bf.GetLength()));
for (int i = 0; i < aboba.GetLength()/SIZE; i++)
aboba.pMem[i] = pMem[i] & bf.pMem[i];
return aboba;
}

TBitField TBitField::operator~(void) // отрицание
{
return FAKE_BITFIELD;
TBitField aboba(bitLen);
for (int i = 0; i < aboba.GetLength()/SIZE; i++)
aboba.pMem[i] = ~pMem[i];
return aboba;
}

// ввод/вывод

istream &operator>>(istream &istr, TBitField &bf) // ввод
{
return istr;
int num = -1;
for (int i = 0; i < bf.GetLength(); ++i)
{
std::cout << "Enter value of bit #" << i << std::endl;
istr >> num;
if (num != 0 && num != 1)
throw "invalid value of a bit!";
if (num == 1)
bf.SetBit(i);
}
return istr;
}

ostream &operator<<(ostream &ostr, const TBitField &bf) // вывод
{
return ostr;
for (int i = 0; i < bf.GetLength(); i++)
ostr << bf.GetBit(i);
ostr << std::endl;
return ostr;
}
Loading