forked from shaobohou/madios
-
Notifications
You must be signed in to change notification settings - Fork 2
/
EquivalenceClass.cpp
65 lines (51 loc) · 1.17 KB
/
EquivalenceClass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "EquivalenceClass.h"
#include <algorithm>
using std::vector;
using std::string;
using std::ostringstream;
EquivalenceClass::EquivalenceClass()
{
}
EquivalenceClass::EquivalenceClass(const vector<unsigned int> &units)
:vector<unsigned int>(units)
{
}
EquivalenceClass::~EquivalenceClass()
{
}
EquivalenceClass EquivalenceClass::computeOverlapEC(const EquivalenceClass &other) const
{
EquivalenceClass overlap;
for(unsigned int i = 0; i < other.size(); i++)
if(has(other[i]))
overlap.add(other[i]);
return overlap;
}
bool EquivalenceClass::has(unsigned int unit) const
{
return (find(begin(), end(), unit) != end());
}
bool EquivalenceClass::add(unsigned int unit)
{
if(has(unit))
return false;
push_back(unit);
return true;
}
LexiconUnit* EquivalenceClass::makeCopy() const
{
return new EquivalenceClass(*this);
}
string EquivalenceClass::toString() const
{
ostringstream sout;
sout << "E[";
if(size() > 0)
{
for(unsigned int i = 0; i < size() - 1; i++)
sout << "P" << at(i) << " | ";
if(size() > 0) sout << "P" << back();
}
sout << "]";
return sout.str();
}