-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomSimulation.cpp
More file actions
28 lines (23 loc) · 904 Bytes
/
RandomSimulation.cpp
File metadata and controls
28 lines (23 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//
// Created by Nick Chapman on 4/19/17.
//
#include "RandomSimulation.h"
RandomSimulation::RandomSimulation() {
this->mt = std::mt19937(std::random_device{}());
this->dist = std::uniform_int_distribution<unsigned int>(0, UINT32_MAX);
}
RandomSimulation::RandomSimulation(unsigned int nFrames, bool verbose) : PagingSimulation(nFrames, verbose) {
this->mt = std::mt19937(std::random_device{}());
this->dist = std::uniform_int_distribution<unsigned int>(0, UINT32_MAX);
}
PageTableEntry* RandomSimulation::RemoveFrameEntry() {
unsigned long advance = this->dist(this->mt) % this->mFrames.size();
auto it = this->mFrames.begin();
std::advance(it, advance);
PageTableEntry* removed = it->second;
this->mFrames.erase(removed->mVpn);
return removed;
}
void RandomSimulation::AddFrameEntry(PageTableEntry* entry) {
this->mFrames.emplace(entry->mVpn, entry);
}