forked from Jefung/simple_DBMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.cpp
67 lines (59 loc) · 1.76 KB
/
index.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
66
67
#include "index.h"
bool operator<(const Index &i1, const Index &i2){
unsigned long size = i1.size() > i2.size() ? i2.size() : i1.size();
for(int i = 0; i < size; i++){
// todo: 支持不同类型比较?
if(typeid(*i1[i]) != typeid(*i2[i]))
throw "the column type must be same";
if(*i1[i] > *i2[i])
return false;
if(*i1[i] < *i2[i])
return true;
}
if(*i1[size - 1] == *i2[size - 1])
return false;
return true;
}
bool operator==(const Index &i1, const Index &i2){
unsigned long size = i1.size() > i2.size() ? i2.size() : i1.size();
for(int i = 0; i < size; i++){
// todo: 支持不同类型比较?
if(typeid(*i1[i]) != typeid(*i2[i]))
throw "the column type must be same";
if(*i1[i] != *i2[i])
return false;
}
return true;
}
bool operator>(const Index &i1, const Index &i2){
unsigned long size = i1.size() > i2.size() ? i2.size() : i1.size();
for(int i = 0; i < size; i++){
// todo: 支持不同类型比较?
if(typeid(*i1[i]) != typeid(*i2[i])){
std::cout << "the column type must be same" << std::endl;
throw "the column type must be same";
}
if(*i1[i] < *i2[i])
return false;
if(*i1[i] > *i2[i])
return true;
}
if(*i1[size - 1] == *i2[size - 1]){
return false;
}
return true;
}
Index::Index(){
}
std::ostream &operator<<(std::ostream &os, const Index &data){
for(int i = 0; i < data.size(); i++){
os << *data[i];
}
return os;
}
bool operator>=(const Index &i1, const Index &i2){
return i1 > i2 || i1 == i2;
}
bool operator<=(const Index &i1, const Index &i2){
return i1 < i2 || i1 == i2;
}