-
Notifications
You must be signed in to change notification settings - Fork 4
/
lfu.h
40 lines (33 loc) · 612 Bytes
/
lfu.h
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
pair<long long int,long long int> cacheLfu[512];
int lfu(long long int tagValue, int setValue ,int numberOfWays)
{
int i,j,k;
//memset(cacheLfu,-1,sizeof(cacheLfu));
long long int hits=0;
k=-1;
int mi=1e9;
long long int p= numberOfWays*setValue;
//cout<<"Hello"<<endl;
for(j=p;j<p+numberOfWays;j++)
{
if(cacheLfu[j].first==tagValue)
{
cacheLfu[j].second++;
return 1;
}
}
if(j==p+numberOfWays)
{
for(j=p;j<p+numberOfWays;j++)
{
if(cacheLfu[j].second<mi)
{
mi=cacheLfu[j].second;
k=j;
}
}
cacheLfu[k].first=tagValue;
cacheLfu[k].second=1;
}
return 0;
}