SwatDB
Public Member Functions | Private Attributes | List of all members
BufferMap Class Reference

#include <bufmgr.h>

Public Member Functions

 BufferMap ()
 Constructor for BufferMap.
 
 ~BufferMap ()
 Destructor for BufferMap.
 
FrameId get (PageId page_id)
 Returns FrameId corresponding to the given PageId. More...
 
bool contains (PageId page_id)
 Returns true if the map contains the given PageId, else false. More...
 
void insert (PageId page_id, FrameId frame_id)
 Inserts the pair <page_id, frame_id> into the map. More...
 
void remove (PageId page_id)
 Removes the key-value pair corresponding to the given PageId from the map. More...
 

Private Attributes

std::unordered_map< PageId, FrameId, BufHashbuf_map
 

Detailed Description

BufferMap is a wrapper class for std::unordered_map<PageId, FrameId> that maps PageIds to a Frame index in the buffer pool. Has different method names from std::unordered_map. Have get(), contains(), insert(), and remove() methods.

Member Function Documentation

◆ contains()

bool BufferMap::contains ( PageId  page_id)

Returns true if the map contains the given PageId, else false.

Precondition
A lock is held on the map. A PageId is provided.
Postcondition
Returns true if the map contains the PageId, else false. Lock is still held on the map.
Parameters
page_idA PageId to be searched in the map.
Returns
bool indicating whether the given PageId exists in the BufferMap.

◆ get()

FrameId BufferMap::get ( PageId  page_id)

Returns FrameId corresponding to the given PageId.

Precondition
A lock is held on the map. This map contains the given PageId.
Postcondition
Returns the corresponding FrameId. Lock is still held on the map.
Parameters
page_idA PageId for which the corresponding FrameId will be returned.
Returns
FrameId which correspond to the given PageId.
Exceptions
PageNotFoundBufMgrif the given PageId is not in the map.

◆ insert()

void BufferMap::insert ( PageId  page_id,
FrameId  frame_id 
)

Inserts the pair <page_id, frame_id> into the map.

Precondition
A lock is held on the map. A PageId and FrameId are provided as input.
Postcondition
Adds a new <PageId, FrameId> pair to the map. If the map contains page_id, then it throws an exception. Lock is still held on the map.
Parameters
page_idA PageId key.
frame_idA FrameId value.
Exceptions
throwPageAlreadyLoadedBufMgr if a page with this PageId is already in the Buffer Pool

◆ remove()

void BufferMap::remove ( PageId  page_id)

Removes the key-value pair corresponding to the given PageId from the map.

Precondition
A lock is held on the map. The given PageId is in the map.
Postcondition
The key-value pair searched by page_id is removed from the map.
Parameters
page_idThe PageId key for the key-value pair to be removed.
Exceptions
PageIdNotFoundBufMgrIf page_id is not in the map.

Member Data Documentation

◆ buf_map

std::unordered_map<PageId,FrameId,BufHash> BufferMap::buf_map
private

The underlying std::unordered_map for storing the map information


The documentation for this class was generated from the following file: