SwatDB
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 #pragma once
11 
16 #include <cstdint>
17 
29 typedef std::uint32_t FileId;
30 
34 typedef std::uint32_t PageNum;
35 
40 typedef std::uint32_t FrameId;
41 
45 typedef std::uint32_t SlotId;
46 
50 struct PageId{
51  FileId file_id;
52  PageNum page_num;
53 
54  bool operator==(const PageId& other) const{
55  return (file_id == other.file_id) && (page_num == other.page_num);
56  }
57 
58  bool operator!=(const PageId& other) const{
59  return (file_id != other.file_id) || (page_num != other.page_num);
60  }
61 };
62 
66 struct RecordId{
67  PageNum page_num;
68  SlotId slot_id;
69 
70  bool operator==(const RecordId& other) const{
71  return (page_num == other.page_num) && (slot_id == other.slot_id);
72  }
73 
74  bool operator!=(const RecordId& other) const{
75  return (page_num != other.page_num) || (slot_id != other.slot_id);
76  }
77 };
78 
82 typedef std::uint32_t FieldId;
83 
87 enum FieldType { IntFieldT,
88  FloatFieldT,
89  StringFieldT};
90 
98 enum CatType { INVALID_CAT_TYPE,
99  HeapFileT,
100  SortedFileT,
101  BPlusTreeT,
102  HashIndexT
103  // add new types here (and add `,` after HashIndexT )
104  };
105 
106 
107 
115 const std::uint32_t FILE_MAX_CAPACITY = 10000000;
116 //const std::uint32_t FILE_MAX_CAPACITY = 2097152; /* 2 MB */
117 //const std::uint32_t FILE_MAX_CAPACITY = 5242880; /* 5 MB */
118 
124 const std::uint32_t MAX_FILE_NUM = 1000;
125 
129 const std::uint32_t PAGE_SIZE = 1024;
130 
131 // TODO: these is defined in terms of the internal details of the current
132 // HeapFile implementation, and assuming a specific target architecture
133 // and compiler padding of structs. We should make these more generic
134 // to deal with changes to any of these.
140 const std::uint32_t MAX_RECORD_SIZE = PAGE_SIZE - (8 * sizeof(std::uint32_t));
141 
152 const std::uint32_t MAX_PAGE_NUM = ((8*(FILE_MAX_CAPACITY -sizeof(std::uint32_t)
153  *2))/(8*PAGE_SIZE+1))-1;
154 
158 const std::uint32_t MAX_FILE_NAME_LEN = 511; /* 2^9 is huge */
159 
163 const std::uint32_t BUF_SIZE = 1024;
164 
168 const std::uint32_t INVALID_PAGE_NUM = MAX_PAGE_NUM+1;
169 
174 const std::uint32_t HEADER_PAGE_NUM = 0;
175 
179 const std::uint32_t INVALID_FILE_ID = MAX_FILE_NUM+1;
180 
184 const PageId INVALID_PAGE_ID = {INVALID_FILE_ID, INVALID_PAGE_NUM};
185 
190 const std::uint32_t INVALID_SLOT_OFFSET = PAGE_SIZE+1;
191 
196 
200 const RecordId INVALID_RECORD_ID = {INVALID_PAGE_NUM, INVALID_SLOT_ID};
201 
206 const float MAX_HEAP_PAGE_LOAD = 0.9;
const std::uint32_t INVALID_FILE_ID
Definition: swatdb_types.h:179
std::uint32_t PageNum
Definition: swatdb_types.h:34
CatType
Definition: swatdb_types.h:98
const std::uint32_t HEADER_PAGE_NUM
Definition: swatdb_types.h:174
const SlotId INVALID_SLOT_ID
Definition: swatdb_types.h:195
const float MAX_HEAP_PAGE_LOAD
Definition: swatdb_types.h:206
const std::uint32_t MAX_FILE_NAME_LEN
Definition: swatdb_types.h:158
const std::uint32_t FILE_MAX_CAPACITY
Definition: swatdb_types.h:115
const std::uint32_t MAX_RECORD_SIZE
Definition: swatdb_types.h:140
Definition: swatdb_types.h:66
const std::uint32_t MAX_FILE_NUM
Definition: swatdb_types.h:124
const RecordId INVALID_RECORD_ID
Definition: swatdb_types.h:200
Definition: swatdb_types.h:50
const std::uint32_t MAX_PAGE_NUM
Definition: swatdb_types.h:152
const std::uint32_t PAGE_SIZE
Definition: swatdb_types.h:129
FieldType
Definition: swatdb_types.h:87
std::uint32_t FrameId
Index of each frame in the bufferpool of BufferManager.
Definition: swatdb_types.h:40
std::uint32_t FieldId
Definition: swatdb_types.h:82
const std::uint32_t BUF_SIZE
Definition: swatdb_types.h:163
std::uint32_t FileId
Definition: swatdb_types.h:29
const std::uint32_t INVALID_SLOT_OFFSET
Definition: swatdb_types.h:190
const PageId INVALID_PAGE_ID
Definition: swatdb_types.h:184
const std::uint32_t INVALID_PAGE_NUM
Definition: swatdb_types.h:168