-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathran.cpp
More file actions
51 lines (47 loc) · 1.15 KB
/
ran.cpp
File metadata and controls
51 lines (47 loc) · 1.15 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "ran.h"
namespace coen383
{
//CONSTRUCTOR
ran::ran()
{
pageRequest = 0;
numElements = 0;
pageNumber = 0;
numCount = 0;
srand ( time(NULL) );
//*used for debugging*//
// myfile.open ("output");
}
void ran::pageReplaceAlgo()
{
setItr = set.find(pageRequest);
if(setItr == set.end())
{
//page does not already exist in the cache
std::cout<<"Page number "<<pageRequest<<" caused a page fault."<<std::endl;
//*used for debugging*//
// myfile<<"Page number "<<pageRequest<<" caused a page fault.\n";
if(set.size() >= tableSize)
{
std::set<int>::const_iterator it = set.begin();
int count = rand()%tableSize;
for (int i = 0; i < count; i++)
++it;
set.erase(it);
}
set.insert(pageRequest);
numCount++;
}
else
{
std::cerr<<"Page number "<<pageRequest<<" caused a page hit."<<std::endl;
}
//*used for debugging*//
// std::cerr<<"set: ";
// for (setItr = set.begin(); setItr != set.end(); ++setItr)
// {
// std::cerr << '\t' << *setItr;
// }
// std::cerr<<std::endl;
}
}