-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelation.h
52 lines (44 loc) · 1.18 KB
/
relation.h
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
#ifndef Relation_h
#define Relation_h
#include "datalogProgram.h"
#include "constraint.h"
#include "tuple.h"
#include <algorithm>
struct tupleCompare
{
bool operator()(const Tuple& A, const Tuple& B)
{
// cout << "Called compare" << endl;
int lA = A.data.size();
int lB = B.data.size();
for (int i = 0; i < lA; i++)
{
// cout << lB << "comparing " << A[i] << " to " << B[i] << endl;
if (i >= lB) return false;
if (A.data[i] < B.data[i]) return true;
else if (A.data[i] > B.data[i]) return false;
}
return false;
}
};
class Relation
{
public:
vector<string> columns;
set<Tuple, tupleCompare> tuples;
Relation(vector<string> col_names);
Relation select(vector<Constraint>& constraints);
Relation project(vector<int>& newInds);
Relation project(vector<string> names);
Relation rename(vector<string> newNames);
Relation join(Relation& other);
//add the contents of another relation to this one
void unionWith(Relation& other, ostream& out);
void add(vector<string> v);
void add(Tuple t);
int size();
string toString();
};
string tuple_to_string(vector<string>& t);
string named_tuple_to_string(vector<string>& t, vector<string>& names);
#endif