
#include "ElementSet.h"
using namespace std;

ElementSet::ElementSet()
{
}

ElementSet::ElementSet(char initial)
{
    mySet.insert(initial);
}

ElementSet ElementSet::Union(const ElementSet & other)
{
    ElementSet es;
    for (set<char>::iterator it = mySet.begin(); it != mySet.end(); it++)
        es.mySet.insert(*it);
    for (set<char>::iterator it = other.mySet.begin(); it != other.mySet.end(); it++)
        es.mySet.insert(*it);
    return es;
}

ElementSet ElementSet::Intersection(const ElementSet & other)
{
    ElementSet es;
    for (set<char>::iterator it = mySet.begin(); it != mySet.end(); it++)
    {
        set<char>::iterator find_it = other.mySet.find(*it);
        if (find_it != other.mySet.end())
            es.mySet.insert(*it);
    }
    return es;
}

ostream & operator<<(std::ostream & out, const ElementSet & e)
{
    int size = e.mySet.size();
    if (size > 1)
        out << '{';
    for (set<char>::iterator it = e.mySet.begin(); it != e.mySet.end(); it++)
    {
        out << *it;
    }
    if (size > 1)
        out << '}';
    return out;
}

void ElementSet::label()
{
    set<char>::iterator it = mySet.begin();
    if (it == mySet.end())
        return;
    it++;
    mySet.erase(it, mySet.end());
}
