SwatDB
Loading...
Searching...
No Matches
include
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
25
struct
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
38
class
BufferMap
{
39
40
public
:
41
45
BufferMap
(){ }
46
50
~BufferMap
(){ }
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
BufferMap
Definition
bm_buffermap.h:38
BufferMap::~BufferMap
~BufferMap()
Destructor for BufferMap.
Definition
bm_buffermap.h:50
BufferMap::buf_map
std::unordered_map< PageId, FrameId, BufHash > buf_map
Definition
bm_buffermap.h:114
BufferMap::get
FrameId get(PageId page_id)
Returns FrameId corresponding to the given PageId.
BufferMap::BufferMap
BufferMap()
Constructor for BufferMap.
Definition
bm_buffermap.h:45
BufferMap::remove
void remove(PageId page_id)
Removes the key-value pair corresponding to the given PageId from the map.
BufferMap::insert
void insert(PageId page_id, FrameId frame_id)
Inserts the pair <page_id, frame_id> into the map.
BufferMap::contains
bool contains(PageId page_id)
Returns true if the map contains the given PageId, else false.
BufHash
Definition
bm_buffermap.h:25
PageId
Definition
swatdb_types.h:54
swatdb_types.h
FrameId
std::uint32_t FrameId
Index of each frame in the bufferpool of BufferManager.
Definition
swatdb_types.h:44
Generated by
1.9.8