-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatistics.h
More file actions
108 lines (73 loc) · 2.33 KB
/
Statistics.h
File metadata and controls
108 lines (73 loc) · 2.33 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef STATISTICS_
#define STATISTICS_
#include "ParseTree.h"
#include <cstring>
#include <string>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include<sstream>
using namespace std;
struct Relation {
private:
double numOfTuples;
public:
Relation() {
this->numOfTuples = 0;
}
Relation(double numOfTuples) {
this->numOfTuples = numOfTuples;
}
double GetNumOfTuples() {
return numOfTuples;
}
void SetNumOfTuples(double n) {
this->numOfTuples = n;
}
};
struct Att {
private:
int numOfDistinct;
public:
Att() {
this->numOfDistinct = 0;
}
Att(int numOfDistinct) {
this->numOfDistinct = numOfDistinct;
}
int GetNumOfDistinct() {
return numOfDistinct;
}
void SetNumOfDistinct(int n) {
this->numOfDistinct = n;
}
};
class Statistics {
private:
unordered_map<string, Relation> groupNameToRelationMap;
unordered_map<string, Att> attNameToAttributeMap;
unordered_map<string, unordered_set<string> > groupNameToSetOfRelationsMap;
unordered_map<string, string> relNameToGroupNameMap;
void AddAtt(const string &relName, string attName, int numDistincts);
void PreProcessApply(struct AndList *parseTree, unordered_set<string> *relNames);
void ValidateApplyOnRelations(unordered_set<string> *relNames);
void PreProcessApplyOnAttributes(struct AndList *parseTree, unordered_set<string> *relNames);
void PreProcessNameOperand(Operand *operand, unordered_set<string> *relNames);
public:
Statistics();
Statistics(Statistics ©Me); // Performs deep copy
~Statistics();
void AddRel(char *relName, int numTuples);
void AddAtt(char *relName, char *attName, int numDistincts);
void CopyRel(char *oldName, char *newName);
void Read(char *fromWhere);
void Write(char *fromWhere);
void Apply(struct AndList *parseTree, char *relNames[], int numToJoin);
double Estimate(struct AndList *parseTree, char **relNames, int numToJoin);
unordered_map<string, Relation> *GetGroupNameToRelationMap();
unordered_map<string, Att> *GetAttNameToAttributeMap();
unordered_map<string, unordered_set<string> > *GetGroupNameToSetOfRelationsMap();
unordered_map<string, string> *GetRelNameToGroupNameMap();
};
#endif