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
125
126
130typedef std::uint32_t Level;
131
136typedef std::uint32_t HashVal;
137
145enum CatType { INVALID_CAT_TYPE,
146 HeapFileT,
147 SortedFileT,
148 BPlusTreeT,
149 HashIndexT
150 // add new types here (and add `,` after HashIndexT )
151 };
152
153
154enum Comp {INVALID_TYPE,
155 LESS,
156 GREATER,
157 EQUAL,
158 NOT_EQUAL,
159 LESS_EQUAL,
160 GREATER_EQUAL
161 };
162
167enum RepType { INVALID_REP_TYPE,
168 ClockT,
169 RandomT,
170 MruT,
171 ClockRandomT,
172 LruT,
173 // add new types here (and add after LruT and before MAXREPTYPES)
174 MAXREPTYPES
175};
176
181const int BM_MAX_REP_STR_LEN = (48);
187const char bm_rep_strs[MAXREPTYPES][BM_MAX_REP_STR_LEN] = { "Invalid",
188 "Clock",
189 "Random",
190 "MRU",
191 "ClockRandom", /* what is this? */
192 "LRU"
193 // add new string for new policy types here (add `,` after "LRU" )
194 // make sure length of string is less than BM_MAX_REP_STR_LEN
195};
196
197
201enum SelectType { INVALID_SELECT_TYPE,
202 FileScanT,
203 IndexT
204 // add new types here (and add `,` after Index )
205 };
206
207
211enum JoinType { INVALID_JOIN_TYPE,
212 TupleNLJT,
213 IndexNLJT,
214 BlockNLJT,
215 SeqHashJoinT,
216 ParHashJoinT
217 // add new types here (and add `,` after ParHashJoin )
218 };
219
220
226
227 FieldId field_id;
228 void *value;
229 Comp comp;
230
231};
232
233
241const std::uint32_t FILE_MAX_CAPACITY = 100000000;
242//const std::uint32_t FILE_MAX_CAPACITY = 2097152; /* 2 MB */
243//const std::uint32_t FILE_MAX_CAPACITY = 5242880; /* 5 MB */
244
250const std::uint32_t MAX_FILE_NUM = 1000;
251
255/* NOTE: (don't make the page size larger than 2^16 due to field offsets in
256 * records)
257 */
258const std::uint32_t PAGE_SIZE = 1024;
259
260// TODO: these is defined in terms of the internal details of the current
261// HeapFile implementation, and assuming a specific target architecture
262// and compiler padding of structs. We should make these more generic
263// to deal with changes to any of these.
269const std::uint32_t MAX_RECORD_SIZE = PAGE_SIZE - (8 * sizeof(std::uint32_t));
270
281const std::uint32_t MAX_PAGE_NUM = ((8*(FILE_MAX_CAPACITY -sizeof(std::uint32_t)
282 *2))/(8*PAGE_SIZE+1))-1;
283
287const std::uint32_t MAX_FILE_NAME_LEN = 511; /* 2^9 is huge */
288
292const std::uint32_t BUF_SIZE = 1024;
293
294//const std::uint32_t BUF_SIZE = 2048;
295
299const std::uint32_t MAX_FIELD_NAME = 32;
300
304const std::uint32_t INVALID_PAGE_NUM = MAX_PAGE_NUM+1;
305
310const std::uint32_t HEADER_PAGE_NUM = 0;
311
315const std::uint32_t INVALID_FILE_ID = MAX_FILE_NUM+1;
316
321
326const std::uint32_t INVALID_SLOT_OFFSET = PAGE_SIZE+1;
327
332
337
342const float MAX_HEAP_PAGE_LOAD = 0.9;
343
348const float MAX_HASH_BUCKET_LOAD = 0.9;
349
353const SlotId MAX_HASH_DIRSLOT = PAGE_SIZE/sizeof(PageNum);
354
355
356#endif
Definition swatdb_types.h:107
Definition swatdb_types.h:54
Definition swatdb_types.h:70
Definition swatdb_types.h:225
const SlotId INVALID_SLOT_ID
Definition swatdb_types.h:331
const std::uint32_t MAX_RECORD_SIZE
Definition swatdb_types.h:269
const float MAX_HASH_BUCKET_LOAD
Definition swatdb_types.h:348
const float MAX_HEAP_PAGE_LOAD
Definition swatdb_types.h:342
const std::uint32_t MAX_FILE_NUM
Definition swatdb_types.h:250
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:241
const std::uint32_t INVALID_PAGE_NUM
Definition swatdb_types.h:304
const std::uint32_t BUF_SIZE
Definition swatdb_types.h:292
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:320
const std::uint32_t HEADER_PAGE_NUM
Definition swatdb_types.h:310
const RecordId INVALID_RECORD_ID
Definition swatdb_types.h:336
const char bm_rep_strs[MAXREPTYPES][BM_MAX_REP_STR_LEN]
Definition swatdb_types.h:187
std::uint16_t FieldOffset
Definition swatdb_types.h:92
RepType
Definition swatdb_types.h:167
FieldType
Definition swatdb_types.h:97
const std::uint32_t INVALID_FILE_ID
Definition swatdb_types.h:315
const int BM_MAX_REP_STR_LEN
Definition swatdb_types.h:181
std::uint32_t Level
Definition swatdb_types.h:130
const std::uint32_t INVALID_SLOT_OFFSET
Definition swatdb_types.h:326
const std::uint32_t PAGE_SIZE
Definition swatdb_types.h:258
std::uint32_t HashVal
Definition swatdb_types.h:136
const std::uint32_t MAX_FILE_NAME_LEN
Definition swatdb_types.h:287
const SlotId MAX_HASH_DIRSLOT
Definition swatdb_types.h:353
const std::uint32_t MAX_FIELD_NAME
Definition swatdb_types.h:299
std::uint32_t PageNum
Definition swatdb_types.h:38
const std::uint32_t MAX_PAGE_NUM
Definition swatdb_types.h:281
JoinType
Definition swatdb_types.h:211
SelectType
Definition swatdb_types.h:201
CatType
Definition swatdb_types.h:145