SwatDB
Loading...
Searching...
No Matches
bm_buffermap.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,2025 Swarthmore College Computer Science Department
7 * Swarthmore PA, Professors Tia Newhall, Ameet Soni
8 */
9
10#ifndef _SWATDB_BM_BUFFERMAP_H_
11#define _SWATDB_BM_BUFFERMAP_H_
12
17#include <utility>
18#include <unordered_map>
19
20#include "swatdb_types.h"
21
25struct BufHash{
26 std::size_t operator()(const PageId& page_id) const{
27 return (std::hash<unsigned int>() (page_id.file_id)) ^
28 (std::hash<unsigned int>() (page_id.page_num));
29 }
30};
31
38class BufferMap {
39
40 public:
41
46
51
64 FrameId get(PageId page_id);
65
77 bool contains(PageId page_id);
78
94 void insert(PageId page_id, FrameId frame_id);
95
107 void remove(PageId page_id);
108
109 private:
110
114 std::unordered_map<PageId,FrameId,BufHash> buf_map;
115};
116
117#endif
Definition bm_buffermap.h:38
~BufferMap()
Destructor for BufferMap.
Definition bm_buffermap.h:50
std::unordered_map< PageId, FrameId, BufHash > buf_map
Definition bm_buffermap.h:114
FrameId get(PageId page_id)
Returns FrameId corresponding to the given PageId.
BufferMap()
Constructor for BufferMap.
Definition bm_buffermap.h:45
void remove(PageId page_id)
Removes the key-value pair corresponding to the given PageId from the map.
void insert(PageId page_id, FrameId frame_id)
Inserts the pair <page_id, frame_id> into the map.
bool contains(PageId page_id)
Returns true if the map contains the given PageId, else false.
Definition bm_buffermap.h:25
Definition swatdb_types.h:54
std::uint32_t FrameId
Index of each frame in the bufferpool of BufferManager.
Definition swatdb_types.h:44