#include <vector>
#include <cstdint>
#include "set.h"
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 temp;
for (auto const obj1 : this->vector) {
temp = true;
for (auto const obj2 : another.Data())
if (obj1 == obj2) {
temp = false;
break;
}
if (temp)
new_set.Add(obj1);
}
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 obj : this->vector)
if (obj == num)
return;
this->vector.push_back(num);
}
void Set::Remove(int64_t num) {
for (unsigned 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 obj : this->vector)
if (obj == num)
return true;
return false;
}
std::vector<int64_t> Set::Data() const {
return this->vector;
}