SwatDB
Loading...
Searching...
No Matches
hashindexfile.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_HASHINDEXFILE_H_
11#define _SWATDB_HASHINDEXFILE_H_
12
16#include <utility>
17
18#include "swatdb_types.h"
19#include "indexfile.h" //for inheritance
20
21class Key;
22class HashBucketPage;
23
30class HashIndexFile;
31
36static const std::uint32_t MAX_HASH_SIZE =
37 (PAGE_SIZE-4*sizeof(std::uint32_t))/sizeof(PageNum);
38
44
49
53 std::uint32_t dir_size;
54
58 std::uint32_t num_bucket;
59
63 std::uint32_t num_entries;
67 PageNum dir[MAX_HASH_SIZE];
68};
69
70
71class HashIndexFile : public IndexFile{
72
73 friend class HashIndexScanner;
74
75 public:
76
94 relation, std::vector<std::string> field_list);
95
113 relation, std::vector<FieldId> field_list);
114
122
136
149
181 void insertEntry(Key key, RecordId record_id);
182
198 std::vector<RecordId> getEntries(Key key);
199
200 //TODO: add scanner and getEntry function
201
219 void deleteEntry(Key key, RecordId record_id);
220
235 void deleteKey(Key key);
236
242
243 private:
261 std::pair<SlotId, SlotId>_findDirSlot(HashVal hash_val, Level level);
262
288 void _levelUp(HashIndexHeader* file_header);
289
305 PageId _splitPage(HashIndexHeader* file_header, HashBucketPage* bucket_page,
306 PageId bucket_page_id);
307};
308
309
310#endif
Definition bufmgr.h:121
Definition catalog.h:161
Catalog * catalog
Definition file.h:124
BufferManager * buf_mgr
Definition file.h:129
Definition hashbucketpage.h:95
Definition hashindexfile.h:71
HashIndexHeader getHeader()
THIS METHOD IS FOR DEBUGGING ONLY. Returns the current HashIndexHeader.
PageId _splitPage(HashIndexHeader *file_header, HashBucketPage *bucket_page, PageId bucket_page_id)
Helper function for splitting a bucket.
void createHeader()
Allocates and initializes the header Page of the file.
HashIndexFile(Catalog *catalog, BufferManager *buf_mgr, FileId relation, std::vector< FieldId > field_list)
Constructor for IndexFile class.
HashIndexFile(Catalog *catalog, BufferManager *buf_mgr, FileId relation, std::vector< std::string > field_list)
Constructor for IndexFile class.
void flushHeader()
Flushes header Page to disk.
std::vector< RecordId > getEntries(Key key)
Returns a list all RecordIds with the given Key.
void insertEntry(Key key, RecordId record_id)
Inserts an Entry into the HashIndexFile.
void deleteEntry(Key key, RecordId record_id)
Method for deleting an entry of the given Key and RecordId.
~HashIndexFile()
Destructor. Data members are cleaned up, but none of the dynamically allocated data members are delet...
std::pair< SlotId, SlotId > _findDirSlot(HashVal hash_val, Level level)
Helper function for computing the location of the slot for PageNum of the bucket, corresponding to th...
void deleteKey(Key key)
Method for deleting all entires with the given key.
void _levelUp(HashIndexHeader *file_header)
Helper function for incrementing the global level of the hash index.
Definition hashindexscanner.h:41
Definition indexfile.h:41
FileId relation
Definition indexfile.h:133
Definition key.h:38
Definition hashindexfile.h:43
PageNum dir[MAX_HASH_SIZE]
Definition hashindexfile.h:67
std::uint32_t num_entries
Definition hashindexfile.h:63
std::uint32_t dir_size
Definition hashindexfile.h:53
Level global_level
Definition hashindexfile.h:48
std::uint32_t num_bucket
Definition hashindexfile.h:58
Definition swatdb_types.h:54
Definition swatdb_types.h:70
std::uint32_t FileId
Definition swatdb_types.h:33
std::uint32_t Level
Definition swatdb_types.h:130
const std::uint32_t PAGE_SIZE
Definition swatdb_types.h:258
std::uint32_t HashVal
Definition swatdb_types.h:136
std::uint32_t PageNum
Definition swatdb_types.h:38