SwatDB
Loading...
Searching...
No Matches
swatdb_types.h
Go to the documentation of this file.
1/*
2 * SwatDB
3 *
4 * @authors: See Contributors.doc for code contributors
5 *
6 * Copyright (c) 2020 Swarthmore College Computer Science Department
7 * Swarthmore PA, Professors Tia Newhall, Ameet Soni
8 */
9
10#ifndef _SWATDB_SWATDBTYPES_H_
11#define _SWATDB_SWATDBTYPES_H_
12
13
14
19#include <cstdint>
20#include <string>
21
33typedef std::uint32_t FileId;
34
38typedef std::uint32_t PageNum;
39
44typedef std::uint32_t FrameId;
45
49typedef std::uint32_t SlotId;
50
54struct PageId{
55 FileId file_id;
56 PageNum page_num;
57
58 bool operator==(const PageId& other) const{
59 return (file_id == other.file_id) && (page_num == other.page_num);
60 }
61
62 bool operator!=(const PageId& other) const{
63 return (file_id != other.file_id) || (page_num != other.page_num);
64 }
65};
66
70struct RecordId{
71 PageNum page_num;
72 SlotId slot_id;
73
74 bool operator==(const RecordId& other) const{
75 return (page_num == other.page_num) && (slot_id == other.slot_id);
76 }
77
78 bool operator!=(const RecordId& other) const{
79 return (page_num != other.page_num) || (slot_id != other.slot_id);
80 }
81};
82
86typedef std::uint32_t FieldId;
87
92typedef std::uint16_t FieldOffset;
93
97enum FieldType { IntFieldT,
98 FloatFieldT,
99 StringFieldT,
100 InvalidFieldT};
101
102
108 std::string field_name;
109 FieldType field_type;
110 std::uint32_t max_size;
111
112 bool operator==(const FieldEntry& other) const{
113 return (max_size == other.max_size) && (field_name == other.field_name)
114 && (field_type == other.field_type);
115 }
116
117 bool operator!=(const FieldEntry& other) const{
118 return (max_size != other.max_size) || (field_name != other.field_name)
119 || (field_type != other.field_type);
120 }
121
122};
123
124
128typedef std::uint32_t Level;
129
134typedef std::uint32_t HashVal;
135
143enum CatType { INVALID_CAT_TYPE,
144 HeapFileT,
145 SortedFileT,
146 BPlusTreeT,
147 HashIndexT
148 // add new types here (and add `,` after HashIndexT )
149 };
150
151
152enum Comp {INVALID_TYPE,
153 LESS,
154 GREATER,
155 EQUAL,
156 NOT_EQUAL,
157 LESS_EQUAL,
158 GREATER_EQUAL
159 };
160
165enum RepType { INVALID_REP_TYPE,
166 ClockT,
167 RandomT,
168 MruT,
169 ClockRandomT,
170 LruT,
171 // add new types here (and add after LruT and before MAXREPTYPES)
172 MAXREPTYPES
173};
174
179const int BM_MAX_REP_STR_LEN = (48);
185const char bm_rep_strs[MAXREPTYPES][BM_MAX_REP_STR_LEN] = { "Invalid",
186 "Clock",
187 "Random",
188 "MRU",
189 "ClockRandom", /* what is this? */
190 "LRU"
191 // add new string for new policy types here (add `,` after "LRU" )
192 // make sure length of string is less than BM_MAX_REP_STR_LEN
193};
194
195
199enum SelectType { INVALID_SELECT_TYPE,
200 FileScanT,
201 IndexT
202 // add new types here (and add `,` after Index )
203 };
204
205
209enum JoinType { INVALID_JOIN_TYPE,
210 TupleNLJT,
211 IndexNLJT,
212 BlockNLJT,
213 SeqHashJoinT,
214 ParHashJoinT
215 // add new types here (and add `,` after ParHashJoin )
216 };
217
218
224
225 FieldId field_id;
226 void *value;
227 Comp comp;
228
229};
230
231
239const std::uint32_t FILE_MAX_CAPACITY = 100000000;
240//const std::uint32_t FILE_MAX_CAPACITY = 2097152; /* 2 MB */
241//const std::uint32_t FILE_MAX_CAPACITY = 5242880; /* 5 MB */
242
248const std::uint32_t MAX_FILE_NUM = 1000;
249
253/* NOTE: (don't make the page size larger than 2^16 due to field offsets in
254 * records)
255 */
256const std::uint32_t PAGE_SIZE = 1024;
257
258// TODO: these is defined in terms of the internal details of the current
259// HeapFile implementation, and assuming a specific target architecture
260// and compiler padding of structs. We should make these more generic
261// to deal with changes to any of these.
267const std::uint32_t MAX_RECORD_SIZE = PAGE_SIZE - (8 * sizeof(std::uint32_t));
268
279const std::uint32_t MAX_PAGE_NUM = ((8*(FILE_MAX_CAPACITY -sizeof(std::uint32_t)
280 *2))/(8*PAGE_SIZE+1))-1;
281
285const std::uint32_t MAX_FILE_NAME_LEN = 511; /* 2^9 is huge */
286
290const std::uint32_t BUF_SIZE = 1024;
291
292//const std::uint32_t BUF_SIZE = 2048;
293
297const std::uint32_t MAX_FIELD_NAME = 32;
298
302const std::uint32_t INVALID_PAGE_NUM = MAX_PAGE_NUM+1;
303
308const std::uint32_t HEADER_PAGE_NUM = 0;
309
313const std::uint32_t INVALID_FILE_ID = MAX_FILE_NUM+1;
314
319
324const std::uint32_t INVALID_SLOT_OFFSET = PAGE_SIZE+1;
325
330
335
340const float MAX_HEAP_PAGE_LOAD = 0.9;
341
346const float MAX_HASH_BUCKET_LOAD = 0.9;
347
351const SlotId MAX_HASH_DIRSLOT = PAGE_SIZE/sizeof(PageNum);
352
353
354#endif
Definition swatdb_types.h:107
Definition swatdb_types.h:54
Definition swatdb_types.h:70
Definition swatdb_types.h:223
const SlotId INVALID_SLOT_ID
Definition swatdb_types.h:329
const std::uint32_t MAX_RECORD_SIZE
Definition swatdb_types.h:267
const float MAX_HASH_BUCKET_LOAD
Definition swatdb_types.h:346
const float MAX_HEAP_PAGE_LOAD
Definition swatdb_types.h:340
const std::uint32_t MAX_FILE_NUM
Definition swatdb_types.h:248
std::uint32_t FrameId
Index of each frame in the bufferpool of BufferManager.
Definition swatdb_types.h:44
const std::uint32_t FILE_MAX_CAPACITY
Definition swatdb_types.h:239
const std::uint32_t INVALID_PAGE_NUM
Definition swatdb_types.h:302
const std::uint32_t BUF_SIZE
Definition swatdb_types.h:290
std::uint32_t FieldId
Definition swatdb_types.h:86
std::uint32_t FileId
Definition swatdb_types.h:33
const PageId INVALID_PAGE_ID
Definition swatdb_types.h:318
const std::uint32_t HEADER_PAGE_NUM
Definition swatdb_types.h:308
const RecordId INVALID_RECORD_ID
Definition swatdb_types.h:334
const char bm_rep_strs[MAXREPTYPES][BM_MAX_REP_STR_LEN]
Definition swatdb_types.h:185
std::uint16_t FieldOffset
Definition swatdb_types.h:92
RepType
Definition swatdb_types.h:165
FieldType
Definition swatdb_types.h:97
const std::uint32_t INVALID_FILE_ID
Definition swatdb_types.h:313
const int BM_MAX_REP_STR_LEN
Definition swatdb_types.h:179
std::uint32_t Level
Definition swatdb_types.h:128
const std::uint32_t INVALID_SLOT_OFFSET
Definition swatdb_types.h:324
const std::uint32_t PAGE_SIZE
Definition swatdb_types.h:256
std::uint32_t HashVal
Definition swatdb_types.h:134
const std::uint32_t MAX_FILE_NAME_LEN
Definition swatdb_types.h:285
const SlotId MAX_HASH_DIRSLOT
Definition swatdb_types.h:351
const std::uint32_t MAX_FIELD_NAME
Definition swatdb_types.h:297
std::uint32_t PageNum
Definition swatdb_types.h:38
const std::uint32_t MAX_PAGE_NUM
Definition swatdb_types.h:279
JoinType
Definition swatdb_types.h:209
SelectType
Definition swatdb_types.h:199
CatType
Definition swatdb_types.h:143