#include "set.h"
#include <vector>
void Set::Add(int64_t val) {
int i = (val * 3 + 11) % 1000007;
while (c[i] != -1 && c[i] != val) {
i = (i + 17) % 1000007;
}
c[i] = val;
}
void Set::Remove(int64_t val) {
int i = (val * 3 + 11) % 1000007;
while (c[i] != -1 && c[i] != val) {
i = (i + 17) % 1000007;
}
if (c[i] == val) {
c[i] = -2;
}
}
bool Set::Contains(int64_t val) const {
int i = (val * 3 + 11) % 1000007;
while (c[i] != -1 && c[i] != val) {
i = (i + 17) % 1000007;
}
return (c[i] == val);
}
Set::Set(const std::vector<int64_t>& a) {
c.assign(1000007, -1);
for (int i = 0; i < a.size(); i++)
Add(a[i]);
}
Set Set::Union(const Set& b) const {
Set new_set;
for (int i = 0; i < 1000007; i++) {
if (c[i] >= 0)
new_set.Add(c[i]);
if (b.c[i] >= 0)
new_set.Add(b.c[i]);
}
return new_set;
}
Set Set::Intersection(const Set& b) const {
Set new_set;
for (int i = 0; i < 1000007; i++) {
if (c[i] >= 0 && b.Contains(c[i]))
new_set.Add(c[i]);
}
return new_set;
}
Set Set::Difference(const Set& b) const {
Set new_set;
for (int i = 0; i < 1000007; i++) {
if (c[i] >= 0 && (b.Contains(c[i]) == false))
new_set.Add(c[i]);
}
return new_set;
}
Set Set::SymmetricDifference(const Set& b) const {
Set new_set;
for (int i = 0; i < 1000007; i++) {
if (c[i] >= 0 && (b.Contains(c[i]) == false))
new_set.Add(c[i]);
if (b.c[i] >= 0 && (Contains(b.c[i]) == false))
new_set.Add(b.c[i]);
}
return new_set;
}
std::vector<int64_t> Set::Data() const {
std::vector<int64_t> ans;
for (int i = 0; i < 1000007; i++) {
if (c[i] >= 0)
ans.push_back(c[i]);
}
return ans;
}