forked from MorganBauer/COP-6726-Databases-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comparison.h
108 lines (77 loc) · 2.53 KB
/
Comparison.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
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 COMPARISON_H
#define COMPARISON_H
#include "Record.h"
#include "Schema.h"
#include "File.h"
#include "Comparison.h"
#include "ComparisonEngine.h"
#include <iostream>
// This stores an individual comparison that is part of a CNF
class Comparison {
friend class ComparisonEngine;
friend class CNF;
Target operand1;
int whichAtt1;
Target operand2;
int whichAtt2;
Type attType;
CompOperator op;
public:
Comparison();
//copy constructor
Comparison(const Comparison ©Me);
// print to the screen
void Print ();
};
class Schema;
// This structure encapsulates a sort order for records
class OrderMaker {
friend class ComparisonEngine;
friend class CNF;
int numAtts;
int whichAtts[MAX_ANDS];
Type whichTypes[MAX_ANDS];
public:
// writes out an ordermaker
friend std::ostream& operator<<(std::ostream&, const OrderMaker&);
// reads into an ordermaker
friend std::istream& operator>>(std::istream&, OrderMaker&);
// creates an empty OrdermMaker
OrderMaker();
// create an OrderMaker that can be used to sort records
// based upon ALL of their attributes
OrderMaker(Schema *schema);
int * GetWhichAtts() {return &whichAtts[0];}
int GetNumAtts() {return numAtts;}
// print to the screen
void Print ();
};
class Record;
// This structure stores a CNF expression that is to be evaluated
// during query execution
class CNF {
friend class ComparisonEngine;
Comparison orList[MAX_ANDS][MAX_ORS];
int orLens[MAX_ANDS];
int numAnds;
public:
int GetSearchOrder(OrderMaker &);
// this returns an instance of the OrderMaker class that
// allows the CNF to be implemented using a sort-based
// algorithm such as a sort-merge join. Returns a 0 if and
// only if it is impossible to determine an acceptable ordering
// for the given comparison
int GetSortOrders (OrderMaker &left, OrderMaker &right);
// print the comparison structure to the screen
void Print ();
// this takes a parse tree for a CNF and converts it into a 2-D
// matrix storing the same CNF expression. This function is applicable
// specifically to the case where there are two relations involved
void GrowFromParseTree (struct AndList *parseTree, Schema *leftSchema,
Schema *rightSchema, Record &literal);
// version of the same function, except that it is used in the case of
// a relational selection over a single relation so only one schema is used
void GrowFromParseTree (struct AndList *parseTree, Schema *mySchema,
Record &literal);
};
#endif