#include "set.h"
#include <vector>

Set::Set(const std::vector<int64_t> &vector) {
    for (auto const item : vector) {
        this->Add(item);
    }
}

Set Set::Union(const Set &old) const {
    Set new_set;
    for (auto const item : old.Data()) {
        new_set.Add(item);
    }
    for (auto const item : this->vector) {
        new_set.Add(item);
    }
    return new_set;
}

Set Set::Intersection(const Set &another) const {
    Set new_set;
    for (auto const item1 : this->vector) {
        for (auto const item2: another.Data()) {
            if (item1 == item2) {
                new_set.Add(item1);
            }
        }
    }
    return new_set;
}

Set Set::Difference(const Set &another) const {
    Set new_set;
    bool used;
    for (auto const item1 : this->vector) {
        used = true;
        for (auto const item2 : another.Data()) {
            if (item1 == item2) {
                used = false;
                break;
            }
        }
        if (used) {
            new_set.Add(item1);
        }
    }
    return new_set;
}

Set Set::SymmetricDifference(const Set &another) const {
    return this->Difference(another).Union(another.Difference(*this));
}

void Set::Add(int64_t num) {
    for (auto const item : this->vector) {
        if (item == num) {
            return;
        }
    }
    this->vector.push_back(num);
}

void Set::Remove(int64_t num) {
    for (int i = 0; i < this->vector.size(); i++) {
        if (this->vector[i] == num) {
            this->vector.erase(this->vector.begin() + i);
            break;
        }
    }
}

bool Set::Contains(int64_t num) const {
    for (auto const item : this->vector) {
        if (item == num) {
            return true;
        }
    }
    return false;
}

std::vector<int64_t> Set::Data() const {
    return this->vector;
}