-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex.hpp
78 lines (56 loc) · 2.19 KB
/
Index.hpp
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
// Created by rick gessner on 5/17/20.
// Copyright © 2020 rick gessner. All rights reserved.
//
// Modified by Zongheng Cao after the skeleton All rights reserved.
//
// used for in memory space of index, record the table and attribute name
// and the valueMap: value, blockNum
#ifndef Index_h
#define Index_h
#include "Storage.hpp"
#include "Other/keywords.hpp"
#include "Other/Value.hpp"
#include <string>
using namespace std;
namespace ECE141 {
using IntOpt = std::optional<uint32_t>;
struct LessKey {
bool operator()(const ValueType& anLHS, const ValueType& aRHS) const {
return anLHS < aRHS;
}
};
class Index{
public:
using ValueMap = std::map<ValueType, uint32_t, LessKey>;
Index(){}
Index(const Index& aCopy);
Index& operator=(const Index& aCopy);
Index(const std::string &aField, string tableName, DataType aType)
: field(aField), type(aType), tableName(tableName), blockNum(0) {
type=aType;
changed=false;
}
virtual ~Index() {}
ValueMap& getList() {return list;}
void setChanged(bool aValue=true) {changed=aValue;}
bool isChanged() {return changed;}
const std::string& getFieldName() const {return field;}
Index& setFieldName(string name) {field = name; return *this;}
Index& setTableName(string name) {tableName = name; return *this;}
uint32_t getBlockNum() const {return blockNum;}
//manage keys/values in the index...
Index& addKeyValue(const ValueType &aKey, uint32_t aValue);
Index& removeKeyValue(const ValueType &aKey);
bool contains(const ValueType &aKey);
DataType& getValue();
string getTableName(){return tableName;}
protected:
std::string field; // 名字 比如 name age
DataType type; //是什么数据类型的
string tableName; //table name
bool changed; //是否被修改 如果被修改了 需要写入
uint32_t blockNum; //storage block# of index... //这个index在第几个block num
ValueMap list; //tree map来存储value 和 对应的 index
};
}
#endif /* Index_h */